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

428 lines (427 loc) 15.5 kB
import { h, Host, } from "@stencil/core"; import { convertPropsToClasses } from "./modus-wc-date.tailwind"; import { inheritAriaAttributes } from "../utils"; /** * A customizable date picker component used to create date inputs. * * Adheres to WCAG 2.2 standards. */ export class ModusWcDate { constructor() { this.inheritedAttributes = {}; /** Indicates that the input should have a border. */ this.bordered = true; /** Custom CSS class to apply to the input. */ this.customClass = ''; /** Whether the form control is disabled. */ this.disabled = false; /** Whether the value is editable. */ this.readOnly = false; /** A value is required or must be checked for the form to be submittable. */ this.required = false; /** The size of the input. */ this.size = 'md'; /** The value of the control (yyyy-mm-dd). */ 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 = 'Date input'; } this.inheritedAttributes = inheritAriaAttributes(this.el); } getClasses() { const classList = [ 'modus-wc-date-input', 'modus-wc-input', 'modus-wc-w-full', ]; 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); if (this.customClass) classList.push(this.customClass); return classList.join(' '); } render() { return (h(Host, { key: 'd2d6adb865b99bc62336bc13ece19489a23cf130' }, this.label && (h("modus-wc-input-label", { key: '7f71382015e690732e4f6a7f4fa01a580213c063', forId: this.inputId, labelText: this.label, required: this.required, size: this.size })), h("input", Object.assign({ key: 'f34692e111de7eb366149b088ffd6e66f7b9d395', "aria-disabled": this.disabled, class: this.getClasses(), disabled: this.disabled, id: this.inputId, max: this.max, min: this.min, name: this.name, onBlur: this.handleBlur, onFocus: this.handleFocus, onInput: this.handleInput, readonly: this.readOnly, required: this.required, tabIndex: this.inputTabIndex, type: "date", value: this.value }, this.inheritedAttributes)), this.feedback && (h("modus-wc-input-feedback", { key: '998e68c8818472e05e202de0e57d81bbfd4b7509', level: this.feedback.level, message: this.feedback.message, size: this.size })))); } static get is() { return "modus-wc-date"; } static get originalStyleUrls() { return { "$": ["modus-wc-date.scss"] }; } static get styleUrls() { return { "$": ["modus-wc-date.css"] }; } static get properties() { return { "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" }, "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 }, "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": "string", "attribute": "max", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Maximum date value." }, "getter": false, "setter": false, "reflect": false }, "min": { "type": "string", "attribute": "min", "mutable": false, "complexType": { "original": "string", "resolved": "string | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Minimum date 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 }, "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 or must be checked 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'" }, "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 (yyyy-mm-dd)." }, "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"; } }