UNPKG

@public-ui/components

Version:

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

841 lines (840 loc) 32.4 kB
/*! * KoliBri - The accessible HTML-Standard */ import { __decorate } from "tslib"; import { h } from "@stencil/core"; import clsx from "../../utils/clsx"; import { createUniqueId } from "../../utils/dev.utils"; import { createCtaRef, delegateClick, delegateFocus } from "../../utils/element-interaction"; import { InputCheckboxController } from "./controller"; import KolCheckboxStateWrapperFc from "../../functional-component-wrappers/CheckboxStateWrapper/CheckboxStateWrapper"; import KolFieldControlStateWrapperFc from "../../functional-component-wrappers/FieldControlStateWrapper/FieldControlStateWrapper"; import KolFormFieldStateWrapperFc from "../../functional-component-wrappers/FormFieldStateWrapper/FormFieldStateWrapper"; import { propagateSubmitEventToForm } from "../form/controller"; export class KolInputCheckbox { getModelValue() { return this._checked ? this.state._value : null; } async getValue() { return this.getModelValue(); } async focus() { } async click() { } getFormFieldProps() { return { state: this.state, class: clsx('kol-input-checkbox', { [`kol-input-checkbox--checked`]: this.state._checked, [`kol-input-checkbox--indeterminate`]: this.state._indeterminate, [`kol-input-checkbox--variant-${this.state._variant || 'default'}`]: true, [`kol-input-checkbox--label-align-${this.state._labelAlign || 'right'}`]: true, }), tooltipAlign: this._tooltipAlign, alert: this.showAsAlert(), renderNoTooltip: true, }; } getFieldControlProps() { return { class: clsx('kol-input-checkbox__field-control', { [`kol-input-checkbox__field-control--checked`]: this.state._checked, [`kol-input-checkbox__field-control--indeterminate`]: this.state._indeterminate, [`kol-input-checkbox__field-control--variant-${this.state._variant || 'default'}`]: true, }), state: this.state, fieldControlLabelProps: { onMouseDown: (e) => { if (this.inputHasFocus) { e.preventDefault(); } }, }, }; } getInputProps() { return { state: this.state, icon: this.getIcon(), onMouseDown: (e) => { if (this.inputHasFocus && !(e.target instanceof HTMLInputElement)) { e.preventDefault(); } }, inputProps: Object.assign(Object.assign({ class: clsx({ 'visually-hidden': this.state._variant === 'button', }), ref: this.ctaRef }, this.controller.onFacade), { onInput: this.onInput, onChange: this.onChange, onKeyDown: this.onKeyDown, onFocus: (event) => { this.controller.onFacade.onFocus(event); this.inputHasFocus = true; }, onBlur: (event) => { if (this._disabled) { return; } this.controller.onFacade.onBlur(event); this.inputHasFocus = false; }, onClick: undefined }), }; } getIcon() { if (this.state._indeterminate) return this.state._icons.indeterminate; if (this.state._checked) return this.state._icons.checked; return this.state._icons.unchecked; } render() { return (h(KolFormFieldStateWrapperFc, Object.assign({ key: 'e19d056690c7e9f4fd0281fbc3d61fcf2936d23b' }, this.getFormFieldProps(), { renderNoLabel: true }), h(KolFieldControlStateWrapperFc, Object.assign({ key: 'aa9db978e7584e102fe07c741e47a2f032754e22' }, this.getFieldControlProps(), { renderNoHint: true }), h(KolCheckboxStateWrapperFc, Object.assign({ key: '8b1fc962d3d3e1ced0ddc9ae56c7cfce1804996f' }, this.getInputProps()))))); } constructor() { this.ctaRef = createCtaRef(); this._checked = false; this._hideMsg = false; this._disabled = false; this._hideLabel = false; this._hint = ''; this._labelAlign = 'right'; this._required = false; this._tooltipAlign = 'top'; this._touched = false; this._value = true; this._variant = 'default'; this.state = { _checked: false, _hideMsg: false, _icons: { checked: 'kolicon-check', indeterminate: 'kolicon-minus', unchecked: 'kolicon-cross', }, _id: createUniqueId('input-checkbox'), _indeterminate: false, _label: '', _value: true, _variant: 'default', _labelAlign: 'right', }; this.inputHasFocus = false; this.onInput = (event) => { this._checked = !this._checked; this._indeterminate = false; const value = this.getModelValue(); this.controller.onFacade.onInput(event, false, value); this.controller.setFormAssociatedCheckboxValue(value); }; this.onChange = (event) => { this.controller.onFacade.onChange(event, this.getModelValue()); }; this.onKeyDown = (event) => { this.controller.onFacade.onKeyDown(event); if (event.code === 'Enter' || event.code === 'NumpadEnter') { propagateSubmitEventToForm({ form: this.host, ref: this.ctaRef.el, }); } }; this.controller = new InputCheckboxController(this, 'checkbox', this.host); } showAsAlert() { return Boolean(this.state._touched) && !this.inputHasFocus; } validateAccessKey(value) { this.controller.validateAccessKey(value); } validateChecked(value) { this.controller.validateChecked(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); } validateIndeterminate(value) { this.controller.validateIndeterminate(value); } validateLabel(value) { this.controller.validateLabel(value); } validateLabelAlign(value) { this.controller.validateLabelAlign(value); } validateMsg(value) { this.controller.validateMsg(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); } validateSyncValueBySelector(value) { this.controller.validateSyncValueBySelector(value); } validateTouched(value) { this.controller.validateTouched(value); } validateValue(value) { this.controller.validateValue(value); } validateVariant(value) { this.controller.validateVariant(value); } componentWillLoad() { this._touched = this._touched === true; this.controller.componentWillLoad(); } static get is() { return "kol-input-checkbox"; } 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" }, "_checked": { "type": "boolean", "mutable": true, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "TODO", "text": ": Change type back to `CheckedPropType` after Stencil#4663 has been resolved." }], "text": "Defines whether the checkbox is checked or not. Can be read and written." }, "getter": false, "setter": false, "reflect": true, "attribute": "_checked", "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" }, "_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" }, "_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": "Stringified<InputCheckboxIconsProp>", "resolved": "string | undefined | { checked: string; indeterminate?: string | undefined; unchecked?: string | undefined; } | { checked?: string | undefined; indeterminate: string; unchecked?: string | undefined; } | { checked?: string | undefined; indeterminate?: string | undefined; unchecked: string; }", "references": { "Stringified": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::Stringified" }, "InputCheckboxIconsProp": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::InputCheckboxIconsProp" } } }, "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" }, "_indeterminate": { "type": "boolean", "mutable": true, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "TODO", "text": ": Change type back to `IndeterminatePropType` after Stencil#4663 has been resolved." }], "text": "Puts the checkbox in the indeterminate state, does not change the value of _checked." }, "getter": false, "setter": false, "reflect": true, "attribute": "_indeterminate" }, "_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" }, "_labelAlign": { "type": "string", "mutable": false, "complexType": { "original": "LabelAlignPropType", "resolved": "\"left\" | \"right\" | undefined", "references": { "LabelAlignPropType": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::LabelAlignPropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines which alignment should be used for presentation." }, "getter": false, "setter": false, "reflect": false, "attribute": "_label-align", "defaultValue": "'right'" }, "_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 }, "_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" }, "_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": "any", "mutable": false, "complexType": { "original": "StencilUnknown", "resolved": "boolean | null | number | object | string | undefined", "references": { "StencilUnknown": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::StencilUnknown" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Defines the value of the element." }, "getter": false, "setter": false, "reflect": false, "attribute": "_value", "defaultValue": "true" }, "_variant": { "type": "string", "mutable": false, "complexType": { "original": "InputCheckboxVariantPropType", "resolved": "\"button\" | \"default\" | \"switch\" | undefined", "references": { "InputCheckboxVariantPropType": { "location": "import", "path": "../../schema/props/variant-input-checkbox", "id": "src/schema/props/variant-input-checkbox.ts::InputCheckboxVariantPropType" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Defines which variant should be used for presentation." }, "getter": false, "setter": false, "reflect": false, "attribute": "_variant", "defaultValue": "'default'" } }; } static get states() { return { "state": {}, "inputHasFocus": {} }; } static get methods() { return { "getValue": { "complexType": { "signature": "() => Promise<StencilUnknown>", "parameters": [], "references": { "Promise": { "location": "global", "id": "global::Promise" }, "StencilUnknown": { "location": "import", "path": "../../schema", "id": "src/schema/index.ts::StencilUnknown" } }, "return": "Promise<StencilUnknown>" }, "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": "_checked", "methodName": "validateChecked" }, { "propName": "_disabled", "methodName": "validateDisabled" }, { "propName": "_hideMsg", "methodName": "validateHideMsg" }, { "propName": "_hideLabel", "methodName": "validateHideLabel" }, { "propName": "_hint", "methodName": "validateHint" }, { "propName": "_icons", "methodName": "validateIcons" }, { "propName": "_indeterminate", "methodName": "validateIndeterminate" }, { "propName": "_label", "methodName": "validateLabel" }, { "propName": "_labelAlign", "methodName": "validateLabelAlign" }, { "propName": "_msg", "methodName": "validateMsg" }, { "propName": "_name", "methodName": "validateName" }, { "propName": "_on", "methodName": "validateOn" }, { "propName": "_required", "methodName": "validateRequired" }, { "propName": "_shortKey", "methodName": "validateShortKey" }, { "propName": "_syncValueBySelector", "methodName": "validateSyncValueBySelector" }, { "propName": "_touched", "methodName": "validateTouched" }, { "propName": "_value", "methodName": "validateValue" }, { "propName": "_variant", "methodName": "validateVariant" }]; } } __decorate([ delegateFocus('ctaRef') ], KolInputCheckbox.prototype, "focus", null); __decorate([ delegateClick('ctaRef') ], KolInputCheckbox.prototype, "click", null); //# sourceMappingURL=shadow.js.map