@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
124 lines (119 loc) • 7.34 kB
JavaScript
import { p as proxyCustomElement, H, e as createEvent, h, c as Host } from './p-BMvVSi6Y.js';
import { i as inheritAriaAttributes } from './p-COxr4v9W.js';
import { d as defineCustomElement$3 } from './p-C8YB6DYg.js';
import { d as defineCustomElement$2 } from './p-DWQdP1KV.js';
import { d as defineCustomElement$1 } from './p-CXnOhVIy.js';
const convertPropsToClasses = ({ bordered, feedback, size, }) => {
let classes = '';
if (bordered) {
classes = `${classes} modus-wc-select-bordered`;
}
if (feedback) {
classes = `${classes} modus-wc-input--${feedback.level}`;
}
if (size) {
classes = `${classes} modus-wc-select-${size}`;
}
return classes.trim();
};
const modusWcSelectCss = ".modus-wc-input--error{border-color:var(--modus-wc-color-error) !important}.modus-wc-input--info{border-color:var(--modus-wc-color-info) !important}.modus-wc-input--success{border-color:var(--modus-wc-color-success) !important}.modus-wc-input--warning{border-color:var(--modus-wc-color-warning) !important}modus-wc-select .modus-wc-input-label{padding-bottom:var(--modus-wc-spacing-sm)}[data-theme=modus-classic-light] modus-wc-select .modus-wc-select,[data-theme=modus-classic-dark] modus-wc-select .modus-wc-select{border-radius:var(--modus-wc-border-radius-md)}[data-theme=modus-classic-light] modus-wc-select .modus-wc-select.modus-wc-select-sm,[data-theme=modus-classic-dark] modus-wc-select .modus-wc-select.modus-wc-select-sm{font-size:var(--modus-wc-font-size-sm);height:var(--modus-wc-input-height-sm);line-height:var(--modus-wc-input-height-sm);min-height:var(--modus-wc-input-height-sm)}[data-theme=modus-classic-light] modus-wc-select .modus-wc-select.modus-wc-select-md,[data-theme=modus-classic-dark] modus-wc-select .modus-wc-select.modus-wc-select-md{font-size:var(--modus-wc-font-size-md);height:var(--modus-wc-input-height-md);line-height:var(--modus-wc-input-height-md);min-height:var(--modus-wc-input-height-md)}[data-theme=modus-classic-light] modus-wc-select .modus-wc-select.modus-wc-select-lg,[data-theme=modus-classic-dark] modus-wc-select .modus-wc-select.modus-wc-select-lg{font-size:var(--modus-wc-font-size-lg);height:var(--modus-wc-input-height-lg);line-height:var(--modus-wc-font-size-lg);min-height:var(--modus-wc-font-size-lg)}[data-theme=modus-classic-light] modus-wc-select .modus-wc-select:focus,[data-theme=modus-classic-dark] modus-wc-select .modus-wc-select:focus{border-color:var(--modus-wc-color-blue-light);border-width:var(--modus-wc-border-width-sm);box-shadow:none;outline:none}[data-theme=modus-classic-light] modus-wc-select .modus-wc-select.modus-wc-select-bordered:not(:disabled):not(:focus){border-color:var(--modus-wc-color-gray-6)}[data-theme=modus-classic-dark] modus-wc-select .modus-wc-select:focus{border-color:var(--modus-wc-color-highlight-blue)}[data-theme=modus-classic-dark] modus-wc-select .modus-wc-select,[data-theme=modus-modern-dark] modus-wc-select .modus-wc-select{background-color:var(--modus-wc-color-gray-10)}";
const ModusWcSelect = /*@__PURE__*/ proxyCustomElement(class ModusWcSelect extends H {
constructor() {
super();
this.__registerHost();
this.inputBlur = createEvent(this, "inputBlur");
this.inputChange = createEvent(this, "inputChange");
this.inputFocus = createEvent(this, "inputFocus");
this.inheritedAttributes = {};
/** Indicates that the input should have a border. */
this.bordered = true;
/** Custom CSS class to apply to the inner div. */
this.customClass = '';
/** Whether the form control is disabled. */
this.disabled = false;
/** The options to display in the select dropdown. */
this.options = [];
/** 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 control. */
this.value = '';
this.handleBlur = (event) => {
this.inputBlur.emit(event);
};
this.handleFocus = (event) => {
this.inputFocus.emit(event);
};
this.handleInput = (event) => {
this.inputChange.emit(event);
};
}
componentWillLoad() {
if (!this.el.ariaLabel) {
this.el.ariaLabel = 'Select';
}
this.inheritedAttributes = inheritAriaAttributes(this.el);
}
getClasses() {
const classList = ['modus-wc-select', 'modus-wc-w-full'];
const propClasses = convertPropsToClasses({
bordered: this.bordered,
feedback: this.feedback,
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() {
return (h(Host, { key: '105f4e06d3fce8ae7c4c3b663613004a275a48b0' }, this.label && (h("modus-wc-input-label", { key: '87acfb2056bf7fa24460219c7b91d8bdb7413b5b', forId: this.inputId, labelText: this.label, required: this.required, size: this.size })), h("select", Object.assign({ key: '1a2ca389c24128654b6857ad076f01481b3777a3', class: this.getClasses(), disabled: this.disabled, id: this.inputId, name: this.name, onBlur: this.handleBlur, onFocus: this.handleFocus, onInput: this.handleInput, required: this.required, tabindex: this.inputTabIndex }, this.inheritedAttributes), this.options.map((option) => (h("option", { disabled: option.disabled, selected: option.value === this.value, value: option.value }, option.label)))), this.feedback && (h("modus-wc-input-feedback", { key: 'aa662901e740e13d0504c46eda4d7db63ebc792d', level: this.feedback.level, message: this.feedback.message, size: this.size }))));
}
get el() { return this; }
static get style() { return modusWcSelectCss; }
}, [0, "modus-wc-select", {
"bordered": [4],
"customClass": [1, "custom-class"],
"disabled": [4],
"feedback": [16],
"inputId": [1, "input-id"],
"inputTabIndex": [2, "input-tab-index"],
"label": [1],
"name": [1],
"options": [1040],
"required": [4],
"size": [1],
"value": [1537]
}]);
function defineCustomElement() {
if (typeof customElements === "undefined") {
return;
}
const components = ["modus-wc-select", "modus-wc-icon", "modus-wc-input-feedback", "modus-wc-input-label"];
components.forEach(tagName => { switch (tagName) {
case "modus-wc-select":
if (!customElements.get(tagName)) {
customElements.define(tagName, ModusWcSelect);
}
break;
case "modus-wc-icon":
if (!customElements.get(tagName)) {
defineCustomElement$3();
}
break;
case "modus-wc-input-feedback":
if (!customElements.get(tagName)) {
defineCustomElement$2();
}
break;
case "modus-wc-input-label":
if (!customElements.get(tagName)) {
defineCustomElement$1();
}
break;
} });
}
export { ModusWcSelect as M, defineCustomElement as d };