@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
184 lines (182 loc) • 7.17 kB
JavaScript
import { h, Host } from "@stencil/core";
import { inheritAriaAttributes } from "../utils";
import { convertPropsToClasses } from "./modus-wc-input-feedback.tailwind";
import { CheckCircleOutlineIcon } from "../../icons/check-circle-outline.icon";
import { InfoOutlineIcon } from "../../icons/info-outline.icon";
import { WarningOutlineIcon } from "../../icons/warning-outline.icon";
/**
* A customizable feedback component used to provide additional context related to form input interactions.
*
* <b>To use a custom icon, this component requires Modus icons to be installed in the host application. See [Modus Icon Usage](/docs/documentation-modus-icon-usage--docs) for steps.</b>
*/
export class ModusWcInputFeedback {
constructor() {
this.inheritedAttributes = {};
/** Custom CSS class to apply to the outer div element. */
this.customClass = '';
/** The Modus icon to use instead of the pre-defined icons. */
this.icon = '';
/** The message. */
this.message = '';
/** The size of the feedback component. */
this.size = 'md';
}
componentWillLoad() {
this.inheritedAttributes = inheritAriaAttributes(this.el);
}
getClasses() {
const classList = ['modus-wc-input-feedback'];
const propClasses = convertPropsToClasses({
level: this.level,
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(' ');
}
getPresetIcon() {
switch (this.level) {
case 'error':
return h(WarningOutlineIcon, { className: "modus-wc-input-feedback-icon" });
case 'info':
return h(InfoOutlineIcon, { className: "modus-wc-input-feedback-icon" });
case 'success':
return (h(CheckCircleOutlineIcon, { className: "modus-wc-input-feedback-icon" }));
case 'warning':
return h(WarningOutlineIcon, { className: "modus-wc-input-feedback-icon" });
}
}
render() {
return (h(Host, { key: 'ded54b9ce471063dc50ed10bb58ddc5567e9d6fa' }, h("div", Object.assign({ key: 'adfa707815c57e662b7875c889a1ecd442017040', class: this.getClasses() }, this.inheritedAttributes), this.icon ? (h("modus-wc-icon", { decorative: true, name: this.icon })) : (this.getPresetIcon()), h("span", { key: '2a0da0ab5ff2fd9f46a26ddfe639b867041b0164' }, this.message))));
}
static get is() { return "modus-wc-input-feedback"; }
static get originalStyleUrls() {
return {
"$": ["modus-wc-input-feedback.scss"]
};
}
static get styleUrls() {
return {
"$": ["modus-wc-input-feedback.css"]
};
}
static get properties() {
return {
"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 outer div element."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"icon": {
"type": "string",
"attribute": "icon",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The Modus icon to use instead of the pre-defined icons."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"level": {
"type": "string",
"attribute": "level",
"mutable": false,
"complexType": {
"original": "IInputFeedbackLevel",
"resolved": "\"error\" | \"info\" | \"success\" | \"warning\"",
"references": {
"IInputFeedbackLevel": {
"location": "local",
"path": "/home/runner/work/modus-wc-2.0/modus-wc-2.0/src/components/modus-wc-input-feedback/modus-wc-input-feedback.tsx",
"id": "src/components/modus-wc-input-feedback/modus-wc-input-feedback.tsx::IInputFeedbackLevel"
}
}
},
"required": true,
"optional": false,
"docs": {
"tags": [],
"text": "The level informs which icon and color that will be rendered."
},
"getter": false,
"setter": false,
"reflect": false
},
"message": {
"type": "string",
"attribute": "message",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The message."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"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 feedback component."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'md'"
}
};
}
static get elementRef() { return "el"; }
}