UNPKG

@trimble-oss/moduswebcomponents

Version:

Modus Web Components is a modern, accessible UI library built with Stencil JS that provides reusable web components following Trimble's Modus design system. This updated version focuses on improved flexibility, enhanced theming options, comprehensive cust

577 lines (576 loc) 21.3 kB
import { h, Host, } from "@stencil/core"; import { convertPropsToClasses } from "./modus-wc-number-input.tailwind"; import { inheritAriaAttributes } from "../utils"; /** * A customizable input component used to create number inputs with types */ export class ModusWcNumberInput { constructor() { this.inheritedAttributes = {}; /** Indicates that the input should have a border. */ this.bordered = true; /** The currency symbol to display. */ this.currencySymbol = ''; /** Custom CSS class to apply to the input. */ this.customClass = ''; /** Whether the form control is disabled. */ this.disabled = false; /** * Hints at the type of data that might be entered by the user while editing the element or its contents. * This allows a browser to display an appropriate virtual keyboard. */ this.inputMode = 'numeric'; /** Text that appears in the form control when it has no value set. */ this.placeholder = ''; /** Whether the value is editable. */ this.readOnly = false; /** A value is required for the form to be submittable. */ this.required = false; /** The size of the input. */ this.size = 'md'; /** Type of form control. */ this.type = 'number'; /** The value of the control. */ this.value = ''; this.handleBlur = (event) => { this.inputBlur.emit(event); }; this.handleFocus = (event) => { this.inputFocus.emit(event); }; this.handleInput = (event) => { this.inputChange.emit(event); }; } componentWillLoad() { if (!this.el.ariaLabel) { this.el.ariaLabel = this.placeholder || 'Number input'; } this.inheritedAttributes = inheritAriaAttributes(this.el); } getSharedClasses(styleList) { const classList = [...styleList]; const propClasses = convertPropsToClasses({ bordered: this.bordered, feedback: this.feedback, readOnly: this.readOnly, size: this.size, }); // The order CSS classes are added matters to CSS specificity if (propClasses) classList.push(propClasses); return classList.join(' '); } getInputClasses() { const classList = [ 'modus-wc-number-input', 'modus-wc-input', 'modus-wc-w-full', ]; if (this.currencySymbol) { classList.push('modus-wc-join-item'); } return this.getSharedClasses(classList); } getCurrencyClasses() { const classList = [ 'modus-wc-input-currency', 'modus-wc-join-item', 'modus-wc-flex', 'modus-wc-items-center', ]; return this.getSharedClasses(classList); } getWrapperClasses() { const classList = ['modus-wc-number-input-container']; if (this.currencySymbol) { classList.push('modus-wc-join'); classList.push('modus-wc-flex'); } return classList.join(' '); } render() { return (h(Host, { key: '0688c302a1d6e2ef33cdaaa4dd505b32c2f936de', class: this.customClass }, this.label && (h("modus-wc-input-label", { key: '586f51f3ef69afae292771dd8412b35bd2b42632', forId: this.inputId, labelText: this.label, required: this.required, size: this.size })), h("div", { key: '0b531ccbd6bbd10017dbb343acb78ecded5e7d90', class: this.getWrapperClasses() }, this.currencySymbol && (h("div", { key: 'f8a5899027f25b0d6f5a963a1813fabe3d8985bd', class: this.getCurrencyClasses() }, this.currencySymbol)), h("input", Object.assign({ key: '120373fb433d051a5f5623cea2db8f1f99ee380f', "aria-placeholder": this.placeholder, "aria-required": this.required, autocomplete: this.autoComplete, class: this.getInputClasses(), disabled: this.disabled, id: this.inputId, inputmode: this.inputMode, max: this.max, min: this.min, name: this.name, onBlur: this.handleBlur, onFocus: this.handleFocus, onInput: this.handleInput, placeholder: this.placeholder, readonly: this.readOnly, required: this.required, step: this.step, tabIndex: this.inputTabIndex, type: this.type, value: this.value }, this.inheritedAttributes))), this.feedback && (h("modus-wc-input-feedback", { key: '475e95b5c72d1d130982bc0e5017615ae05ddf0d', level: this.feedback.level, message: this.feedback.message, size: this.size })))); } static get is() { return "modus-wc-number-input"; } static get originalStyleUrls() { return { "$": ["modus-wc-number-input.scss"] }; } static get styleUrls() { return { "$": ["modus-wc-number-input.css"] }; } static get properties() { return { "autoComplete": { "type": "string", "attribute": "auto-complete", "mutable": false, "complexType": { "original": "'on' | 'off'", "resolved": "\"off\" | \"on\" | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Hint for form autofill feature." }, "getter": false, "setter": false, "reflect": false }, "bordered": { "type": "boolean", "attribute": "bordered", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Indicates that the input should have a border." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "true" }, "currencySymbol": { "type": "string", "attribute": "currency-symbol", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The currency symbol to display." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "''" }, "customClass": { "type": "string", "attribute": "custom-class", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Custom CSS class to apply to the input." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "''" }, "disabled": { "type": "boolean", "attribute": "disabled", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Whether the form control is disabled." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "false" }, "feedback": { "type": "unknown", "attribute": "feedback", "mutable": false, "complexType": { "original": "IInputFeedbackProp", "resolved": "IInputFeedbackProp | undefined", "references": { "IInputFeedbackProp": { "location": "import", "path": "../types", "id": "src/components/types.ts::IInputFeedbackProp" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Feedback to render below the input." }, "getter": false, "setter": false }, "inputId": { "type": "string", "attribute": "input-id", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The ID of the input element." }, "getter": false, "setter": false, "reflect": false }, "inputMode": { "type": "string", "attribute": "input-mode", "mutable": false, "complexType": { "original": "'decimal' | 'none' | 'numeric'", "resolved": "\"decimal\" | \"none\" | \"numeric\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Hints at the type of data that might be entered by the user while editing the element or its contents.\nThis allows a browser to display an appropriate virtual keyboard." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "'numeric'" }, "inputTabIndex": { "type": "number", "attribute": "input-tab-index", "mutable": false, "complexType": { "original": "number", "resolved": "number | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Determine the control's relative ordering for sequential focus navigation (typically with the Tab key)." }, "getter": false, "setter": false, "reflect": false }, "label": { "type": "string", "attribute": "label", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The text to display within the label." }, "getter": false, "setter": false, "reflect": false }, "max": { "type": "number", "attribute": "max", "mutable": false, "complexType": { "original": "number", "resolved": "number | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The input's maximum value." }, "getter": false, "setter": false, "reflect": false }, "min": { "type": "number", "attribute": "min", "mutable": false, "complexType": { "original": "number", "resolved": "number | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The input's minimum value." }, "getter": false, "setter": false, "reflect": false }, "name": { "type": "string", "attribute": "name", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Name of the form control. Submitted with the form as part of a name/value pair." }, "getter": false, "setter": false, "reflect": false }, "placeholder": { "type": "string", "attribute": "placeholder", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Text that appears in the form control when it has no value set." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "''" }, "readOnly": { "type": "boolean", "attribute": "read-only", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Whether the value is editable." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "false" }, "required": { "type": "boolean", "attribute": "required", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "A value is required for the form to be submittable." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "false" }, "size": { "type": "string", "attribute": "size", "mutable": false, "complexType": { "original": "ModusSize", "resolved": "\"lg\" | \"md\" | \"sm\" | undefined", "references": { "ModusSize": { "location": "import", "path": "../types", "id": "src/components/types.ts::ModusSize" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "The size of the input." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "'md'" }, "step": { "type": "number", "attribute": "step", "mutable": false, "complexType": { "original": "number", "resolved": "number | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The granularity that the value adheres to." }, "getter": false, "setter": false, "reflect": false }, "type": { "type": "string", "attribute": "type", "mutable": false, "complexType": { "original": "'number' | 'range'", "resolved": "\"number\" | \"range\" | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Type of form control." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "'number'" }, "value": { "type": "string", "attribute": "value", "mutable": true, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "The value of the control." }, "getter": false, "setter": false, "reflect": true, "defaultValue": "''" } }; } static get events() { return [{ "method": "inputBlur", "name": "inputBlur", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "Event emitted when the input loses focus." }, "complexType": { "original": "FocusEvent", "resolved": "FocusEvent", "references": { "FocusEvent": { "location": "global", "id": "global::FocusEvent" } } } }, { "method": "inputChange", "name": "inputChange", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "Event emitted when the input value changes." }, "complexType": { "original": "InputEvent", "resolved": "InputEvent", "references": { "InputEvent": { "location": "global", "id": "global::InputEvent" } } } }, { "method": "inputFocus", "name": "inputFocus", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "Event emitted when the input gains focus." }, "complexType": { "original": "FocusEvent", "resolved": "FocusEvent", "references": { "FocusEvent": { "location": "global", "id": "global::FocusEvent" } } } }]; } static get elementRef() { return "el"; } }