當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript createWidgetBase.mixin函數代碼示例

本文整理匯總了TypeScript中@dojo/widget-core/createWidgetBase.mixin函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript mixin函數的具體用法?TypeScript mixin怎麽用?TypeScript mixin使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了mixin函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: onClick

export interface ButtonProperties extends WidgetProperties {
	label?: string;
	name?: string;
	onClick?(event: MouseEvent): void;
}

export type Button = Widget<ButtonProperties> & {
	onClick(event?: MouseEvent): void;
};

export interface ButtonFactory extends WidgetFactory<Button, ButtonProperties> { }

const createButton: ButtonFactory = createWidgetBase
	.mixin({
		mixin: {
			onClick(this: Button, event: MouseEvent) {
				this.properties.onClick && this.properties.onClick(event);
			},
			nodeAttributes: [
				function(this: Button): VNodeProperties {
					return { innerHTML: this.properties.label, onclick: this.onClick };
				}
			],
			tagName: 'button',
			type: 'button'
		}
	});

export default createButton;
開發者ID:Tomdye,項目名稱:examples,代碼行數:29,代碼來源:createButton.ts

示例2:

	onDblclick: (event: MouseEvent) => void;
}

export interface LabelFactory extends WidgetFactory<Label, LabelProperties> {}

const createLabel: LabelFactory = createWidgetBase
	.mixin({
		mixin: {
			tagName: 'label',
			onDblclick(this: Label, event: MouseEvent) {
				this.properties.onDblclick && this.properties.onDblclick(event);
			},
			onKeypress(this: Label, event: KeyboardEvent) {
				this.properties.onKeypress && this.properties.onKeypress(event);
			},
			nodeAttributes: [
				function (this: Label): VNodeProperties {
					return {
						innerHTML: this.properties.label,
						'aria-describedby': 'edit-instructions',
						tabindex: '0',
						onkeyup: this.onKeypress,
						ondblclick: this.onDblclick
					};
				}
			]
		}
	});

export default createLabel;
開發者ID:Tomdye,項目名稱:examples,代碼行數:30,代碼來源:createLabel.ts

示例3: function

export type TodoFooter = Widget<TodoFooterProperties>;

const createTodoFooter = createWidgetBase.mixin({
	mixin: {
		tagName: 'footer',
		classes: [ 'footer' ],
		getChildrenNodes: function(this: TodoFooter): (DNode | null)[] {
			const { activeCount, activeFilter, completedCount } = this.properties;
			const countLabel = activeCount === 1 ? 'item' : 'items';

			return [
				v('span', { 'class': 'todo-count' }, [
					v('strong', [activeCount + ' ']),
					v('span', [countLabel + ' left'])
				]),
				w('todo-filter', {
					classes: [ 'filters' ],
					activeFilter
				}),
				completedCount ? w('button', {
					onClick: clearCompleted,
					label: 'Clear completed',
					classes: [ 'clear-completed' ]
				}) : null
			];
		}
	}
});

export default createTodoFooter;
開發者ID:Tomdye,項目名稱:examples,代碼行數:30,代碼來源:createTodoFooter.ts

示例4:

export interface CheckboxProperties extends WidgetProperties {
	checked?: boolean;
	onChange?: (event?: Event) => void;
};

export type CheckboxInput = Widget<CheckboxProperties> & {
	onChange: (event?: Event) => void;
}

export type CheckboxInputFactory = WidgetFactory<CheckboxInput, CheckboxProperties>

const createCheckboxInput: CheckboxInputFactory = createWidgetBase
	.mixin({
		mixin: {
			tagName: 'input',
			type: 'checkbox',
			onChange(this: CheckboxInput, event?: Event) {
				this.properties.onChange && this.properties.onChange(event);
			},
			nodeAttributes: [
				function (this: CheckboxInput): VNodeProperties {
					const { type, onChange: onchange, properties: { checked } } = this;
					return { checked, onchange, type };
				}
			]
		}
	});

export default createCheckboxInput;
開發者ID:Tomdye,項目名稱:examples,代碼行數:29,代碼來源:createCheckboxInput.ts

示例5: if

const createFocusableTextInput: FocusableTextInputFactory = createWidgetBase
	.mixin({
		mixin: {
			tagName: 'input',

			type: 'text',

			onKeyUp(this: FocusableTextInput, event?: KeyboardEvent) {
				this.properties.onKeyUp && this.properties.onKeyUp(event);
			},
			onBlur(this: FocusableTextInput, event?: Event) {
				this.properties.onBlur && this.properties.onBlur(event);
			},
			afterUpdate(this: FocusableTextInput, element: HTMLInputElement) {
				const focused = this.properties.focused;
				if (focused) {
					setTimeout(() => element.focus(), 0);
				}
				else if (!focused && document.activeElement === element) {
					element.blur();
				}
			},
			nodeAttributes: [
				function (this: FocusableTextInput): VNodeProperties {
					const { onKeyUp: onkeyup, onBlur: onblur, afterUpdate, afterUpdate: afterCreate } = this;
					const { placeholder, value = '' } = this.properties;

					return { afterUpdate, placeholder, innerHTML: value, value, afterCreate, onkeyup, onblur };
				}
			]
		}
	});
開發者ID:Tomdye,項目名稱:examples,代碼行數:32,代碼來源:createFocusableTextInput.ts

示例6:

import { Widget, WidgetProperties, WidgetFactory } from '@dojo/widget-core/interfaces';
import { VNodeProperties } from '@dojo/interfaces/vdom';
import createWidgetBase from '@dojo/widget-core/createWidgetBase';

