@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
888 lines (887 loc) • 34.4 kB
JavaScript
/*!
* 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 KolInputContainerFc from "../../functional-component-wrappers/InputContainerStateWrapper/InputContainerStateWrapper";
import KolInputStateWrapperFc from "../../functional-component-wrappers/InputStateWrapper/InputStateWrapper";
import KolSuggestionsFc from "../../functional-components/Suggestions";
import { createRelatedUniqueId, createUniqueId } from "../../utils/dev.utils";
import { createCtaRef, delegateClick, delegateFocus } from "../../utils/element-interaction";
import { propagateSubmitEventToForm } from "../form/controller";
import { InputRangeController } from "./controller";
export class KolInputRange {
async focus() { }
async click() { }
getSanitizedFloatValue(value) {
const floatValue = parseFloat(value);
if (this.state._max && floatValue > this.state._max) {
return this.state._max;
}
if (this.state._min && floatValue < this.state._min) {
return this.state._min;
}
return floatValue;
}
remapValue(value) {
if (this._initialValueType === 'NumberString') {
return String(value);
}
return value;
}
async getValue() {
if (this.ctaRef.el !== undefined) {
const value = this.ctaRef.el.value;
const floatValue = this.getSanitizedFloatValue(value);
return this.remapValue(floatValue);
}
}
componentDidLoad() {
var _a;
if (!this._value && ((_a = this.refInputRange) === null || _a === void 0 ? void 0 : _a.value)) {
this.validateValue(parseFloat(this.refInputRange.value));
}
}
getFormFieldProps() {
return {
state: this.state,
class: clsx('kol-input-range', 'range'),
tooltipAlign: this._tooltipAlign,
alert: this.showAsAlert(),
};
}
getGenericInputProps() {
return Object.assign(Object.assign({ state: Object.assign(Object.assign({}, this.state), { _suggestions: [] }) }, 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;
} });
}
get hasSuggestions() {
return Array.isArray(this.state._suggestions) && this.state._suggestions.length > 0;
}
getInputRangeProps() {
return Object.assign(Object.assign({}, this.getGenericInputProps()), { name: this.state._name ? `${this.state._name}-range` : undefined, list: this.hasSuggestions ? createRelatedUniqueId(this.state._id, 'list') : undefined, type: 'range', tabIndex: -1, id: undefined, 'aria-hidden': 'true', ref: this.setInputRangeRef });
}
getInputNumberProps() {
return Object.assign(Object.assign({}, this.getGenericInputProps()), { name: this.state._name ? `${this.state._name}-number` : undefined, list: this.hasSuggestions ? createRelatedUniqueId(this.state._id, 'list') : undefined, type: 'number', ref: this.setInputNumberRef, onKeyDown: this.onKeyDown });
}
setInitialValueType(value) {
if (this.controller.isNumberString(value)) {
this._initialValueType = 'NumberString';
}
else {
this._initialValueType = 'number';
}
}
render() {
const inputsWrapperStyle = {
'--kolibri-input-range--input-number--width': `calc(${String(this.state._max).length}ch + 2em)`,
};
return (h(KolFormFieldStateWrapperFc, Object.assign({ key: '78e7e5f22820d3d31f77f4fba91bbd676b662465' }, this.getFormFieldProps()), h(KolInputContainerFc, { key: '9d3100e05a452a7fdeae5b9f2f26107095a30e3d', state: this.state }, h("div", { key: '37d9c90170837613b62eb33a83b57645ca67eb1e', class: "kol-input-range__inputs-wrapper", style: inputsWrapperStyle }, h(KolInputStateWrapperFc, Object.assign({ key: 'b1f91e3ab1ee2444af28beda5a4e66a2ee30ac57', class: "kol-input-range__input kol-input-range__input--range" }, this.getInputRangeProps())), h(KolInputStateWrapperFc, Object.assign({ key: '0d7a442b7b54eff7bc9a3ffdbf610ea775d0c34b', class: "kol-input-range__input kol-input-range__input--number" }, this.getInputNumberProps()))), this.hasSuggestions && h(KolSuggestionsFc, { key: '267899744596fcc9654097d47052415923c6e897', id: this.state._id, suggestions: this.state._suggestions }))));
}
constructor() {
this.ctaRef = createCtaRef();
this.setInputNumberRef = (element) => {
if (element) {
this.ctaRef(element);
if (!this._value && element.value) {
this.validateValue(parseFloat(element.value));
}
}
};
this.setInputRangeRef = (element) => {
if (element) {
this.refInputRange = element;
}
};
this.onInput = (event) => {
const value = event.target.value;
const floatValue = this.getSanitizedFloatValue(value);
this.controller.onFacade.onInput(event, true, this.remapValue(floatValue));
};
this.onChange = (event) => {
const value = event.target.value;
const floatValue = this.getSanitizedFloatValue(value);
const remappedValue = this.remapValue(floatValue);
this.validateValue(remappedValue);
this.controller.onFacade.onChange(event, remappedValue);
};
this.onKeyDown = (event) => {
this.controller.onFacade.onKeyDown(event);
if (event.code === 'Enter' || event.code === 'NumpadEnter') {
propagateSubmitEventToForm({
form: this.host,
ref: this.ctaRef.el,
});
}
};
this._autoComplete = 'off';
this._disabled = false;
this._hideMsg = false;
this._hideLabel = false;
this._hint = '';
this._max = 100;
this._min = 0;
this._tooltipAlign = 'top';
this._touched = false;
this.state = {
_hideMsg: false,
_id: createUniqueId('input-range'),
_label: '',
_suggestions: [],
_min: 0,
_max: 100,
};
this._initialValueType = 'number';
this.inputHasFocus = false;
this.controller = new InputRangeController(this, 'range', this.host);
}
showAsAlert() {
return Boolean(this.state._touched) && !this.inputHasFocus;
}
validateAccessKey(value) {
this.controller.validateAccessKey(value);
}
validateAutoComplete(value) {
this.controller.validateAutoComplete(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);
}
validateMax(value) {
this.controller.validateMax(value);
}
validateMin(value) {
this.controller.validateMin(value);
}
validateMsg(value) {
this.controller.validateMsg(value);
}
validateName(value) {
this.controller.validateName(value);
}
validateOn(value) {
this.controller.validateOn(value);
}
validateShortKey(value) {
this.controller.validateShortKey(value);
}
validateStep(value) {
this.controller.validateStep(value);
}
validateSuggestions(value) {
this.controller.validateSuggestions(value);
}
validateSyncValueBySelector(value) {
this.controller.validateSyncValueBySelector(value);
}
validateTouched(value) {
this.controller.validateTouched(value);
}
validateValue(value) {
this.controller.validateValue(value);
if (value !== undefined) {
this.setInitialValueType(value);
}
}
validateVariant(value) {
this.controller.validateVariant(value);
}
componentWillLoad() {
if (this._value !== undefined) {
this.setInitialValueType(this._value);
}
this._touched = this._touched === true;
this.controller.componentWillLoad();
}
static get is() { return "kol-input-range"; }
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"
},
"_autoComplete": {
"type": "string",
"mutable": false,
"complexType": {
"original": "AutoCompletePropType",
"resolved": "string | undefined",
"references": {
"AutoCompletePropType": {
"location": "import",
"path": "../../schema",
"id": "src/schema/index.ts::AutoCompletePropType"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Defines whether the input can be auto-completed."
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "_auto-complete",
"defaultValue": "'off'"
},
"_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"
},
"_max": {
"type": "any",
"mutable": false,
"complexType": {
"original": "number | NumberString",
"resolved": "`${number}.${number}` | `${number}` | number | undefined",
"references": {
"NumberString": {
"location": "import",
"path": "../../schema",
"id": "src/schema/index.ts::NumberString"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Defines the maximum value of the element."
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "_max",
"defaultValue": "100"
},
"_min": {
"type": "any",
"mutable": false,
"complexType": {
"original": "number | NumberString",
"resolved": "`${number}.${number}` | `${number}` | number | undefined",
"references": {
"NumberString": {
"location": "import",
"path": "../../schema",
"id": "src/schema/index.ts::NumberString"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Defines the smallest possible input value."
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "_min",
"defaultValue": "0"
},
"_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
},
"_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"
},
"_step": {
"type": "any",
"mutable": false,
"complexType": {
"original": "number | NumberString",
"resolved": "`${number}.${number}` | `${number}` | number | undefined",
"references": {
"NumberString": {
"location": "import",
"path": "../../schema",
"id": "src/schema/index.ts::NumberString"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Defines the step size for value changes."
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "_step"
},
"_suggestions": {
"type": "string",
"mutable": false,
"complexType": {
"original": "SuggestionsPropType",
"resolved": "W3CInputValue[] | string | undefined",
"references": {
"SuggestionsPropType": {
"location": "import",
"path": "../../schema",
"id": "src/schema/index.ts::SuggestionsPropType"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Suggestions to provide for the input."
},
"getter": false,
"setter": false,
"reflect": false,
"attribute": "_suggestions"
},
"_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": true,
"complexType": {
"original": "number | NumberString",
"resolved": "`${number}.${number}` | `${number}` | number | undefined",
"references": {
"NumberString": {
"location": "import",
"path": "../../schema",
"id": "src/schema/index.ts::NumberString"
}
}
},
"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": {},
"_initialValueType": {},
"inputHasFocus": {}
};
}
static get methods() {
return {
"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": []
}
},
"getValue": {
"complexType": {
"signature": "() => Promise<number | NumberString | undefined>",
"parameters": [],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
},
"NumberString": {
"location": "import",
"path": "../../schema",
"id": "src/schema/index.ts::NumberString"
}
},
"return": "Promise<number | NumberString | undefined>"
},
"docs": {
"text": "Returns the current value.",
"tags": []
}
}
};
}
static get elementRef() { return "host"; }
static get watchers() {
return [{
"propName": "_accessKey",
"methodName": "validateAccessKey"
}, {
"propName": "_autoComplete",
"methodName": "validateAutoComplete"
}, {
"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": "_max",
"methodName": "validateMax"
}, {
"propName": "_min",
"methodName": "validateMin"
}, {
"propName": "_msg",
"methodName": "validateMsg"
}, {
"propName": "_name",
"methodName": "validateName"
}, {
"propName": "_on",
"methodName": "validateOn"
}, {
"propName": "_shortKey",
"methodName": "validateShortKey"
}, {
"propName": "_step",
"methodName": "validateStep"
}, {
"propName": "_suggestions",
"methodName": "validateSuggestions"
}, {
"propName": "_syncValueBySelector",
"methodName": "validateSyncValueBySelector"
}, {
"propName": "_touched",
"methodName": "validateTouched"
}, {
"propName": "_value",
"methodName": "validateValue"
}, {
"propName": "_variant",
"methodName": "validateVariant"
}];
}
}
__decorate([
delegateFocus('ctaRef')
], KolInputRange.prototype, "focus", null);
__decorate([
delegateClick('ctaRef')
], KolInputRange.prototype, "click", null);
//# sourceMappingURL=shadow.js.map