@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
175 lines (173 loc) • 6.67 kB
JavaScript
import { h, Host } from "@stencil/core";
import { handleShadowDOMStyles } from "../base-component";
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() {
// Auto-inject CSS if component is used inside user's shadow DOM
handleShadowDOMStyles(this.el);
if (!this.decorative && !this.el.ariaLabel) {
this.el.ariaLabel = `${this.name} icon`;
}
this.inheritedAttributes = inheritAriaAttributes(this.el);
}
getClasses() {
let classList = [];
// Add base class
classList.push('modus-wc-icon');
// Add icon font class based on variant
if (this.variant === 'outlined') {
classList.push('modus-icons-outlined');
}
else if (this.variant === 'solid') {
classList.push('modus-icons-solid');
}
else {
classList.push('modus-icons');
}
// Add size class - this is common for all variants
classList.push(`modus-wc-icon--${this.size}`);
// Add custom class if provided
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: 'fe663bd3846135d1dda08eca273d9df19bde8c0a', class: "modus-wc-flex modus-wc-items-center" }, h("i", Object.assign({ key: 'd8bedd1e99b4dbe86184635d8bb231f5069ece11', "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'"
},
"variant": {
"type": "string",
"attribute": "variant",
"mutable": false,
"complexType": {
"original": "'outlined' | 'solid'",
"resolved": "\"outlined\" | \"solid\" | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The icon variant, can be \"outlined\" or \"solid\"."
},
"getter": false,
"setter": false,
"reflect": false
}
};
}
static get elementRef() { return "el"; }
}