UNPKG

@postnord/web-components

Version:
77 lines (72 loc) 7.58 kB
/*! * Built with Stencil * By PostNord. */ 'use strict'; var index = require('./index-DVv2io0H.js'); var alert_exclamation_circle = require('./alert_exclamation_circle-BiBEJK9P.js'); var chevron_down = require('./chevron_down-BLU6_yOG.js'); var index$1 = require('./index.cjs.js'); const pnSelectCss = "pn-select{display:inline-block}pn-select .pn-select-label{cursor:pointer;display:flex;justify-content:space-between;align-items:flex-end;font-weight:400;color:#2d2013;margin:0 0 0.25em 0;gap:0.5em;-webkit-tap-highlight-color:transparent;transition-property:color;transition-duration:0.2s;transition-timing-function:cubic-bezier(0.7, 0, 0.3, 1)}@media (prefers-reduced-motion: reduce){pn-select .pn-select-label{transition-duration:0s;transition-delay:0s}}pn-select .pn-select-label>span{font-size:0.875em}pn-select .pn-select-input{position:relative}pn-select .pn-select-icon{pointer-events:none;position:absolute;top:50%;transform:translateY(-50%);width:1.5em;height:1.5em;border-radius:50%;background-color:transparent}pn-select .pn-select-icon[data-default]{right:0.75em}pn-select .pn-select-icon[data-custom]{left:0.75em}pn-select .pn-select-icon[data-custom]~.pn-select-element{padding-left:3em}pn-select .pn-select-icon[data-error]{right:3em}pn-select .pn-select-icon[data-error]~.pn-select-element{padding-right:5em}pn-select .pn-select-icon>.pn-icon-svg{transition-property:transform;transition-duration:0.2s;transition-timing-function:cubic-bezier(0.7, 0, 0.3, 1)}@media (prefers-reduced-motion: reduce){pn-select .pn-select-icon>.pn-icon-svg{transition-duration:0s;transition-delay:0s}}pn-select .pn-select-element{cursor:pointer;color:#2d2013;background-color:#ffffff;border:0.0625em solid #969087;border-radius:0.5em;padding:0.75em;font-family:inherit;font-size:1em;font-weight:500;line-height:1.5em;-webkit-font-smoothing:antialiased;-webkit-tap-highlight-color:transparent}pn-select .pn-select-element:-webkit-autofill,pn-select .pn-select-element:-webkit-autofill:hover,pn-select .pn-select-element:-webkit-autofill:focus,pn-select .pn-select-element:-webkit-autofill:active{-webkit-box-shadow:0 0 0 10em #e0f8ff inset;-webkit-text-fill-color:#2d2013}pn-select .pn-select-element{outline:0.2rem solid transparent;outline-offset:0.2rem}pn-select .pn-select-element:focus-visible{outline-color:#005d92;background-color:#ffffff;border-color:#005d92}pn-select .pn-select-element{transition-property:outline-color, background-color, border-color, color;transition-duration:0.2s;transition-timing-function:cubic-bezier(0.7, 0, 0.3, 1)}@media (prefers-reduced-motion: reduce){pn-select .pn-select-element{transition-duration:0s;transition-delay:0s}}pn-select .pn-select-element::placeholder{color:#5e554a;font-weight:normal}pn-select .pn-select-element:hover{border-color:#005d92}pn-select .pn-select-element:disabled{color:#5e554a;background-color:#f3f2f2;border-color:#f3f2f2}pn-select .pn-select-element{width:100%;padding-right:3em;-webkit-appearance:none;-moz-appearance:none;appearance:none}pn-select .pn-select-element:open+pn-icon .pn-icon-svg{transform:rotate(180deg)}pn-select .pn-select-element:disabled{color:#5e554a;background-color:#f3f2f2;border-color:#f3f2f2}pn-select .pn-select-element[data-placeholder]{color:#5e554a;font-weight:normal}pn-select .pn-select-element:hover{color:#2d2013;background-color:#effbff}pn-select .pn-select-no-results{margin:0;padding:0.75em}pn-select .pn-select-helper{color:#5e554a;font-size:0.875em;font-weight:400;margin:0.25em 0 0 0;display:flex;flex-direction:column;gap:0.25em}pn-select .pn-select-helper[role=alert]{color:#a70707}pn-select .pn-select[data-error]>.pn-select-label{color:#a70707}pn-select .pn-select[data-error]>.pn-select-input>.pn-select-element{border-color:#a70707}pn-select .pn-select[data-error]>.pn-select-input>.pn-select-element:hover{border-color:#500715}pn-select .pn-select[data-error]>.pn-select-input>.pn-select-element:focus-visible{background-color:#ffffff;border-color:#a70707;outline-color:#a70707}pn-select .pn-select[data-error]>.pn-select-input>.pn-select-element:hover{background-color:#fdefee}"; const PnSelect = class { constructor(hostRef) { index.registerInstance(this, hostRef); } id = `pn-select-${index$1.uuidv4()}`; idHelpertext = `${this.id}-text`; select; mo; get hostElement() { return index.getElement(this); } /** Label placed above the select. */ label; /** Display a helper text underneath the select. */ helpertext; /** Select HTML id */ selectId = this.id; /** Display an icon to the left of the select input. */ icon; /** HTML select name. @category HTML */ name; /** HTML form name. @category HTML */ form; /** HTML autocomplete. @category HTML */ autocomplete; /** * Set the select as required. * @category Validation */ required = false; /** * Disable the select. * @category Validation */ disabled = false; /** * Trigger the invalid state. * @category Validation */ invalid = false; /** * Display an error message and trigger the invalid state. * @category Validation */ error; componentDidLoad() { if (this.mo) this.mo.disconnect(); this.mo = new MutationObserver(() => index.forceUpdate(this.hostElement)); this.mo.observe(this.hostElement, { childList: true, subtree: true }); } hasError() { return this.invalid || !!this.error; } hasMessage() { return !!this.helpertext || !!this.error; } render() { return (index.h(index.Host, { key: '810261028a57676a607be5484adc734e3dc8585f' }, index.h("div", { key: 'c53f4efdf7f6b671320449b1587a8c54d5212eda', class: "pn-select", "data-error": this.hasError() }, this.label && (index.h("label", { key: '0e34dc7ea37d21adbfba8cae4aa40fdce008527f', htmlFor: this.selectId, class: "pn-select-label" }, index.h("span", { key: '241895f4272e92267985bf08a72efe0f3197e041' }, this.label))), index.h("div", { key: '2f2a1be7ba996bdd80b133caea326ad68feff722', class: "pn-select-input" }, this.icon && index.h("pn-icon", { key: '4d9c72ec0db0798a23468a71017b9228a26ec5b8', class: "pn-select-icon", icon: this.icon, "data-custom": true, "aria-hidden": "true" }), this.hasError() && (index.h("pn-icon", { key: 'fa759790b857a658235cd152c9173a668d80854f', class: "pn-select-icon", icon: alert_exclamation_circle.alert_exclamation_circle, color: "warning", "data-error": true, "aria-hidden": "true" })), index.h("select", { key: 'f772ebb5a0c9e5c0b04c6db27d570a1c5c9dc571', id: this.selectId, class: "pn-select-element", name: this.name, form: this.form, autocomplete: this.autocomplete, "aria-describedby": this.hasMessage() && this.idHelpertext, "aria-invalid": this.hasError().toString(), disabled: this.disabled, "data-placeholder": this.select?.value === '', ref: el => (this.select = el) }, index.h("slot", { key: '114336b1b1c8cb23855ed894dd3a525730b02a93' })), index.h("pn-icon", { key: '6e8ec3aa93753b50cf3b975b1a03e7667c7f51be', class: "pn-select-icon", icon: chevron_down.chevron_down, color: "blue700", "data-default": true, "aria-hidden": "true" })), this.hasMessage() && (index.h("p", { key: 'a7978486474a959d2d229da5b416233ed3083648', id: this.idHelpertext, class: "pn-select-helper", role: !!this.error ? 'alert' : null }, index.h("span", { key: 'b788645f220059c7f0226458bf65167f49d09060' }, this.error || this.helpertext)))))); } }; PnSelect.style = pnSelectCss; exports.pn_select = PnSelect; //# sourceMappingURL=pn-select.entry.cjs.js.map