UNPKG

@scania/tegel

Version:
241 lines (240 loc) 8.93 kB
import { Host, h } from "@stencil/core"; import generateUniqueId from "../../utils/generateUniqueId"; /** * @slot <default> - <b>Unnamed slot.</b> For the step elements. */ export class TdsStepper { constructor() { /** The orientation the Steps */ this.orientation = 'horizontal'; /** Text position, only available on a direction: horizontal */ this.labelPosition = 'below'; /** Size of the component and it's children. */ this.size = 'lg'; /** Hides the label for the child components if true. */ this.hideLabels = false; /** ID used for internal Stepper functionality and events, must be unique. * * **NOTE**: If you're listening for Stepper events, you need to set this ID yourself to identify the Stepper, * as the default ID is random and will be different every time. */ this.stepperId = generateUniqueId(); /** Label for the stepper component, for screen reader users */ this.tdsAriaLabel = 'Progress steps'; } componentWillLoad() { if (this.orientation === 'vertical') { this.labelPosition = 'aside'; } } handleDirectionChange() { this.internalTdsPropsChange.emit({ stepperId: this.stepperId, changed: ['orientation'], orientation: this.orientation, }); } handleLabelPositionChange() { this.internalTdsPropsChange.emit({ stepperId: this.stepperId, changed: ['labelPosition'], labelPosition: this.labelPosition, }); } handleSizeChange() { this.internalTdsPropsChange.emit({ stepperId: this.stepperId, changed: ['size'], size: this.size, }); } handleHideLabelsChange() { this.internalTdsPropsChange.emit({ stepperId: this.stepperId, changed: ['hideLabels'], hideLabels: this.hideLabels, }); } render() { return (h(Host, { key: 'a62077cf8b1936e7109eea64cad0ceb67a45c676' }, h("div", { key: 'f958fcd53b074ac8ac72d055162e738116e94956', role: "list", "aria-label": this.tdsAriaLabel, class: `${this.orientation} text-position-${this.labelPosition} ${this.size}` }, h("slot", { key: 'e9dfa6c14ec134baafe5a58394337b09ca091809' })))); } static get is() { return "tds-stepper"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["stepper.scss"] }; } static get styleUrls() { return { "$": ["stepper.css"] }; } static get properties() { return { "orientation": { "type": "string", "mutable": false, "complexType": { "original": "'horizontal' | 'vertical'", "resolved": "\"horizontal\" | \"vertical\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "The orientation the Steps" }, "getter": false, "setter": false, "reflect": false, "attribute": "orientation", "defaultValue": "'horizontal'" }, "labelPosition": { "type": "string", "mutable": false, "complexType": { "original": "'aside' | 'below'", "resolved": "\"aside\" | \"below\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Text position, only available on a direction: horizontal" }, "getter": false, "setter": false, "reflect": false, "attribute": "label-position", "defaultValue": "'below'" }, "size": { "type": "string", "mutable": false, "complexType": { "original": "'sm' | 'lg'", "resolved": "\"lg\" | \"sm\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Size of the component and it's children." }, "getter": false, "setter": false, "reflect": false, "attribute": "size", "defaultValue": "'lg'" }, "hideLabels": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Hides the label for the child components if true." }, "getter": false, "setter": false, "reflect": false, "attribute": "hide-labels", "defaultValue": "false" }, "stepperId": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "ID used for internal Stepper functionality and events, must be unique.\n\n**NOTE**: If you're listening for Stepper events, you need to set this ID yourself to identify the Stepper,\nas the default ID is random and will be different every time." }, "getter": false, "setter": false, "reflect": false, "attribute": "stepper-id", "defaultValue": "generateUniqueId()" }, "tdsAriaLabel": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Label for the stepper component, for screen reader users" }, "getter": false, "setter": false, "reflect": false, "attribute": "tds-aria-label", "defaultValue": "'Progress steps'" } }; } static get events() { return [{ "method": "internalTdsPropsChange", "name": "internalTdsPropsChange", "bubbles": true, "cancelable": false, "composed": true, "docs": { "tags": [{ "name": "internal", "text": "Broadcasts changes in props to the Stepper children" }], "text": "" }, "complexType": { "original": "InternalTdsStepperPropChange", "resolved": "{ stepperId: string; changed: (keyof TdsStepperProps)[]; } & Partial<TdsStepperProps>", "references": { "InternalTdsStepperPropChange": { "location": "local", "path": "/home/runner/work/tegel/tegel/packages/core/src/components/stepper/stepper.tsx", "id": "src/components/stepper/stepper.tsx::InternalTdsStepperPropChange" } } } }]; } static get elementRef() { return "host"; } static get watchers() { return [{ "propName": "orientation", "methodName": "handleDirectionChange" }, { "propName": "labelPosition", "methodName": "handleLabelPositionChange" }, { "propName": "size", "methodName": "handleSizeChange" }, { "propName": "hideLabels", "methodName": "handleHideLabelsChange" }]; } }