UNPKG

@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

190 lines (189 loc) 7.16 kB
import { h, Host, } from "@stencil/core"; import { convertPropsToClasses } from "./modus-wc-stepper.tailwind"; import { handleShadowDOMStyles } from "../base-component"; import { inheritAriaAttributes } from "../utils"; /** * Used to show a list of steps in a process. */ export class ModusWcStepper { constructor() { this.inheritedAttributes = {}; /** Custom CSS class to apply to the steps element. */ this.customClass = ''; /** The steps to display. */ this.steps = []; /** If true, steps will be rendered as buttons and emit `stepClick` when activated. */ this.interactive = false; } componentWillLoad() { handleShadowDOMStyles(this.el); this.inheritedAttributes = inheritAriaAttributes(this.el); } getClasses() { const classList = ['modus-wc-steps']; const propClasses = convertPropsToClasses({ interactive: this.interactive, orientation: this.orientation, }); // 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(' '); } getStepLabel(step) { var _a, _b; return (_b = (_a = step.label) !== null && _a !== void 0 ? _a : step.content) !== null && _b !== void 0 ? _b : ''; } getStepAriaLabel(step, index) { const stepLabel = this.getStepLabel(step); return stepLabel || `Step ${index + 1}`; } getClassesForStep(step) { const classList = ['modus-wc-step']; // The order CSS classes are added matters to CSS specificity if (step.color) classList.push(`modus-wc-step-${step.color}`); if (step.customClass) classList.push(step.customClass); return classList.join(' '); } handleStepActivate(index) { if (!this.interactive) { return; } this.stepClick.emit({ index }); } render() { const isInteractive = !!this.interactive; return (h(Host, { key: 'b79de01973e037f929b3690ae60a2ad75a4df821' }, h("ul", Object.assign({ key: '1e306dd6938240556519b70c4060565474a75745', class: this.getClasses() }, this.inheritedAttributes), this.steps.map((step, index) => { const stepLabel = this.getStepLabel(step); return (h("li", { class: this.getClassesForStep(step), key: index, "data-content": step.content }, isInteractive && (h("button", { type: "button", class: "modus-wc-stepper-step-button", "aria-label": this.getStepAriaLabel(step, index), onClick: () => this.handleStepActivate(index) })), stepLabel)); })))); } static get is() { return "modus-wc-stepper"; } static get originalStyleUrls() { return { "$": ["modus-wc-stepper.scss"] }; } static get styleUrls() { return { "$": ["modus-wc-stepper.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 steps element." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "''" }, "orientation": { "type": "string", "attribute": "orientation", "mutable": false, "complexType": { "original": "Orientation", "resolved": "\"horizontal\" | \"vertical\" | undefined", "references": { "Orientation": { "location": "import", "path": "../types", "id": "src/components/types.ts::Orientation" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "The orientation of the steps." }, "getter": false, "setter": false, "reflect": false }, "steps": { "type": "unknown", "attribute": "steps", "mutable": false, "complexType": { "original": "IStepperItem[]", "resolved": "IStepperItem[]", "references": { "IStepperItem": { "location": "local", "path": "/home/runner/work/modus-wc-2.0/modus-wc-2.0/src/components/modus-wc-stepper/modus-wc-stepper.tsx", "id": "src/components/modus-wc-stepper/modus-wc-stepper.tsx::IStepperItem" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "The steps to display." }, "getter": false, "setter": false, "defaultValue": "[]" }, "interactive": { "type": "boolean", "attribute": "interactive", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "If true, steps will be rendered as buttons and emit `stepClick` when activated." }, "getter": false, "setter": false, "reflect": false, "defaultValue": "false" } }; } static get events() { return [{ "method": "stepClick", "name": "stepClick", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "Emitted with the 0-based step index when a step is activated and `interactive` is true." }, "complexType": { "original": "{ index: number }", "resolved": "{ index: number; }", "references": {} } }]; } static get elementRef() { return "el"; } }