@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
140 lines (138 loc) • 5.41 kB
JavaScript
import { h, Host } from "@stencil/core";
import { inheritAriaAttributes } from "../utils";
/**
* A customizable icon component used to render Modus icons.
*
* <b>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 ModusWcIcon {
constructor() {
this.inheritedAttributes = {};
/** Custom CSS class to apply to the i element. */
this.customClass = '';
/** Indicates that the icon is decorative. When true, sets aria-hidden to hide the icon from screen readers. */
this.decorative = true;
/** The icon size, can be "sm", "md", "lg" (a custom size can be specified in CSS). This adjusts the font size for the icon. */
this.size = 'md';
}
componentWillLoad() {
if (!this.decorative && !this.el.ariaLabel) {
this.el.ariaLabel = `${this.name} icon`;
}
this.inheritedAttributes = inheritAriaAttributes(this.el);
}
getClasses() {
const classList = ['modus-wc-icon modus-icons'];
// The order CSS classes are added matters to CSS specificity
classList.push(`modus-wc-icon--${this.size}`);
if (this.customClass)
classList.push(this.customClass);
return classList.join(' ');
}
render() {
const ariaHidden = this.decorative ? 'true' : null;
const role = this.decorative ? undefined : 'img';
return (h(Host, { key: '81718a9ea5b64625ca3b89ddabe0be8f2f31df73', class: "modus-wc-flex modus-wc-items-center" }, h("i", Object.assign({ key: 'e384b6a3a1bc388cb16e7fea0b34a5e9c6670be7', "aria-hidden": ariaHidden, "aria-label": this.decorative ? null : this.el.ariaLabel, class: this.getClasses(), role: role, tabindex: -1 }, this.inheritedAttributes), this.name)));
}
static get is() { return "modus-wc-icon"; }
static get originalStyleUrls() {
return {
"$": ["modus-wc-icon.scss"]
};
}
static get styleUrls() {
return {
"$": ["modus-wc-icon.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 i element."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"decorative": {
"type": "boolean",
"attribute": "decorative",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Indicates that the icon is decorative. When true, sets aria-hidden to hide the icon from screen readers."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "true"
},
"name": {
"type": "string",
"attribute": "name",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": true,
"optional": false,
"docs": {
"tags": [],
"text": "The icon name, should match the CSS class in the icon font."
},
"getter": false,
"setter": false,
"reflect": false
},
"size": {
"type": "string",
"attribute": "size",
"mutable": false,
"complexType": {
"original": "DaisySize",
"resolved": "\"lg\" | \"md\" | \"sm\" | \"xs\" | undefined",
"references": {
"DaisySize": {
"location": "import",
"path": "../types",
"id": "src/components/types.ts::DaisySize"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The icon size, can be \"sm\", \"md\", \"lg\" (a custom size can be specified in CSS). This adjusts the font size for the icon."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'md'"
}
};
}
static get elementRef() { return "el"; }
}