@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
481 lines (480 loc) • 17.9 kB
JavaScript
import { h, Host, } from "@stencil/core";
import { convertPropsToClasses } from "./modus-wc-textarea.tailwind";
import { inheritAriaAttributes, inheritAttributes } from "../utils";
/**
* A customizable textarea component.
*/
export class ModusWcTextarea {
constructor() {
this.inheritedAttributes = {};
/** Indicates that the input should have a border. */
this.bordered = true;
/** Custom CSS class to apply to the textarea (supports DaisyUI). */
this.customClass = '';
/** The disabled state of the textarea. */
this.disabled = false;
/** The placeholder text for the textarea. */
this.placeholder = '';
/** The readonly state of the textarea. */
this.readonly = false;
/** A value is required for the form to be submittable. */
this.required = false;
/** The size of the input. */
this.size = 'md';
/** The value of the textarea. */
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 || 'Text area';
}
this.inheritedAttributes = Object.assign(Object.assign({}, inheritAriaAttributes(this.el)), inheritAttributes(this.el, ['spellcheck']));
}
getClasses() {
const classList = ['modus-wc-textarea', 'modus-wc-w-full'];
const propClasses = convertPropsToClasses({
bordered: this.bordered,
feedback: this.feedback,
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: '1902761024a938b1382161008dbcd667e64fd935' }, this.label && (h("modus-wc-input-label", { key: 'b784204a89a35f469696fecd782cf5ca84099673', forId: this.inputId, labelText: this.label, required: this.required, size: this.size })), h("textarea", Object.assign({ key: 'befecb3b8408e96dbf70bebcd042b7c03a380675', "aria-placeholder": this.placeholder, "aria-required": this.required, autocorrect: this.autoCorrect, class: this.getClasses(), disabled: this.disabled, enterkeyhint: this.enterkeyhint, id: this.inputId, maxLength: this.maxLength, name: this.name, onBlur: this.handleBlur, onFocus: this.handleFocus, onInput: this.handleInput, placeholder: this.placeholder, readonly: this.readonly, required: this.required, rows: this.rows, tabIndex: this.inputTabIndex, value: this.value }, this.inheritedAttributes)), this.feedback && (h("modus-wc-input-feedback", { key: '5332b13d9782beeff602209a202a066ce88168e4', level: this.feedback.level, message: this.feedback.message, size: this.size }))));
}
static get is() { return "modus-wc-textarea"; }
static get originalStyleUrls() {
return {
"$": ["modus-wc-textarea.scss"]
};
}
static get styleUrls() {
return {
"$": ["modus-wc-textarea.css"]
};
}
static get properties() {
return {
"autoCorrect": {
"type": "string",
"attribute": "auto-correct",
"mutable": false,
"complexType": {
"original": "'on' | 'off'",
"resolved": "\"off\" | \"on\" | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Controls automatic correction in inputted text. Support by browser varies."
},
"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"
},
"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 textarea (supports DaisyUI)."
},
"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": "The disabled state of the textarea."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "false"
},
"enterkeyhint": {
"type": "string",
"attribute": "enterkeyhint",
"mutable": false,
"complexType": {
"original": "| 'enter'\n | 'done'\n | 'go'\n | 'next'\n | 'previous'\n | 'search'\n | 'send'",
"resolved": "\"done\" | \"enter\" | \"go\" | \"next\" | \"previous\" | \"search\" | \"send\" | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "A hint to the browser for which enter key to display."
},
"getter": false,
"setter": false,
"reflect": 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": "The tabindex of the input."
},
"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
},
"maxLength": {
"type": "number",
"attribute": "max-length",
"mutable": false,
"complexType": {
"original": "number",
"resolved": "number | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The maximum number of characters allowed in the textarea."
},
"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": "The placeholder text for the textarea."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"readonly": {
"type": "boolean",
"attribute": "readonly",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The readonly state of the textarea."
},
"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"
},
"rows": {
"type": "number",
"attribute": "rows",
"mutable": false,
"complexType": {
"original": "number",
"resolved": "number | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The number of visible text lines for the textarea."
},
"getter": false,
"setter": false,
"reflect": 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 textarea."
},
"getter": false,
"setter": false,
"reflect": true,
"defaultValue": "''"
}
};
}
static get events() {
return [{
"method": "inputBlur",
"name": "inputBlur",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": "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": "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": "Emitted when the input gains focus."
},
"complexType": {
"original": "FocusEvent",
"resolved": "FocusEvent",
"references": {
"FocusEvent": {
"location": "global",
"id": "global::FocusEvent"
}
}
}
}];
}
static get elementRef() { return "el"; }
}