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

111 lines (105 loc) 7.63 kB
import { p as proxyCustomElement, H, e as createEvent, h, c as Host } from './p-BMvVSi6Y.js'; import { D as DAISY_TO_MODUS_LABEL_SIZE } from './p-DZXd_sgn.js'; import { i as inheritAriaAttributes } from './p-COxr4v9W.js'; import { d as defineCustomElement$2 } from './p-CXnOhVIy.js'; const convertPropsToClasses = (props) => { let classes = ''; if (Object.prototype.hasOwnProperty.call(props, 'size') && props.size) { classes = `${classes} modus-wc-toggle-${props.size}`; } return classes; }; const modusWcSwitchCss = "modus-wc-switch.modus-wc-switch-host{--rounded-badge:32px;align-items:center;display:flex}modus-wc-switch.modus-wc-switch-host .modus-wc-input-label{font-weight:var(--modus-wc-font-weight-normal);padding-inline-start:var(--modus-wc-spacing-md)}[data-theme=modus-classic-light] modus-wc-switch .modus-wc-toggle,[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle{background-color:var(--modus-wc-color-white);border:none;color:var(--modus-wc-color-gray-4);outline-color:var(--modus-wc-color-highlight-blue);--fallback-b1:var(--modus-wc-color-gray-4)}[data-theme=modus-classic-light] modus-wc-switch .modus-wc-toggle.modus-wc-toggle-sm,[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle.modus-wc-toggle-sm{--handleoffset:1rem;height:1rem;width:2rem}[data-theme=modus-classic-light] modus-wc-switch .modus-wc-toggle.modus-wc-toggle-md,[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle.modus-wc-toggle-md{--handleoffset:1.25rem;height:1.25rem;width:2.5rem}[data-theme=modus-classic-light] modus-wc-switch .modus-wc-toggle.modus-wc-toggle-lg,[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle.modus-wc-toggle-lg{--handleoffset:1.5rem;height:1.5rem;width:3rem}[data-theme=modus-classic-light] modus-wc-switch .modus-wc-toggle:checked,[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle:checked{--fallback-b1:var(--modus-wc-color-blue-light);color:var(--modus-wc-color-blue-light)}[data-theme=modus-classic-light] modus-wc-switch .modus-wc-toggle:not(:disabled):hover:not(:checked),[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle:not(:disabled):hover:not(:checked){background-color:var(--modus-wc-color-white);outline:2px solid var(--modus-wc-color-blue-light);outline-offset:-2px}[data-theme=modus-classic-light] modus-wc-switch .modus-wc-toggle:not(:disabled):hover:checked,[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle:not(:disabled):hover:checked{background-color:var(--modus-wc-color-white);--fallback-b1:var(--modus-wc-color-trimble-blue)}[data-theme=modus-classic-light] modus-wc-switch .modus-wc-toggle:not(:disabled):focus-visible,[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle:not(:disabled):focus-visible{outline:2px solid var(--modus-wc-color-highlight-blue);outline-offset:2px}[data-theme=modus-classic-light] modus-wc-switch .modus-wc-toggle:disabled,[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle:disabled{background-color:var(--modus-wc-color-white)}[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle:checked{--fallback-b1:var(--modus-wc-color-highlight-blue);color:var(--modus-wc-color-highlight-blue)}[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle:not(:disabled):hover:not(:checked){background-color:var(--modus-wc-color-white);outline:2px solid var(--modus-wc-color-highlight-blue);outline-offset:-2px}[data-theme=modus-classic-dark] modus-wc-switch .modus-wc-toggle:not(:disabled):hover:checked{background-color:var(--modus-wc-color-white);--fallback-b1:var(--modus-wc-color-blue-light)}"; const ModusWcSwitch$1 = /*@__PURE__*/ proxyCustomElement(class ModusWcSwitch extends H { constructor() { super(); this.__registerHost(); this.inputBlur = createEvent(this, "inputBlur"); this.inputChange = createEvent(this, "inputChange"); this.inputFocus = createEvent(this, "inputFocus"); this.inheritedAttributes = {}; /** Custom CSS class to apply to the inner div. */ this.customClass = ''; /** The disabled state of the switch. */ this.disabled = false; /** The indeterminate state of the switch. */ this.indeterminate = false; /** Name of the form control. Submitted with the form as part of a name/value pair. */ this.name = ''; /** A value is required for the form to be submittable. */ this.required = false; /** The size of the input. */ this.size = 'md'; /** The value of the switch. */ this.value = false; this.handleBlur = (event) => { this.inputBlur.emit(event); }; this.handleFocus = (event) => { this.inputFocus.emit(event); }; this.handleInput = (event) => { this.inputChange.emit(event); }; } componentDidRender() { const checkbox = this.el.querySelector('input[type="checkbox"]'); if (checkbox) { checkbox.indeterminate = this.indeterminate; } } componentWillLoad() { if (!this.el.ariaLabel) { this.el.ariaLabel = 'Switch button'; } this.inheritedAttributes = inheritAriaAttributes(this.el); } getClasses() { const classList = ['modus-wc-toggle']; const propClasses = convertPropsToClasses({ size: this.size }); // 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 labelSize = this.size && DAISY_TO_MODUS_LABEL_SIZE[this.size]; return (h(Host, { key: 'c826ad7fe778389cf1c487167d936bba9928eacf', class: "modus-wc-switch-host" }, h("input", Object.assign({ key: 'ba143399fa714328b9ecb17003492d4885d843b4', "aria-checked": this.indeterminate ? 'mixed' : this.value, "aria-disabled": this.disabled, checked: this.value, class: this.getClasses(), disabled: this.disabled, id: this.inputId, onBlur: this.handleBlur, onFocus: this.handleFocus, onInput: this.handleInput, required: this.required, tabIndex: this.inputTabIndex, type: "checkbox" }, this.inheritedAttributes)), this.label && (h("modus-wc-input-label", { key: 'dd39b4a72e723f57a6149942519772ac39e98f0a', forId: this.inputId, labelText: this.label, required: this.required, size: labelSize })))); } get el() { return this; } static get style() { return modusWcSwitchCss; } }, [0, "modus-wc-switch", { "customClass": [1, "custom-class"], "disabled": [4], "indeterminate": [1540], "inputId": [1, "input-id"], "inputTabIndex": [2, "input-tab-index"], "label": [1], "name": [1], "required": [4], "size": [1], "value": [1540] }]); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["modus-wc-switch", "modus-wc-input-label"]; components.forEach(tagName => { switch (tagName) { case "modus-wc-switch": if (!customElements.get(tagName)) { customElements.define(tagName, ModusWcSwitch$1); } break; case "modus-wc-input-label": if (!customElements.get(tagName)) { defineCustomElement$2(); } break; } }); } const ModusWcSwitch = ModusWcSwitch$1; const defineCustomElement = defineCustomElement$1; export { ModusWcSwitch, defineCustomElement };