export interface TitleProperties extends WidgetProperties {
	label?: string;
}

export interface TitleFactory extends WidgetFactory<Widget<TitleProperties>, TitleProperties> { }

const createTitle: TitleFactory = createWidgetBase.mixin({
	mixin: {
		tagName: 'h1',
		nodeAttributes: [
			function (this: Widget<TitleProperties>): VNodeProperties {
				return { innerHTML: this.properties.label };
			}
		]
	}
});

export default createTitle;
開發者ID:Tomdye,項目名稱:examples,代碼行數:22,代碼來源:createTitle.ts

示例7: function

import { DNode, Widget, WidgetProperties } from '@dojo/widget-core/interfaces';
import createWidgetBase from '@dojo/widget-core/createWidgetBase';
import { w } from '@dojo/widget-core/d';
import { todoToggleAll } from '../actions/userActions';

export interface MainSectionProperties extends WidgetProperties {
	allCompleted: boolean;
	store: any;
}

const createMainSection = createWidgetBase.mixin({
	mixin: {
		tagName: 'section',
		classes: [ 'main' ],
		getChildrenNodes: function (this: Widget<MainSectionProperties>): DNode[] {
			const { properties: { activeFilter, todos, allCompleted: checked } } = this;

			return [
				w('checkbox', { checked, onChange: todoToggleAll, classes: [ 'toggle-all' ]}),
				w('todo-list', { todos, activeFilter })
			];
		}
	}
});

export default createMainSection;
開發者ID:Tomdye,項目名稱:examples,代碼行數:26,代碼來源:createMainSection.ts

示例8: function

const createTodoItem = createWidgetBase.mixin({
		mixin: {
			tagName: 'li',
			nodeAttributes: [
				function(this: TodoItem): VNodeProperties {
					const { completed, editing } = this.properties;
					return {
						classes: { completed, editing }
					};
				}
			],
			getChildrenNodes: function(this: TodoItem): (DNode | null)[] {
				const { properties: { id: todoId, completed: checked, label, editing: focused = false } } = this;

				return [
					v('div.view', [
						w('checkbox', { classes: [ 'toggle' ], checked, onChange: bind(todoToggleComplete, this) }),
						w('label', { label, onDblclick: bind(todoEdit, this), onKeypress: bind(todoEdit, this) }),
						w('button', { classes: [ 'destroy' ], onClick: bind(todoRemove, this) })
					]),
					focused ? w('text-input', {
						value: label,
						id: todoId,
						focused, classes: [ 'edit' ],
						onBlur: bind(todoSave, this),
						onKeyUp: bind(todoEditInput, this)
					}) : null
				];
			}
		}
});
開發者ID:Tomdye,項目名稱:examples,代碼行數:31,代碼來源:createTodoItem.ts

示例9: createFilterItems

export type TodoFilterFactory = WidgetFactory<TodoFilter, TodoFilterProperties>

function createFilterItems(activeFilter: string): DNode[] {
	const filters = [ 'all', 'active', 'completed' ];
	return filters.map((filterItem) => {
		const label = filterItem[0].toUpperCase() + filterItem.substring(1);
		return v('li', {}, [
			v('a', {
				innerHTML: label,
				href: `#${filterItem}`,
				classes: {
					selected: activeFilter === filterItem
				}
			})
		]);
	});
}

const createTodoFilter: TodoFilterFactory = createWidgetBase.mixin({
	mixin: {
		tagName: 'ul',
		classes: [ 'filters' ],
		getChildrenNodes: function(this: TodoFilter): DNode[] {
			const activeFilter = this.properties.activeFilter || '';
			return createFilterItems(activeFilter);
		}
	}
});

export default createTodoFilter;
開發者ID:Tomdye,項目名稱:examples,代碼行數:30,代碼來源:createTodoFilter.ts

示例10: function

import { DNode, WidgetOptions, WidgetMixin, WidgetFactory, WidgetProperties } from '@dojo/widget-core/interfaces';
import createWidgetBase from '@dojo/widget-core/createWidgetBase';
import storeMixin, { StoreMixinApi, StoreMixinProperties } from '@dojo/widget-core/mixins/storeMixin';
import { v, w } from '@dojo/widget-core/d';

import { todoInput } from './actions/userActions';
import { bind } from './utils';

export interface AppProperties extends WidgetProperties, StoreMixinProperties { }

export interface AppMixin extends WidgetMixin<AppProperties>, StoreMixinApi { }

export interface AppFactory extends WidgetFactory<AppMixin, WidgetOptions<AppProperties>> { }

const createApp: AppFactory = createWidgetBase
	.mixin(storeMixin)
	.mixin({
		mixin: {
			classes: [ 'todoapp' ],
			tagName: 'section',
			getChildrenNodes: function(this: AppMixin): DNode[] {
				const { todos = [], activeCount, completedCount, allCompleted, activeFilter } = this.state;
				const classes = todos && todos.length ? [] : [ 'hidden' ];
				const todoFooterProperties = { id: 'todo-footer', activeCount, completedCount, activeFilter, classes };

				return [
					v('header', {}, [
						w('title', { label: 'todos' }),
						w('text-input', { classes: ['new-todo'], focused: true, placeholder: 'What needs to be done?', onKeyUp: bind(todoInput, this) })
					]),
					w('main-section', { todos, activeFilter, allCompleted }),
開發者ID:Tomdye,項目名稱:examples,代碼行數:31,代碼來源:createApp.ts


注:本文中的@dojo/widget-core/createWidgetBase.mixin函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。