UNPKG

@postnord/web-components

Version:
173 lines (168 loc) 13.3 kB
/*! * Built with Stencil * By PostNord. */ import { proxyCustomElement, Mixin, h, Host } from '@stencil/core/internal/client'; import { u as uuidv4 } from './helpers.js'; import { a as animateHeightFactory } from './index2.js'; import { d as defineCustomElement$2 } from './pn-icon2.js'; const pnRadioButtonCss = "pn-radio-button{position:relative;display:inline-block}pn-radio-button .pn-radio{position:relative;display:flex;flex-wrap:wrap;flex-direction:row}pn-radio-button .pn-radio-label{cursor:pointer;color:#2d2013;-webkit-tap-highlight-color:transparent}pn-radio-button .pn-radio-helpertext{color:#5e554a;margin:0 0 0.5em 0}pn-radio-button .pn-radio-helpertext:last-child{margin:0}pn-radio-button .pn-radio-content{display:flex;flex-direction:column;align-items:flex-start;font-weight:400;line-height:1.5;flex:1;margin:0 0 0 0.75em}pn-radio-button .pn-radio-button{display:flex;gap:0.75em;padding:0}pn-radio-button .pn-radio-outer{background-color:#ffffff;border:0.0625em solid #969087;border-radius:50%;height:1.5em;width:1.5em;display:flex;justify-content:center;align-items:center;outline:0.2rem solid transparent;outline-offset:0.2rem;transition-property:border-color, background-color, outline-color;transition-duration:0.2s;transition-timing-function:cubic-bezier(0.7, 0, 0.3, 1)}@media (prefers-reduced-motion: reduce){pn-radio-button .pn-radio-outer{transition-duration:0s;transition-delay:0s}}pn-radio-button .pn-radio-inner{height:0.75em;width:0.75em;background-color:#005d92;border-radius:50%;transform:scale(0);transform-origin:center center;transition-property:background-color, transform;transition-duration:0.2s;transition-timing-function:cubic-bezier(0.7, 0, 0.3, 1)}@media (prefers-reduced-motion: reduce){pn-radio-button .pn-radio-inner{transition-duration:0s;transition-delay:0s}}pn-radio-button .pn-radio[data-tile]{padding:1em;border:0.0625em solid #969087;border-radius:0.5em;background-color:#ffffff;outline:0.2rem solid transparent;outline-offset:0.2rem;transition-property:border-color, background-color, outline-color;transition-duration:0.2s;transition-timing-function:cubic-bezier(0.7, 0, 0.3, 1)}@media (prefers-reduced-motion: reduce){pn-radio-button .pn-radio[data-tile]{transition-duration:0s;transition-delay:0s}}pn-radio-button .pn-radio[data-tile] .pn-radio-outer{outline:none}pn-radio-button .pn-radio[data-invalid]{border-color:#a70707}pn-radio-button .pn-radio[data-invalid] .pn-radio-outer{border-color:#a70707}pn-radio-button .pn-radio[data-invalid] .pn-radio-inner{background-color:#a70707}pn-radio-button .pn-radio-container{flex:1 1 100%;overflow:hidden;visibility:hidden}pn-radio-button .pn-radio-container[data-open]{visibility:visible;overflow:unset}pn-radio-button .pn-radio-container[data-moving]{visibility:visible;overflow:hidden}pn-radio-button .pn-radio-area{padding:0.75em 0 0 2.25em;display:flex;flex-direction:column;flex-wrap:nowrap;gap:1em}pn-radio-button .pn-radio>pn-icon{margin-left:0.75em}pn-radio-button>input[type=radio]{cursor:pointer;opacity:0;position:absolute;margin:0;z-index:1;top:0;left:0;font-size:1em;width:1.5em;height:1.5em;-webkit-tap-highlight-color:transparent}pn-radio-button>input[type=radio][data-tile]:not([data-expand]){width:100%;height:100%}pn-radio-button>input[type=radio][data-expand]{top:1em;left:1em}pn-radio-button>input[type=radio][aria-describedby]+.pn-radio[data-tile] .pn-radio-label{font-weight:500}pn-radio-button>input[type=radio]:hover+.pn-radio[data-tile]{border-color:#005d92;background-color:#e0f8ff}pn-radio-button>input[type=radio]:hover+.pn-radio[data-tile] .pn-radio-outer{background-color:#e0f8ff}pn-radio-button>input[type=radio]:hover+.pn-radio[data-tile][data-invalid]{border-color:#a70707;background-color:#fdefee}pn-radio-button>input[type=radio]:hover+.pn-radio[data-tile][data-invalid] .pn-radio-outer{background-color:#fdefee}pn-radio-button>input[type=radio]:hover+.pn-radio[data-invalid] .pn-radio-outer{border-color:#a70707;background-color:#fdefee}pn-radio-button>input[type=radio]:hover+.pn-radio .pn-radio-outer{border-color:#005d92;background-color:#e0f8ff}pn-radio-button>input[type=radio]:checked:hover+.pn-radio[data-tile][data-invalid]{border-color:#500715}pn-radio-button>input[type=radio]:checked:hover+.pn-radio[data-invalid]>.pn-radio-button>.pn-radio-outer{border-color:#500715}pn-radio-button>input[type=radio]:focus-visible+.pn-radio .pn-radio-outer{outline-color:#005d92}pn-radio-button>input[type=radio]:focus-visible+.pn-radio[data-invalid] .pn-radio-outer{outline-color:#a70707}pn-radio-button>input[type=radio]:focus-visible+.pn-radio[data-tile]{outline-color:#005d92;border-color:#005d92}pn-radio-button>input[type=radio]:focus-visible+.pn-radio[data-tile][data-invalid]{outline-color:#a70707;border-color:#a70707}pn-radio-button>input[type=radio]:focus-visible+.pn-radio[data-tile]>.pn-radio-button>.pn-radio-outer{outline:none}pn-radio-button>input[type=radio]:checked+.pn-radio[data-tile]{border-color:#005d92;background-color:#e0f8ff}pn-radio-button>input[type=radio]:checked+.pn-radio[data-tile][data-invalid]{border-color:#a70707;background-color:#fdefee}pn-radio-button>input[type=radio]:checked+.pn-radio>.pn-radio-button>.pn-radio-outer{border-color:#005d92}pn-radio-button>input[type=radio]:checked+.pn-radio>.pn-radio-button>.pn-radio-outer>.pn-radio-inner{transform:scale(1);background-color:#005d92}pn-radio-button>input[type=radio]:checked+.pn-radio[data-invalid]>.pn-radio-button>.pn-radio-outer{border-color:#a70707}pn-radio-button>input[type=radio]:checked+.pn-radio[data-invalid]>.pn-radio-button>.pn-radio-outer>.pn-radio-inner{background-color:#a70707}pn-radio-button>input[type=radio]:disabled{pointer-events:none}pn-radio-button>input[type=radio]:disabled+.pn-radio .pn-radio-label{pointer-events:none}pn-radio-button>input[type=radio]:disabled+.pn-radio[data-tile]{background-color:#f3f2f2;border-color:#f3f2f2}pn-radio-button>input[type=radio]:disabled+.pn-radio[data-tile]>pn-icon>.pn-icon-svg path{fill:#5e554a}pn-radio-button>input[type=radio]:disabled+.pn-radio[data-tile]>.pn-radio-content>.pn-radio-label{color:#5e554a}pn-radio-button>input[type=radio]:disabled+.pn-radio>.pn-radio-button>.pn-radio-outer{background-color:#f3f2f2;border-color:#969087;outline:none}pn-radio-button>input[type=radio]:disabled+.pn-radio>.pn-radio-button>.pn-radio-outer>.pn-radio-inner{background-color:#969087}"; const PnRadioButton$1 = /*@__PURE__*/ proxyCustomElement(class PnRadioButton extends Mixin(animateHeightFactory) { constructor(registerHost) { super(false); if (registerHost !== false) { this.__registerHost(); } } id = `pn-radio-${uuidv4()}`; idHelpertext = `${this.id}-helpertext`; contentArea; radioInput; get hostElement() { return this; } /** The radio label */ label; /** This adds an optional helpertext under the label. */ helpertext; /** This will be emitted on change and input events. */ value; /** The name of the radio group. */ name; /** Check the radio. */ checked = false; /** A unique HTML ID for the radio. */ radioid = this.id; /** Set the radio as required. @category State */ required = false; /** Disable the radio. @category State */ disabled = false; /** If set to true, color scheme will turn red, indicating that there is an issue or incorrect input related the radio. @category State */ invalid = false; /** * Turn the radio into a clickable tile. A border and padding is added. * * **Do not** use interactive elements (links/buttons) inside of the slots when using this prop. * An exception is made when using the `tile` + `expand` props together, * which allows you to use interactive elements. * * @category Tile */ tile = false; /** * Allow the radio to control the slot area "content". * When checked, the area is visible, when unchecked, the area is hidden. * * The prop `tile` must be used at the same time. * @see {@link tile} * @since v7.17.0 * @category Tile */ expand = false; /** * Add an icon on the right of your radio tile. The `tile` prop must be `true` for the icon to work. * @see {@link tile} * @category Tile */ icon = null; handleId() { this.idHelpertext = `${this.radioid}-helpertext`; } handleChecked() { this.checked = this.radioInput.checked; if (!this.displayContent()) return; if (this.checked) { this.openDropdown(this.contentArea); } else { this.closeDropdown(this.contentArea); } } handleChange(e) { const { name } = e.target; const isSameRadioGroup = name === this.name; /** * Since content can be nested inside of this component, * double check that the event is coming from this specific radio. */ if (isSameRadioGroup) this.checked = this.radioInput.checked; } componentWillLoad() { this.handleId(); } componentDidLoad() { requestAnimationFrame(() => { if (this.displayContent() && this.radioInput.checked) this.openDropdown(this.contentArea); else this.checked = false; }); } isInvalid() { return this.invalid && !this.disabled; } displayText() { return this.displayLabel() || this.displayHelpertext(); } displayLabel() { return !!this.label; } displayHelpertext() { return !!(this.helpertext || this.hostElement.querySelector('[slot="helpertext"]')?.textContent); } displayIcon() { return this.tile && !!this.icon; } displayContent() { return this.tile && this.expand; } render() { return (h(Host, { key: '4ce792357af2aa45ea600b7e93cd2c48f9761949' }, h("input", { key: '0da7848603e6194b194f3908c6ae94d18fddc81d', type: "radio", id: this.radioid, class: "pn-radio-input", value: this.value, name: this.name, disabled: this.disabled, checked: this.checked, required: this.required, "aria-invalid": this.isInvalid()?.toString(), "aria-describedby": this.helpertext && this.idHelpertext, "data-tile": this.tile, "data-expand": this.expand, ref: el => (this.radioInput = el) }), h("div", { key: '54e7114a4570c4de7b55f0f0156084d4691bc4ba', class: "pn-radio", "data-tile": this.tile, "data-expand": this.expand, "data-invalid": this.isInvalid() }, h("div", { key: '4ed96522fb7cf5e37636ccbab0a80abe9da41c61', class: "pn-radio-button" }, h("div", { key: '666ca6f0b6ff5087161fceaea63e91992b1235b1', class: "pn-radio-outer" }, h("div", { key: '283e1b6073b0631656652f1dbcf56d94ffac9384', class: "pn-radio-inner" }))), h("p", { key: '54946df55fe4cc8e7dc576d68a92e9ca8e8dc479', class: "pn-radio-content", hidden: !this.displayText() }, h("label", { key: '253244165b2f60e25b9964f30a1d9a10c2403a23', htmlFor: this.radioid, class: "pn-radio-label", hidden: !this.displayLabel() }, this.label), h("span", { key: 'b0fc2c2b862e7fe87a382bef3f180fce524aa239', id: this.idHelpertext, class: "pn-radio-helpertext", hidden: !this.displayHelpertext() }, this.helpertext, h("slot", { key: '9a2fd56d890888fb6e3a65f5b0910bacb690f948', name: "helpertext" })), h("slot", { key: 'bd2229478a4bdac59d57ea3b95ef6a0305fb6c4e' })), this.displayIcon() && h("pn-icon", { key: '74742118fda52e6746be9af330b9c748767e6630', icon: this.icon, color: "gray900" }), h("div", { key: '0f8f488faa70684f8f9b008f4f7b58317565b665', class: "pn-radio-container", "data-open": this.checked, hidden: !this.displayContent(), style: { height: '0px' }, ref: el => (this.contentArea = el) }, h("div", { key: 'ff42957d08901153a930bced6046295e727943f8', class: "pn-radio-area" }, h("slot", { key: 'b8069fc5bc09709887fbb9071f9db2dd5f59a199', name: "content" })))))); } static get watchers() { return { "radioid": ["handleId"], "checked": ["handleChecked"] }; } static get style() { return pnRadioButtonCss; } }, [260, "pn-radio-button", { "label": [1], "helpertext": [1], "value": [513], "name": [1], "checked": [1028], "radioid": [1], "required": [4], "disabled": [4], "invalid": [4], "tile": [4], "expand": [4], "icon": [1], "isClosing": [32], "isExpanding": [32] }, [[8, "change", "handleChange"]], { "radioid": ["handleId"], "checked": ["handleChecked"] }]); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["pn-radio-button", "pn-icon"]; components.forEach(tagName => { switch (tagName) { case "pn-radio-button": if (!customElements.get(tagName)) { customElements.define(tagName, PnRadioButton$1); } break; case "pn-icon": if (!customElements.get(tagName)) { defineCustomElement$2(); } break; } }); } const PnRadioButton = PnRadioButton$1; const defineCustomElement = defineCustomElement$1; export { PnRadioButton, defineCustomElement }; //# sourceMappingURL=pn-radio-button.js.map //# sourceMappingURL=pn-radio-button.js.map