UNPKG

@public-ui/components

Version:

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

961 lines (960 loc) 36.5 kB
/*! * KoliBri - The accessible HTML-Standard */ import { __decorate } from "tslib"; import { h } from "@stencil/core"; import clsx from "../../utils/clsx"; import KolFormFieldStateWrapperFc from "../../functional-component-wrappers/FormFieldStateWrapper/FormFieldStateWrapper"; import KolInputContainerStateWrapperFc from "../../functional-component-wrappers/InputContainerStateWrapper/InputContainerStateWrapper"; import KolTextAreaStateWrapperFc from "../../functional-component-wrappers/TextAreaStateWrapper/TextAreaStateWrapper"; import { createRelatedUniqueId, createUniqueId } from "../../utils/dev.utils"; import { createCtaRef, delegateClick, delegateFocus } from "../../utils/element-interaction"; import { TextareaController } from "./controller"; const increaseTextareaHeight = (el) => { el.style.overflow = 'hidden'; const currentRows = el.rows; const rowHeight = el.clientHeight / currentRows; el.rows = 1; const nextRows = Math.round(el.scrollHeight / rowHeight); el.rows = currentRows; return nextRows; }; export class KolTextarea { async getValue() { var _a; return (_a = this.ctaRef.el) === null || _a === void 0 ? void 0 : _a.value; } async focus() { } async click() { } getFormFieldProps() { return { state: this.state, class: clsx('kol-form-field-textarea', { 'kol-form-field--has-value': this.state._hasValue, 'kol-form-field--has-counter': this.controller.hasSoftCharacterLimit() || this.controller.hasCounter(), }), tooltipAlign: this._tooltipAlign, alert: this.showAsAlert(), }; } getTextAreaProps() { const ariaDescribedBy = typeof this.state._maxLength === 'number' ? [createRelatedUniqueId(this.state._id, 'character-limit-hint')] : undefined; return Object.assign(Object.assign({ ref: this.ctaRef, state: this.state, style: { resize: this.state._resize, }, ariaDescribedBy }, this.controller.onFacade), { 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: 'c35b9c0929d522c0ad02fb0e20510c8ac2434ea4' }, this.getFormFieldProps()), h(KolInputContainerStateWrapperFc, { key: '14b65a21892e945b15e6932e2590ec7eeeb2a626', state: this.state }, h(KolTextAreaStateWrapperFc, Object.assign({ key: 'eeb210bddef4feac525622a76b1dc58d4dea7a7b' }, this.getTextAreaProps()))))); } constructor() { this.ctaRef = createCtaRef(); this._adjustHeight = false; this._disabled = false; this._hideMsg = false; this._hideLabel = false; this._hint = ''; this._hasCounter = false; this._maxLengthBehavior = 'hard'; this._readOnly = false; this._resize = 'vertical'; this._required = false; this._tooltipAlign = 'top'; this._touched = false; this.state = { _adjustHeight: false, _currentLength: 0, _currentLengthDebounced: 0, _hasValue: false, _hideMsg: false, _id: createUniqueId('textarea'), _label: '', _resize: 'vertical', }; this.inputHasFocus = false; this.onInput = (event) => { if (this.ctaRef.el instanceof HTMLTextAreaElement) { this._value = this.ctaRef.el.value; if (this.state._adjustHeight) { this._rows = increaseTextareaHeight(this.ctaRef.el); } this.controller.onFacade.onInput(event); } }; this.controller = new TextareaController(this, 'textarea', this.host); } showAsAlert() { return Boolean(this.state._touched) && !this.inputHasFocus; } validateAccessKey(value) { this.controller.validateAccessKey(value); } validateAdjustHeight(value) { this.controller.validateAdjustHeight(value); } validateDisabled(value) { this.controller.validateDisabled(value); } validateHideMsg(value) { this.controller.validateHideMsg(value); } validateHideLabel(value) { this.controller.validateHideLabel(value); } validateHasCounter(value) { this.controller.validateHasCounter(value); } validateHint(value) { this.controller.validateHint(value); } validateIcons(value) { this.controller.validateIcons(value); } validateLabel(value) { this.controller.validateLabel(value); } validateMaxLength(value) { this.controller.validateMaxLength(value); } validateMaxLengthBehavior(value) { this.controller.validateMaxLengthBehavior(value); } validateMsg(value) { this.controller.validateMsg(value); } validateName(value) { this.controller.validateName(value); } validateOn(value) { this.controller.validateOn(value); } validatePlaceholder(value) { this.controller.validatePlaceholder(value); } validateReadOnly(value) { this.controller.validateReadOnly(value); } validateResize(value) { this.controller.validateResize(value); } validateRequired(value) { this.controller.validateRequired(value); } validateRows(value) { this.controller.validateRows(value); } validateShortKey(value) { this.controller.validateShortKey(value); } validateSpellCheck(value) { this.controller.validateSpellCheck(value); } validateSyncValueBySelector(value) { this.controller.validateSyncValueBySelector(value); } validateTouched(value) { this.controller.validateTouched(value); } validateValue(value) { this.controller.validateValue(value); } validateVariant(value) { this.controller.validateVariant(value); } componentDidLoad() { setTimeout(() => { var _a; if (this._adjustHeight === true && this.ctaRef.el) { this._rows = ((_a = this.state) === null || _a === void 0 ? void 0 : _a._rows) && this.state._rows > increaseTextareaHeight(this.ctaRef.el) ? this.state._rows : increaseTextareaHeight(this.ctaRef.el); } else if (!this._rows) { this._rows = 1; } }); } componentWillLoad() { this._touched = this._touched === true; this.controller.componentWillLoad(); this.state._hasValue = !!this.state._value; this.controller.addValueChangeListener((v) => (this.state._hasValue = !!v)); } static get is() { return "kol-textarea"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "default": ["./style.scss"] }; } static get styleUrls() { return { "default": ["style.css"] }; } static get properties() { return { "_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" }, "_adjustHeight": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "TODO", "text": ": change back to AdjustHeightPropType after stencil #4663 has been resolved" }], "text": "Adjusts the height of the element to its content." }, "getter": false, "setter": false, "reflect": false, "attribute": "_adjust-height", "defaultValue": "false" }, "_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" }, "_maxLength": { "type": "number", "mutable": false, "complexType": { "original": "number", "resolved": "number | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines the maximum number of input characters." }, "getter": false, "setter": false, "reflect": false, "attribute": "_max-length" }, "_hasCounter": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Shows a character counter for the input element." }, "getter": false, "setter": false, "reflect": false, "attribute": "_has-counter", "defaultValue": "false" }, "_maxLengthBehavior": { "type": "string", "mutable": false, "complexType": { "original": "MaxLengthBehaviorPropType", "resolved": "\"hard\" | \"soft\" | undefined", "references": { "MaxLengthBehaviorPropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::MaxLengthBehaviorPropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines the behavior when maxLength is set. 'hard' sets the maxlength attribute, 'soft' shows a character counter without preventing input." }, "getter": false, "setter": false, "reflect": false, "attribute": "_max-length-behavior", "defaultValue": "'hard'" }, "_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" }, "_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 }, "_placeholder": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines the placeholder for input field. To be shown when there's no value." }, "getter": false, "setter": false, "reflect": false, "attribute": "_placeholder" }, "_readOnly": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "TODO", "text": ": Change type back to `ReadOnlyPropType` after Stencil#4663 has been resolved." }], "text": "Makes the input element read only." }, "getter": false, "setter": false, "reflect": false, "attribute": "_read-only", "defaultValue": "false" }, "_resize": { "type": "string", "mutable": false, "complexType": { "original": "TextareaResizePropType", "resolved": "\"none\" | \"vertical\" | undefined", "references": { "TextareaResizePropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::TextareaResizePropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines whether and in which direction the size of the input can be changed by the user. (https://developer.mozilla.org/de/docs/Web/CSS/resize)\nIn version 3 (v3), horizontal resizing is abolished. The corresponding property is then reduced to the properties `vertical` (default) and `none`." }, "getter": false, "setter": false, "reflect": false, "attribute": "_resize", "defaultValue": "'vertical'" }, "_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" }, "_rows": { "type": "number", "mutable": true, "complexType": { "original": "RowsPropType", "resolved": "number | undefined", "references": { "RowsPropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::RowsPropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Maximum number of visible rows of the element." }, "getter": false, "setter": false, "reflect": false, "attribute": "_rows" }, "_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" }, "_spellCheck": { "type": "boolean", "mutable": false, "complexType": { "original": "SpellCheckPropType", "resolved": "boolean | undefined", "references": { "SpellCheckPropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::SpellCheckPropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines whether the browser should check the spelling and grammar." }, "getter": false, "setter": false, "reflect": false, "attribute": "_spell-check" }, "_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" }, "_value": { "type": "string", "mutable": true, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines the value of the element." }, "getter": false, "setter": false, "reflect": true, "attribute": "_value" }, "_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 { "state": {}, "inputHasFocus": {} }; } static get methods() { return { "getValue": { "complexType": { "signature": "() => Promise<string | undefined>", "parameters": [], "references": { "Promise": { "location": "global", "id": "global::Promise" } }, "return": "Promise<string | 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": [] } } }; } static get elementRef() { return "host"; } static get watchers() { return [{ "propName": "_accessKey", "methodName": "validateAccessKey" }, { "propName": "_adjustHeight", "methodName": "validateAdjustHeight" }, { "propName": "_disabled", "methodName": "validateDisabled" }, { "propName": "_hideMsg", "methodName": "validateHideMsg" }, { "propName": "_hideLabel", "methodName": "validateHideLabel" }, { "propName": "_hasCounter", "methodName": "validateHasCounter" }, { "propName": "_hint", "methodName": "validateHint" }, { "propName": "_icons", "methodName": "validateIcons" }, { "propName": "_label", "methodName": "validateLabel" }, { "propName": "_maxLength", "methodName": "validateMaxLength" }, { "propName": "_maxLengthBehavior", "methodName": "validateMaxLengthBehavior" }, { "propName": "_msg", "methodName": "validateMsg" }, { "propName": "_name", "methodName": "validateName" }, { "propName": "_on", "methodName": "validateOn" }, { "propName": "_placeholder", "methodName": "validatePlaceholder" }, { "propName": "_readOnly", "methodName": "validateReadOnly" }, { "propName": "_resize", "methodName": "validateResize" }, { "propName": "_required", "methodName": "validateRequired" }, { "propName": "_rows", "methodName": "validateRows" }, { "propName": "_shortKey", "methodName": "validateShortKey" }, { "propName": "_spellCheck", "methodName": "validateSpellCheck" }, { "propName": "_syncValueBySelector", "methodName": "validateSyncValueBySelector" }, { "propName": "_touched", "methodName": "validateTouched" }, { "propName": "_value", "methodName": "validateValue" }, { "propName": "_variant", "methodName": "validateVariant" }]; } } __decorate([ delegateFocus('ctaRef') ], KolTextarea.prototype, "focus", null); __decorate([ delegateClick('ctaRef') ], KolTextarea.prototype, "click", null); //# sourceMappingURL=shadow.js.map