How to use the @dojo/framework/core/mixins/Themed function in @dojo/framework

To help you get started, we’ve selected a few @dojo/framework examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dojo / widgets / src / time-picker / index.tsx View on Github external
*/
export function parseUnits(value: string | TimeUnits): TimeUnits {
	if (typeof value === 'string') {
		if (!TIME_PATTERN.test(value)) {
			throw new Error('Time strings must be in the format HH:mm or HH:mm:ss');
		}

		const [hour, minute, second = 0] = value.split(':').map((unit) => parseInt(unit, 10));
		return { hour, minute, second } as TimeUnits;
	}

	return value;
}

@theme(css)
export class TimePicker extends ThemedMixin(FocusMixin(WidgetBase)) {
	protected options: TimeUnits[] | null = null;

	private _uuid = uuid();

	private _formatUnits(units: TimeUnits): string {
		const { step = 60 } = this.properties;
		const { hour, minute, second } = units;

		return (step >= 60 ? [hour, minute] : [hour, minute, second])
			.map((unit) => padStart(String(unit), 2, '0'))
			.join(':');
	}

	private _getOptionLabel(value: TimeUnits) {
		const { getOptionLabel } = this.properties;
		const units = parseUnits(value);
github dojo / widgets / src / grid / Cell.tsx View on Github external
export interface CellProperties extends FocusProperties {
	/** The display value (or widget) of the cell */
	value: string | DNode;
	/** If the cell's value may be updated */
	editable?: boolean;
	/** The underlying string value of the cell (used by the editor) */
	rawValue: string;
	/** Called when the Cell's value is saved by the editor */
	updater: (value: any) => void;
	/** The width (in pixels) */
	width?: number;
}

@theme(css)
export default class Cell extends ThemedMixin(FocusMixin(WidgetBase)) {
	private _editing = false;
	private _editingValue = '';
	private _focusKey!: string;
	private _idBase = uuid();

	private _callFocus(key: string) {
		this._focusKey = key;
		this.focus();
	}

	private _onEdit = () => {
		const { editable } = this.properties;
		if (editable) {
			this._editing = true;
			this._callFocus('input');
			this._editingValue = this.properties.rawValue;
github dojo / widgets / src / grid / Row.tsx View on Github external
/** A list of values indexed on the column id */
	item: { [index: string]: any };
	/** Configuration for grid columns (id, title, properties, and custom renderer)  */
	columnConfig: ColumnConfig[];
	/** Handles updating the value of a cell */
	updater: (rowNumber: number, columnId: string, value: any) => void;
	/** Calculated column widths */
	columnWidths?: { [index: string]: number };
	/** handler for row selection */
	onRowSelect?: (type: any) => void;
	/** array of selected rows */
	selected?: boolean;
}

@theme(css)
export default class Row extends ThemedMixin(WidgetBase) {
	private _onRowSelect(event: MouseEvent) {
		const { onRowSelect } = this.properties;
		const type = event.ctrlKey || event.metaKey ? 'multi' : 'single';
		onRowSelect && onRowSelect(type);
	}

	protected render(): DNode {
		const {
			item,
			columnConfig,
			id,
			theme,
			classes,
			columnWidths,
			onRowSelect,
			selected
github dojo / widgets / src / grid / PaginatedBody.ts View on Github external
onScroll: (value: number) => void;
	/** Calculated column widths */
	columnWidths?: { [index: string]: number };
	/** handler for row selection */
	onRowSelect?: (index: number, type: SelectionType) => void;
	/** array of selected rows */
	selectedRows?: number[];
}

const defaultPlaceholderRowRenderer = (index: number) => {
	return w(PlaceholderRow, { key: index });
};

@theme(css)
@diffProperty('pages', reference)
export default class PaginatedBody<s> extends ThemedMixin(WidgetBase)&gt; {
	private _updater(rowNumber: number, columnId: string, value: any) {
		const page = Math.max(Math.ceil(rowNumber / this.properties.pageSize), 1);
		const pageItemNumber = rowNumber - (page - 1) * this.properties.pageSize;
		this.properties.updater(page, pageItemNumber, columnId, value);
	}

	private _onScroll(event: UIEvent) {
		const scrollLeft = (event.target as HTMLElement).scrollLeft;
		this.properties.onScroll(scrollLeft);
	}

	private _renderRows() {
		const {
			pageSize,
			fetcher,
			pages,</s>
github dojo / widgets / src / grid / Footer.tsx View on Github external
import ThemedMixin, { theme } from '@dojo/framework/core/mixins/Themed';
import { DNode } from '@dojo/framework/core/interfaces';

import * as css from '../theme/default/grid-footer.m.css';

export interface FooterProperties {
	/** The total number of rows */
	total?: number;
	/** The current page */
	page: number;
	/** The number of rows per page */
	pageSize: number;
}

@theme(css)
export default class Footer extends ThemedMixin(WidgetBase) {
	protected render(): DNode {
		const { total, page, pageSize } = this.properties;
		const footer =
			total !== undefined
				? `Page ${page} of ${Math.ceil(total / pageSize)}. Total rows ${total}`
				: `Page ${page} of ?`;
		return v('div', { classes: this.theme(css.root) }, [footer]);
	}
}
github dojo / widgets / src / grid / Body.tsx View on Github external
const div = global.document.createElement('div');
	div.style.position = 'absolute';
	global.document.body.appendChild(div);
	r.mount({ domNode: div, sync: true });
	const dimensions = div.getBoundingClientRect();
	global.document.body.removeChild(div);
	return dimensions;
};

const defaultPlaceholderRowRenderer = (index: number) =&gt; {
	return w(PlaceholderRow, { key: index });
};

@theme(css)
@diffProperty('pages', reference)
export default class Body<s> extends ThemedMixin(WidgetBase)&gt; {
	private _rowHeight!: number;
	private _rowsInView!: number;
	private _renderPageSize!: number;
	private _start = 0;
	private _end = 100;
	private _resetScroll = false;

	private _updater(rowNumber: number, columnId: string, value: any) {
		const page = Math.max(Math.ceil(rowNumber / this.properties.pageSize), 1);
		const pageItemNumber = rowNumber - (page - 1) * this.properties.pageSize;
		this.properties.updater(page, pageItemNumber, columnId, value);
	}

	private _onScroll(event: UIEvent) {
		const { totalRows = 0, onScroll } = this.properties;
		const scrollTop = (event.target as HTMLElement).scrollTop;</s>
github dojo / widgets / src / grid / index.tsx View on Github external
/** options store, if no store is passed each grid will factory their own grid */
	store?: Store<s>;
	/** the path to store the grid data in */
	storeId?: string;
	/** set of custom renderers for sorting or filtering */
	customRenderers?: CustomRenderers;
	/** when set uses traditional pagination */
	pagination?: boolean;
	/** handler for row selection */
	onRowSelect?: (rowData: S[]) =&gt; void;
}

const MIN_COLUMN_WIDTH = 100;

@theme(css)
export default class Grid<s> extends ThemedMixin(WidgetBase)&gt; {
	private _store = new Store&gt;();
	private _handle: any;
	private _scrollLeft = 0;
	private _pageSize = 100;
	private _columnWidths: { [index: string]: number } | undefined;
	private _gridWidth = 0;

	constructor() {
		super();
		this._handle = this._store.onChange(this._store.path('_grid'), this.invalidate.bind(this));
	}

	@diffProperty('store', reference)
	protected onStoreProperty(previous: any, current: any) {
		const { storeId = '_grid' } = current;
		this._handle.remove();</s></s>
github dojo / widgets / src / grid / PlaceholderRow.tsx View on Github external
import WidgetBase from '@dojo/framework/core/WidgetBase';
import { v } from '@dojo/framework/core/vdom';
import ThemedMixin, { theme } from '@dojo/framework/core/mixins/Themed';
import { DNode } from '@dojo/framework/core/interfaces';
import * as css from '../theme/default/grid-placeholder-row.m.css';

@theme(css)
export default class PlaceholderRow extends ThemedMixin(WidgetBase) {
	protected render(): DNode {
		return v('div', { classes: this.theme(css.root) }, [
			v('div', { classes: this.theme(css.loading) })
		]);
	}
}
github dojo / widgets / src / grid / Header.tsx View on Github external
[index: string]: string;
	};
	/** Applied sort options */
	sort?: SortOptions;
	/** Custom column renderer for displaying sort options */
	sortRenderer?: SortRenderer;
	/** Custom renderer displaying applied filters */
	filterRenderer?: FilterRenderer;
	/** Callback on column resize */
	onColumnResize?: (index: number, value: number) =&gt; void;
	/** Calculated column widths */
	columnWidths?: { [index: string]: number };
}

@theme(css)
export default class Header extends ThemedMixin(WidgetBase) {
	private _getColumnTitle(column: ColumnConfig): string | DNode {
		if (typeof column.title === 'function') {
			return column.title();
		}
		return column.title;
	}

	private _sortColumn(id: string) {
		const { sort, sorter } = this.properties;
		const direction = sort
			? sort.columnId !== id
				? 'desc'
				: sort.direction === 'desc'
				? 'asc'
				: 'desc'
			: 'desc';
github dojo / widgets / src / grid / PaginatedBody.tsx View on Github external
onScroll: (value: number) =&gt; void;
	/** Calculated column widths */
	columnWidths?: { [index: string]: number };
	/** handler for row selection */
	onRowSelect?: (index: number, type: SelectionType) =&gt; void;
	/** array of selected rows */
	selectedRows?: number[];
}

const defaultPlaceholderRowRenderer = (index: number) =&gt; {
	return w(PlaceholderRow, { key: index });
};

@theme(css)
@diffProperty('pages', reference)
export default class PaginatedBody<s> extends ThemedMixin(WidgetBase)&gt; {
	private _updater(rowNumber: number, columnId: string, value: any) {
		const page = Math.max(Math.ceil(rowNumber / this.properties.pageSize), 1);
		const pageItemNumber = rowNumber - (page - 1) * this.properties.pageSize;
		this.properties.updater(page, pageItemNumber, columnId, value);
	}

	private _onScroll(event: UIEvent) {
		const scrollLeft = (event.target as HTMLElement).scrollLeft;
		this.properties.onScroll(scrollLeft);
	}

	private _renderRows() {
		const {
			pageSize,
			fetcher,
			pages,</s>