本文整理匯總了TypeScript中@ephox/alloy.FormField.sketch方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript FormField.sketch方法的具體用法?TypeScript FormField.sketch怎麽用?TypeScript FormField.sketch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ephox/alloy.FormField
的用法示例。
在下文中一共展示了FormField.sketch方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: renderLabel
export const renderSelectBox = (spec: Types.SelectBox.SelectBox, providersBackstage: UiFactoryBackstageProviders): SketchSpec => {
const translatedOptions = Arr.map(spec.items, (item) => {
return {
text: providersBackstage.translate(item.text),
value: item.value
};
});
// DUPE with TextField.
const pLabel = spec.label.map((label) => renderLabel(label, providersBackstage));
const pField = AlloyFormField.parts().field({
// TODO: Alloy should not allow dom changing of an HTML select!
dom: { },
selectAttributes: {
size: spec.size
},
options: translatedOptions,
factory: AlloyHtmlSelect,
selectBehaviours: Behaviour.derive([
Tabstopping.config({ }),
AddEventsBehaviour.config('selectbox-change', [
AlloyEvents.run(NativeEvents.change(), (component, _) => {
AlloyTriggers.emitWith(component, formChangeEvent, { name: spec.name } );
})
])
])
});
const chevron = spec.size > 1 ? Option.none() :
Option.some({
dom: {
tag: 'div',
classes: ['tox-selectfield__icon-js'],
innerHtml: Icons.get('chevron-down', providersBackstage.icons)
}
});
const selectWrap: SimpleSpec = {
dom: {
tag: 'div',
classes: ['tox-selectfield']
},
components: Arr.flatten([[pField], chevron.toArray()])
};
return AlloyFormField.sketch({
dom: {
tag: 'div',
classes: ['tox-form__group']
},
components: Arr.flatten<AlloySpec>([pLabel.toArray(), [selectWrap]])
});
};
示例2: renderFormFieldSpecWith
const renderFormFieldWith = (pLabel: Option<AlloySpec>, pField: AlloySpec, extraClasses: string[]): SketchSpec => {
const spec = renderFormFieldSpecWith(pLabel, pField, extraClasses);
return AlloyFormField.sketch(spec);
};
示例3: renderLabel
export const renderColorInput = (spec: Types.ColorInput.ColorInput, sharedBackstage: UiFactoryBackstageShared, colorInputBackstage: UiFactoryBackstageForColorInput): SimpleSpec => {
const pField = FormField.parts().field({
factory: Input,
inputClasses: ['tox-textfield'],
onSetValue: (c) => Invalidating.run(c).get(() => { }),
inputBehaviours: Behaviour.derive([
Tabstopping.config({ }),
Invalidating.config({
invalidClass: 'tox-textbox-field-invalid',
getRoot: (comp) => {
return Traverse.parent(comp.element());
},
notify: {
onValid: (comp) => {
// onValid should pass through the value here
// We need a snapshot of the value validated.
const val = Representing.getValue(comp);
AlloyTriggers.emitWith(comp, colorInputChangeEvent, {
color: val
});
}
},
validator: {
validateOnLoad: false,
validate: (input) => {
const inputValue = Representing.getValue(input);
// Consider empty strings valid colours
if (inputValue.length === 0) {
return Future.pure(Result.value(true));
} else {
const span = Element.fromTag('span');
Css.set(span, 'background-color', inputValue);
const res = Css.getRaw(span, 'background-color').fold(
// TODO: Work out what we want to do here.
() => Result.error('blah'),
(_) => Result.value(inputValue)
);
return Future.pure(res);
}
}
}
})
]),
selectOnFocus: false
});
const pLabel: Option<AlloySpec> = spec.label.map((label) => renderLabel(label, sharedBackstage.providers));
const emitSwatchChange = (colorBit, value) => {
AlloyTriggers.emitWith(colorBit, colorSwatchChangeEvent, {
value
});
};
const onItemAction = (comp: AlloyComponent, value) => {
memColorButton.getOpt(comp).each((colorBit) => {
if (value === 'custom') {
colorInputBackstage.colorPicker((valueOpt) => {
valueOpt.fold(
() => AlloyTriggers.emit(colorBit, colorPickerCancelEvent),
(value) => {
emitSwatchChange(colorBit, value);
Settings.addColor(value);
}
);
}, '#ffffff');
} else if (value === 'remove') {
emitSwatchChange(colorBit, '');
} else {
emitSwatchChange(colorBit, value);
}
});
};
const memColorButton = Memento.record(
renderPanelButton({
dom: {
tag: 'span',
attributes: {
'aria-label': sharedBackstage.providers.translate('Color swatch')
}
},
layouts: Option.some({
onRtl: () => [ Layout.southeast ],
onLtr: () => [ Layout.southwest ]
}),
components: [],
fetch: ColorSwatch.getFetch(colorInputBackstage.getColors(), colorInputBackstage.hasCustomColors()),
columns: colorInputBackstage.getColorCols(),
presets: 'color',
onItemAction
}, sharedBackstage)
);
return FormField.sketch({
dom: {
//.........這裏部分代碼省略.........
示例4: makeIcon
export const renderCheckbox = (spec: CheckboxFoo, providerBackstage: UiFactoryBackstageProviders): SimpleSpec => {
const repBehaviour = Representing.config({
store: {
mode: 'manual',
getValue: (comp: AlloyComponent): boolean => {
const el = comp.element().dom() as HTMLInputElement;
return el.checked;
},
setValue: (comp: AlloyComponent, value: boolean) => {
const el = comp.element().dom() as HTMLInputElement;
el.checked = value;
}
}
});
const toggleCheckboxHandler = (comp) => {
comp.element().dom().click();
return Option.some(true);
};
const pField = AlloyFormField.parts().field({
factory: { sketch: Fun.identity },
dom: {
tag: 'input',
classes: ['tox-checkbox__input'],
attributes: {
type: 'checkbox'
}
},
behaviours: Behaviour.derive([
ComposingConfigs.self(),
Tabstopping.config({}),
Focusing.config({ }),
repBehaviour,
Keying.config({
mode: 'special',
onEnter: toggleCheckboxHandler,
onSpace: toggleCheckboxHandler,
stopSpaceKeyup: true
}),
AddEventsBehaviour.config('checkbox-events', [
AlloyEvents.run(NativeEvents.change(), (component, _) => {
AlloyTriggers.emitWith(component, formChangeEvent, { name: spec.name } );
})
])
]),
});
const pLabel = AlloyFormField.parts().label({
dom: {
tag: 'span',
classes: ['tox-checkbox__label'],
innerHtml: providerBackstage.translate(spec.label)
},
behaviours: Behaviour.derive([
Unselecting.config({})
])
});
const makeIcon = (className: string) => {
const iconName = className === 'checked' ? 'selected' : 'unselected';
return {
dom: {
tag: 'span',
classes: ['tox-icon', 'tox-checkbox-icon__' + className],
innerHtml: Icons.get(iconName, providerBackstage.icons)
}
};
};
const memIcons = Memento.record(
{
dom: {
tag: 'div',
classes: ['tox-checkbox__icons']
},
components: [
makeIcon('checked'),
makeIcon('unchecked')
]
}
);
return AlloyFormField.sketch({
dom: {
tag: 'label',
classes: ['tox-checkbox'],
},
components: [
pField,
memIcons.asSpec(),
pLabel
]
});
};
示例5: getItems
//.........這裏部分代碼省略.........
},
lazySink: backstage.shared.getSink,
parts: {
menu: MenuParts.part(false, 1, 'normal')
},
onExecute: (_menu, component, _entry) => {
AlloyTriggers.emitWith(component, formSubmitEvent, {});
},
onItemExecute: (typeahead, _sandbox, _item, _value) => {
updateHistory(typeahead);
AlloyTriggers.emitWith(typeahead, formChangeEvent, { name: spec.name });
}
});
const pLabel = spec.label.map((label) => renderLabel(label, providersBackstage)) as Option<AlloySpec>;
// TODO: Consider a way of merging with Checkbox.
const makeIcon = (name, errId: Option<string>, icon = name, label = name) => {
return ({
dom: {
tag: 'div',
classes: ['tox-icon', 'tox-control-wrap__status-icon-' + name],
innerHtml: Icons.get(icon, providersBackstage.icons),
attributes: {
'title': providersBackstage.translate(label),
'aria-live': 'polite',
...errId.fold(() => ({ }), (id) => ({ id }))
}
}
});
};
const memInvalidIcon = Memento.record(
makeIcon('invalid', Option.some(errorId), 'warning')
);
const memStatus = Memento.record({
dom: {
tag: 'div',
classes: ['tox-control-wrap__status-icon-wrap']
},
components: [
// Include the 'valid' and 'unknown' icons here only if they are to be displayed
memInvalidIcon.asSpec()
]
});
const optUrlPicker = urlBackstage.getUrlPicker(spec.filetype);
const browseUrlEvent = Id.generate('browser.url.event');
const memUrlBox = Memento.record(
{
dom: {
tag: 'div',
classes: ['tox-control-wrap']
},
components: [pField, memStatus.asSpec()]
}
);
const controlHWrapper = (): AlloySpec => {
return {
dom: {
tag: 'div',
classes: ['tox-form__controls-h-stack']
},
components: Arr.flatten([
[memUrlBox.asSpec()],
optUrlPicker.map(() => renderInputButton(spec.label, browseUrlEvent, 'tox-browse-url', 'browse', providersBackstage)).toArray()
])
};
};
const openUrlPicker = (comp: AlloyComponent) => {
Composing.getCurrent(comp).each((field) => {
const urlData = Representing.getValue(field);
optUrlPicker.each((picker) => {
picker(urlData).get((chosenData) => {
Representing.setValue(field, chosenData);
AlloyTriggers.emitWith(comp, formChangeEvent, { name: spec.name });
});
});
});
};
return AlloyFormField.sketch({
dom: renderFormFieldDom(),
components: pLabel.toArray().concat([
controlHWrapper()
]),
fieldBehaviours: Behaviour.derive([
AddEventsBehaviour.config('url-input-events', [
AlloyEvents.run<CustomEvent>(browseUrlEvent, openUrlPicker)
])
])
});
};