UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

810 lines (809 loc) 32.9 kB
/*! * KoliBri - The accessible HTML-Standard */ import { __decorate } from "tslib"; import { h } from "@stencil/core"; import clsx from "../../utils/clsx"; import { KolButtonWcTag } from "../../core/component-names"; import KolFormFieldStateWrapperFc from "../../functional-component-wrappers/FormFieldStateWrapper/FormFieldStateWrapper"; import KolInputContainerFc from "../../functional-component-wrappers/InputContainerStateWrapper/InputContainerStateWrapper"; import KolInputStateWrapperFc from "../../functional-component-wrappers/InputStateWrapper/InputStateWrapper"; import { translate } from "../../i18n"; import { createUniqueId } from "../../utils/dev.utils"; import { createCtaRef, delegateClick, delegateFocus } from "../../utils/element-interaction"; import { InputFileController } from "./controller"; export class KolInputFile { async getValue() { var _a; return (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.files; } async focus() { } async click() { } async reset() { this.controller.setFormAssociatedValue(''); this.filename = this.translateFilenameText; this.hasFileSelected = false; if (this.ctaRef.el) { this.ctaRef.el.value = ''; } } getFormFieldProps() { return { state: this.state, class: clsx('kol-input-file', 'file'), tooltipAlign: this._tooltipAlign, alert: this.showAsAlert(), }; } getInputProps() { return Object.assign(Object.assign({ ref: this.ctaRef, state: this.state, type: 'file', accept: this.state._accept, multiple: this.state._multiple }, this.controller.onFacade), { onChange: this.onChange, onInput: this.onInput, onFocus: (event) => { this.controller.onFacade.onFocus(event); this.inputHasFocus = true; }, onBlur: (event) => { this.controller.onFacade.onBlur(event); this.inputHasFocus = false; } }); } render() { return (h(KolFormFieldStateWrapperFc, Object.assign({ key: 'db89ff748c30a1469075247adcff35dab7e73103' }, this.getFormFieldProps()), h(KolInputContainerFc, { key: 'adbf100f3b3b70f70633a631587de31869bea517', state: this.state }, h("span", { key: '86bd5da99b26aa0a12833bd71f8b029c0772b7f7', class: clsx('kol-input-container__filename', { 'kol-input-container__filename--has-file': this.hasFileSelected }) }, this.filename), h(KolInputStateWrapperFc, Object.assign({ key: '716a7a996a6eb574cccdbab856fa0506906302f2' }, this.getInputProps())), h(KolButtonWcTag, { key: 'f1d03af617865ce810ff7c8536f7400d88ddec9e', class: "kol-input-container__button", _label: this.translateDataBrowseText, _variant: "primary", _disabled: this._disabled })))); } constructor() { this.ctaRef = createCtaRef(); this.translateDataBrowseText = translate('kol-data-browse-text'); this.translateFilenameText = translate('kol-filename-text'); this._disabled = false; this._hideMsg = false; this._hideLabel = false; this._hint = ''; this._multiple = false; this._required = false; this._tooltipAlign = 'top'; this._touched = false; this.filename = this.translateFilenameText; this.hasFileSelected = false; this.state = { _hideMsg: false, _id: createUniqueId('input-file'), _label: '', }; this.inputHasFocus = false; this.onDragOver = (event) => { var _a, _b, _c; event.preventDefault(); (_c = (_b = (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.parentElement) === null || _c === void 0 ? void 0 : _c.classList.add('kol-input-container--is-dragover'); }; this.onDragLeave = () => { var _a, _b, _c; (_c = (_b = (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.parentElement) === null || _c === void 0 ? void 0 : _c.classList.remove('kol-input-container--is-dragover'); }; this.onDrop = (event) => { var _a, _b, _c; event.preventDefault(); if (!this.ctaRef.el) { return; } (_b = (_a = this.ctaRef.el.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.classList.remove('kol-input-container--is-dragover'); if ((_c = event.dataTransfer) === null || _c === void 0 ? void 0 : _c.files.length) { const files = event.dataTransfer.files; this.ctaRef.el.files = files; this.filename = Array.from(files) .map((file) => file.name) .join(', '); this.controller.setFormAssociatedValue(files); this.controller.onFacade.onChange(event, files); this.controller.onFacade.onInput(event, false, files); } }; this.onChange = (event) => { if (this.ctaRef.el instanceof HTMLInputElement && this.ctaRef.el.type === 'file') { const value = this.ctaRef.el.files; this.hasFileSelected = !!(value === null || value === void 0 ? void 0 : value.length); this.filename = (value === null || value === void 0 ? void 0 : value.length) ? Array.from(value) .map((file) => file.name) .join(', ') : this.translateFilenameText; this.controller.onFacade.onChange(event, value); this.controller.setFormAssociatedValue(value); } }; this.onInput = (event) => { if (this.ctaRef.el instanceof HTMLInputElement && this.ctaRef.el.type === 'file') { const files = this.ctaRef.el.files; this.controller.onFacade.onInput(event, false, files); } }; this.controller = new InputFileController(this, 'file', this.host); } showAsAlert() { return Boolean(this.state._touched) && !this.inputHasFocus; } validateAccept(value) { this.controller.validateAccept(value); } validateAccessKey(value) { this.controller.validateAccessKey(value); } validateDisabled(value) { this.controller.validateDisabled(value); } validateHideMsg(value) { this.controller.validateHideMsg(value); } validateHideLabel(value) { this.controller.validateHideLabel(value); } validateHint(value) { this.controller.validateHint(value); } validateIcons(value) { this.controller.validateIcons(value); } validateLabel(value) { this.controller.validateLabel(value); } validateMsg(value) { this.controller.validateMsg(value); } validateMultiple(value) { this.controller.validateMultiple(value); } validateName(value) { this.controller.validateName(value); } validateOn(value) { this.controller.validateOn(value); } validateRequired(value) { this.controller.validateRequired(value); } validateShortKey(value) { this.controller.validateShortKey(value); } validateSmartButton(value) { this.controller.validateSmartButton(value); } validateSyncValueBySelector(value) { this.controller.validateSyncValueBySelector(value); } validateTouched(value) { this.controller.validateTouched(value); } validateVariant(value) { this.controller.validateVariant(value); } componentWillLoad() { this._touched = this._touched === true; this.controller.componentWillLoad(); } componentDidLoad() { var _a, _b; const container = (_b = (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.parentElement; container === null || container === void 0 ? void 0 : container.addEventListener('dragover', this.onDragOver); container === null || container === void 0 ? void 0 : container.addEventListener('dragleave', this.onDragLeave); container === null || container === void 0 ? void 0 : container.addEventListener('drop', this.onDrop); } static get is() { return "kol-input-file"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "default": ["./style.scss"] }; } static get styleUrls() { return { "default": ["style.css"] }; } static get properties() { return { "_accept": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines which file formats are accepted." }, "getter": false, "setter": false, "reflect": false, "attribute": "_accept" }, "_accessKey": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines the key combination that can be used to trigger or focus the component's interactive element." }, "getter": false, "setter": false, "reflect": false, "attribute": "_access-key" }, "_disabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "TODO", "text": ": Change type back to `DisabledPropType` after Stencil#4663 has been resolved." }], "text": "Makes the element not focusable and ignore all events." }, "getter": false, "setter": false, "reflect": false, "attribute": "_disabled", "defaultValue": "false" }, "_hideMsg": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "TODO", "text": ": Change type back to `HideMsgPropType` after Stencil#4663 has been resolved." }], "text": "Hides the error message but leaves it in the DOM for the input's aria-describedby." }, "getter": false, "setter": false, "reflect": false, "attribute": "_hide-msg", "defaultValue": "false" }, "_hideLabel": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "TODO", "text": ": Change type back to `HideLabelPropType` after Stencil#4663 has been resolved." }], "text": "Hides the caption by default and displays the caption text with a tooltip when the\ninteractive element is focused or the mouse is over it." }, "getter": false, "setter": false, "reflect": false, "attribute": "_hide-label", "defaultValue": "false" }, "_hint": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines the hint text." }, "getter": false, "setter": false, "reflect": false, "attribute": "_hint", "defaultValue": "''" }, "_icons": { "type": "string", "mutable": false, "complexType": { "original": "IconsHorizontalPropType", "resolved": "string | undefined | { right?: IconOrIconClass | undefined; left?: IconOrIconClass | undefined; }", "references": { "IconsHorizontalPropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::IconsHorizontalPropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines the icon classnames (e.g. `_icons=\"fa-solid fa-user\"`)." }, "getter": false, "setter": false, "reflect": false, "attribute": "_icons" }, "_label": { "type": "string", "mutable": false, "complexType": { "original": "LabelWithExpertSlotPropType", "resolved": "string", "references": { "LabelWithExpertSlotPropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::LabelWithExpertSlotPropType" } } }, "required": true, "optional": false, "docs": { "tags": [], "text": "Defines the visible or semantic label of the component (e.g. aria-label, label, headline, caption, summary, etc.). Set to `false` to enable the expert slot." }, "getter": false, "setter": false, "reflect": false, "attribute": "_label" }, "_msg": { "type": "string", "mutable": false, "complexType": { "original": "Stringified<MsgPropType>", "resolved": "Omit<AlertProps, \"_on\" | \"_label\" | \"_level\" | \"_variant\" | \"_hasCloser\"> & { _description: string; } | string | undefined", "references": { "Stringified": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::Stringified" }, "MsgPropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::MsgPropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines the properties for a message rendered as Alert component." }, "getter": false, "setter": false, "reflect": false, "attribute": "_msg" }, "_multiple": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "TODO", "text": ": Change type back to `MultiplePropType` after Stencil#4663 has been resolved." }], "text": "Makes the input accept multiple inputs." }, "getter": false, "setter": false, "reflect": false, "attribute": "_multiple", "defaultValue": "false" }, "_name": { "type": "string", "mutable": false, "complexType": { "original": "NamePropType", "resolved": "string | undefined", "references": { "NamePropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::NamePropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines the technical name of an input field." }, "getter": false, "setter": false, "reflect": false, "attribute": "_name" }, "_on": { "type": "unknown", "mutable": false, "complexType": { "original": "InputTypeOnDefault", "resolved": "InputTypeOnBlur & InputTypeOnClick & InputTypeOnChange & InputTypeOnFocus & InputTypeOnInput & InputTypeOnKeyDown | undefined", "references": { "InputTypeOnDefault": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::InputTypeOnDefault" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Gibt die EventCallback-Funktionen f\u00FCr das Input-Event an." }, "getter": false, "setter": false }, "_required": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "TODO", "text": ": Change type back to `RequiredPropType` after Stencil#4663 has been resolved." }], "text": "Makes the input element required." }, "getter": false, "setter": false, "reflect": false, "attribute": "_required", "defaultValue": "false" }, "_shortKey": { "type": "string", "mutable": false, "complexType": { "original": "ShortKeyPropType", "resolved": "string | undefined", "references": { "ShortKeyPropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::ShortKeyPropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Adds a visual shortcut hint after the label and instructs the screen reader to read the shortcut aloud." }, "getter": false, "setter": false, "reflect": false, "attribute": "_short-key" }, "_smartButton": { "type": "string", "mutable": false, "complexType": { "original": "Stringified<InternalButtonProps>", "resolved": "string | undefined | { _label: string; } & { _type?: \"button\" | \"reset\" | \"submit\" | undefined; _accessKey?: string | undefined; _on?: ButtonCallbacksPropType<StencilUnknown> | undefined; _ariaExpanded?: boolean | undefined; _tabIndex?: number | undefined; _value?: StencilUnknown; _role?: \"tab\" | \"treeitem\" | undefined; _ariaControls?: string | undefined; _ariaDescription?: string | undefined; _ariaSelected?: boolean | undefined; _customClass?: string | undefined; _disabled?: boolean | undefined; _hideLabel?: boolean | undefined; _icons?: IconsPropType | undefined; _id?: string | undefined; _inline?: boolean | undefined; _name?: string | undefined; _shortKey?: string | undefined; _syncValueBySelector?: string | undefined; _tooltipAlign?: AlignPropType | undefined; _variant?: string | undefined; }", "references": { "Stringified": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::Stringified" }, "InternalButtonProps": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::InternalButtonProps" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Allows to add a button with an arbitrary action within the element (_hide-label only)." }, "getter": false, "setter": false, "reflect": false, "attribute": "_smart-button" }, "_syncValueBySelector": { "type": "string", "mutable": false, "complexType": { "original": "SyncValueBySelectorPropType", "resolved": "string | undefined", "references": { "SyncValueBySelectorPropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::SyncValueBySelectorPropType" } } }, "required": false, "optional": true, "docs": { "tags": [{ "name": "internal", "text": undefined }], "text": "Selector for synchronizing the value with another input element." }, "getter": false, "setter": false, "reflect": false, "attribute": "_sync-value-by-selector" }, "_tooltipAlign": { "type": "string", "mutable": false, "complexType": { "original": "TooltipAlignPropType", "resolved": "\"bottom\" | \"left\" | \"right\" | \"top\" | undefined", "references": { "TooltipAlignPropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::TooltipAlignPropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines where to show the Tooltip preferably: top, right, bottom or left." }, "getter": false, "setter": false, "reflect": false, "attribute": "_tooltip-align", "defaultValue": "'top'" }, "_touched": { "type": "boolean", "mutable": true, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "TODO", "text": ": Change type back to `TouchedPropType` after Stencil#4663 has been resolved." }], "text": "Shows if the input was touched by a user." }, "getter": false, "setter": false, "reflect": true, "attribute": "_touched", "defaultValue": "false" }, "_variant": { "type": "string", "mutable": false, "complexType": { "original": "VariantClassNamePropType", "resolved": "string | undefined", "references": { "VariantClassNamePropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::VariantClassNamePropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines which variant should be used for presentation." }, "getter": false, "setter": false, "reflect": false, "attribute": "_variant" } }; } static get states() { return { "filename": {}, "hasFileSelected": {}, "state": {}, "inputHasFocus": {} }; } static get methods() { return { "getValue": { "complexType": { "signature": "() => Promise<FileList | null | undefined>", "parameters": [], "references": { "Promise": { "location": "global", "id": "global::Promise" }, "FileList": { "location": "global", "id": "global::FileList" } }, "return": "Promise<FileList | null | undefined>" }, "docs": { "text": "Returns the current value.", "tags": [] } }, "focus": { "complexType": { "signature": "() => Promise<void>", "parameters": [], "references": { "Promise": { "location": "global", "id": "global::Promise" } }, "return": "Promise<void>" }, "docs": { "text": "Sets focus on the internal element.", "tags": [] } }, "click": { "complexType": { "signature": "() => Promise<void>", "parameters": [], "references": { "Promise": { "location": "global", "id": "global::Promise" } }, "return": "Promise<void>" }, "docs": { "text": "Clicks the primary interactive element inside this component.", "tags": [] } }, "reset": { "complexType": { "signature": "() => Promise<void>", "parameters": [], "references": { "Promise": { "location": "global", "id": "global::Promise" } }, "return": "Promise<void>" }, "docs": { "text": "Resets the component's value.", "tags": [] } } }; } static get elementRef() { return "host"; } static get watchers() { return [{ "propName": "_accept", "methodName": "validateAccept" }, { "propName": "_accessKey", "methodName": "validateAccessKey" }, { "propName": "_disabled", "methodName": "validateDisabled" }, { "propName": "_hideMsg", "methodName": "validateHideMsg" }, { "propName": "_hideLabel", "methodName": "validateHideLabel" }, { "propName": "_hint", "methodName": "validateHint" }, { "propName": "_icons", "methodName": "validateIcons" }, { "propName": "_label", "methodName": "validateLabel" }, { "propName": "_msg", "methodName": "validateMsg" }, { "propName": "_multiple", "methodName": "validateMultiple" }, { "propName": "_name", "methodName": "validateName" }, { "propName": "_on", "methodName": "validateOn" }, { "propName": "_required", "methodName": "validateRequired" }, { "propName": "_shortKey", "methodName": "validateShortKey" }, { "propName": "_smartButton", "methodName": "validateSmartButton" }, { "propName": "_syncValueBySelector", "methodName": "validateSyncValueBySelector" }, { "propName": "_touched", "methodName": "validateTouched" }, { "propName": "_variant", "methodName": "validateVariant" }]; } } __decorate([ delegateFocus('ctaRef') ], KolInputFile.prototype, "focus", null); __decorate([ delegateClick('ctaRef') ], KolInputFile.prototype, "click", null); //# sourceMappingURL=shadow.js.map