本文整理汇总了TypeScript中@ephox/alloy.FormField类的典型用法代码示例。如果您正苦于以下问题:TypeScript FormField类的具体用法?TypeScript FormField怎么用?TypeScript FormField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormField类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: renderLabel
export const renderAutocomplete = (spec: AutocompleteGoo, backstage: UiFactoryBackstage): SketchSpec => {
const pLabel = renderLabel(spec.label.getOr('?'), backstage.shared.providers);
const pField = AlloyFormField.parts().field({
factory: Typeahead,
dismissOnBlur: false,
inputClasses: [ 'tox-textfield' ],
minChars: 1,
fetch: (input) => {
const value = Representing.getValue(input);
const items = spec.getItems(value);
const tdata = NestedMenus.build(items, ItemResponse.BUBBLE_TO_SANDBOX, backstage);
return Future.pure(tdata);
},
markers: {
// FIX:
openClass: 'dog'
},
lazySink: backstage.shared.getSink,
parts : {
menu: MenuParts.part(false, 1, 'normal')
}
});
return renderFormField(Option.some(pLabel), pField);
};
示例3:
AlloyEvents.run<ColorSwatchChangeEvent>(colorSwatchChangeEvent, (comp, se) => {
FormField.getField(comp).each((field) => {
Representing.setValue(field, se.event().value());
// Focus the field now that we've set its value
Composing.getCurrent(comp).each(Focusing.focus);
});
}),
示例4:
const renderLabel = (label: string, providersBackstage: UiFactoryBackstageProviders): AlloySpec => {
return AlloyFormField.parts().label({
dom: {
tag: 'label',
classes: ['tox-label'],
innerHtml: providersBackstage.translate(label)
}
});
};
示例5: function
const getFieldPart = (isField1) => AlloyFormField.parts().field({
factory: AlloyInput,
inputClasses: ['tox-textfield'],
inputBehaviours: Behaviour.derive([
Tabstopping.config({}),
AddEventsBehaviour.config('size-input-events', [
AlloyEvents.run(NativeEvents.focusin(), function (component, simulatedEvent) {
AlloyTriggers.emitWith(component, ratioEvent, { isField1 });
}),
AlloyEvents.run(NativeEvents.change(), function (component, simulatedEvent) {
AlloyTriggers.emitWith(component, formChangeEvent, { name: spec.name });
})
])
]),
selectOnFocus: false
});
示例6: renderLabel
export const renderListbox = (spec: ListboxFoo, providersBackstage: UiFactoryBackstageProviders): SketchSpec => {
const pLabel = renderLabel(spec.label, providersBackstage);
const pField = AlloyFormField.parts().field({
factory: HtmlSelect,
dom: {
classes: [ 'mce-select-field' ]
},
selectBehaviours: Behaviour.derive([
Tabstopping.config({ })
]),
options: spec.values,
// FIX: Don't use undefined here.
data: spec.initialValue.getOr(undefined)
});
return renderFormField(Option.some(pLabel), pField);
};
示例7: getDynamicSource
const renderIFrame = (spec: Types.Iframe.Iframe, providersBackstage: UiFactoryBackstageProviders) => {
const isSandbox = platformNeedsSandboxing && spec.sandboxed;
const attributes = {
...spec.label.map<{ title?: string }>((title) => ({title})).getOr({}),
...isSandbox ? { sandbox : 'allow-scripts allow-same-origin' } : { }
};
const sourcing = getDynamicSource(isSandbox);
const pLabel = spec.label.map((label) => renderLabel(label, providersBackstage));
const factory = (newSpec: { uid: string }) => {
return NavigableObject.craft(
{
// We need to use the part uid or the label and field won't be linked with ARIA
uid: newSpec.uid,
dom: {
tag: 'iframe',
attributes
},
behaviours: Behaviour.derive([
Tabstopping.config({ }),
Focusing.config({ }),
RepresentingConfigs.withComp(Option.none(), sourcing.getValue, sourcing.setValue)
])
}
);
};
// Note, it's not going to handle escape at this point.
const pField = FormField.parts().field({
factory: { sketch: factory }
});
return renderFormFieldWith(pLabel, pField, ['tox-form__group--stretched']);
};
示例8: return
//.........这里部分代码省略.........
const onSelect = (component, simulatedEvent) => {
const files = simulatedEvent.event().raw().target.files;
handleFiles(component, files);
};
const handleFiles = (component, files: FileList) => {
Representing.setValue(component, filterByExtension(files));
AlloyTriggers.emitWith(component, formChangeEvent, { name: spec.name });
};
const memInput = Memento.record(
{
dom: {
tag: 'input',
attributes: {
type: 'file',
accept: 'image/*'
},
styles: {
display: 'none'
}
},
behaviours: Behaviour.derive([
AddEventsBehaviour.config('input-file-events', [
AlloyEvents.cutter(SystemEvents.tapOrClick())
])
])
}
);
const renderField = (s) => {
return {
uid: s.uid,
dom: {
tag: 'div',
classes: [ 'tox-dropzone-container' ]
},
behaviours: Behaviour.derive([
RepresentingConfigs.memory([ ]),
ComposingConfigs.self(),
Disabling.config({}),
Toggling.config({
toggleClass: 'dragenter',
toggleOnExecute: false
}),
AddEventsBehaviour.config('dropzone-events', [
AlloyEvents.run('dragenter', sequence([ stopper, Toggling.toggle ])),
AlloyEvents.run('dragleave', sequence([ stopper, Toggling.toggle ])),
AlloyEvents.run('dragover', stopper),
AlloyEvents.run('drop', sequence([ stopper, onDrop ])),
AlloyEvents.run(NativeEvents.change(), onSelect)
]),
]),
components: [
{
dom: {
tag: 'div',
classes: [ 'tox-dropzone' ],
styles: {}
},
components: [
{
dom: {
tag: 'p',
innerHtml: providersBackstage.translate('Drop an image here')
}
},
Button.sketch({
dom: {
tag: 'button',
innerHtml: providersBackstage.translate('Browse for an image'),
styles: {
position: 'relative'
},
classes: [ 'tox-button', 'tox-button--secondary']
},
components: [
memInput.asSpec()
],
action: (comp) => {
const inputComp = memInput.get(comp);
inputComp.element().dom().click();
},
buttonBehaviours: Behaviour.derive([
Tabstopping.config({ })
])
})
]
}
]
};
};
const pLabel = spec.label.map((label) => renderLabel(label, providersBackstage));
const pField = AlloyFormField.parts().field({
factory: { sketch: renderField }
});
return renderFormFieldWith(pLabel, pField, ['tox-form__group--stretched']);
};
示例9: renderLabel
export const renderCollection = (spec: Types.Collection.Collection, providersBackstage: UiFactoryBackstageProviders): SketchSpec => {
// DUPE with TextField.
const pLabel = spec.label.map((label) => renderLabel(label, providersBackstage));
const runOnItem = (f: (c: AlloyComponent, tgt: Element, itemValue: string) => void) => <T extends EventFormat>(comp: AlloyComponent, se: SimulatedEvent<T>) => {
SelectorFind.closest(se.event().target(), '[data-collection-item-value]').each((target) => {
f(comp, target, Attr.get(target, 'data-collection-item-value'));
});
};
const escapeAttribute = (ch) => {
if (ch === '"') { return '"'; }
return ch;
};
const setContents = (comp, items) => {
const htmlLines = Arr.map(items, (item) => {
const textContent = spec.columns === 1 ? `<div class="tox-collection__item-label">${item.text}</div>` : '';
const iconContent = `<div class="tox-collection__item-icon">${item.icon}</div>`;
// Replacing the hyphens and underscores in collection items with spaces
// to ensure the screen readers pronounce the words correctly.
// This is only for aria purposes. Emoticon and Special Character names will still use _ and - for autocompletion.
const mapItemName = {
'_': ' ',
' - ': ' ',
'-': ' '
};
// Title attribute is added here to provide tooltips which might be helpful to sighted users.
// Using aria-label here overrides the Apple description of emojis and special characters in Mac/ MS description in Windows.
// But if only the title attribute is used instead, the names are read out twice. i.e., the description followed by the item.text.
const ariaLabel = item.text.replace(/\_| \- |\-/g, (match) => {
return mapItemName[match];
});
return `<div class="tox-collection__item" tabindex="-1" data-collection-item-value="${escapeAttribute(item.value)}" title="${ariaLabel}" aria-label="${ariaLabel}">${iconContent}${textContent}</div>`;
});
const chunks = spec.columns > 1 && spec.columns !== 'auto' ? Arr.chunk(htmlLines, spec.columns) : [ htmlLines ];
const html = Arr.map(chunks, (ch) => {
return `<div class="tox-collection__group">${ch.join('')}</div>`;
});
Html.set(comp.element(), html.join(''));
};
const collectionEvents = [
AlloyEvents.run<SugarEvent>(NativeEvents.mouseover(), runOnItem((comp, tgt) => {
Focus.focus(tgt);
})),
AlloyEvents.run<SugarEvent>(SystemEvents.tapOrClick(), runOnItem((comp, tgt, itemValue) => {
AlloyTriggers.emitWith(comp, formActionEvent, {
name: spec.name,
value: itemValue
});
})),
AlloyEvents.run(NativeEvents.focusin(), runOnItem((comp, tgt, itemValue) => {
SelectorFind.descendant(comp.element(), '.' + ItemClasses.activeClass).each((currentActive) => {
Class.remove(currentActive, ItemClasses.activeClass);
});
Class.add(tgt, ItemClasses.activeClass);
})),
AlloyEvents.run(NativeEvents.focusout(), runOnItem((comp, tgt, itemValue) => {
SelectorFind.descendant(comp.element(), '.' + ItemClasses.activeClass).each((currentActive) => {
Class.remove(currentActive, ItemClasses.activeClass);
});
})),
AlloyEvents.runOnExecute(runOnItem((comp, tgt, itemValue) => {
AlloyTriggers.emitWith(comp, formActionEvent, {
name: spec.name,
value: itemValue
});
}))
];
const pField = AlloyFormField.parts().field({
dom: {
tag: 'div',
// FIX: Read from columns
classes: [ 'tox-collection' ].concat(spec.columns !== 1 ? [ 'tox-collection--grid' ] : [ 'tox-collection--list' ])
},
components: [ ],
factory: { sketch: Fun.identity },
behaviours: Behaviour.derive([
Replacing.config({ }),
Representing.config({
store: {
mode: 'memory',
initialValue: [ ]
},
onSetValue: (comp, items) => {
setContents(comp, items);
if (spec.columns === 'auto') {
detectSize(comp, 5, 'tox-collection__item').each(({ numRows, numColumns }) => {
Keying.setGridSize(comp, numRows, numColumns);
});
}
AlloyTriggers.emit(comp, formResizeEvent);
//.........这里部分代码省略.........