@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
146 lines (145 loc) • 5.38 kB
JavaScript
import { h, Host } from "@stencil/core";
import { convertPropsToClasses } from "./modus-wc-badge.tailwind";
import { inheritAriaAttributes } from "../utils";
const ALERT_COLORS = ['success', 'warning', 'danger'];
/**
* A customizable badge component used to create badges with different sizes, types, and colors.
*
* The component supports a `<slot>` for injecting content within the badge.
*/
export class ModusWcBadge {
constructor() {
this.inheritedAttributes = {};
/** The color variant of the badge. */
this.color = 'primary';
/** Custom CSS class to apply to the span element. */
this.customClass = '';
/** The size of the badge. */
this.size = 'md';
/** The variant of the badge. */
this.variant = 'filled';
}
componentWillLoad() {
this.inheritedAttributes = inheritAriaAttributes(this.el);
}
getClasses() {
const classList = ['modus-wc-badge'];
const propClasses = convertPropsToClasses({
color: this.color,
size: this.size,
variant: this.variant,
});
// 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() {
const isAlert = ALERT_COLORS.includes(this.color);
return (h(Host, { key: '9ac09e30e95f0fe8d0a6ad0c6be44e58fd6f719b' }, h("span", Object.assign({ key: 'bdf1edadf71d454036aa1e6fadd4b9986a65e0ed', class: this.getClasses(), role: isAlert ? 'alert' : 'status', tabindex: -1 }, this.inheritedAttributes), h("slot", { key: 'e7345a0aa696fc242161991e4f2a976bfd233866' }))));
}
static get is() { return "modus-wc-badge"; }
static get originalStyleUrls() {
return {
"$": ["modus-wc-badge.scss"]
};
}
static get styleUrls() {
return {
"$": ["modus-wc-badge.css"]
};
}
static get properties() {
return {
"color": {
"type": "string",
"attribute": "color",
"mutable": false,
"complexType": {
"original": "| 'primary'\n | 'secondary'\n | 'tertiary'\n | 'high-contrast'\n | 'success'\n | 'warning'\n | 'danger'",
"resolved": "\"danger\" | \"high-contrast\" | \"primary\" | \"secondary\" | \"success\" | \"tertiary\" | \"warning\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "The color variant of the badge."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'primary'"
},
"customClass": {
"type": "string",
"attribute": "custom-class",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Custom CSS class to apply to the span element."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"size": {
"type": "string",
"attribute": "size",
"mutable": false,
"complexType": {
"original": "ModusSize",
"resolved": "\"lg\" | \"md\" | \"sm\"",
"references": {
"ModusSize": {
"location": "import",
"path": "../types",
"id": "src/components/types.ts::ModusSize"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "The size of the badge."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'md'"
},
"variant": {
"type": "string",
"attribute": "variant",
"mutable": false,
"complexType": {
"original": "'counter' | 'filled' | 'text'",
"resolved": "\"counter\" | \"filled\" | \"text\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "The variant of the badge."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'filled'"
}
};
}
static get elementRef() { return "el"; }
}