UNPKG

@postnord/web-components

Version:

PostNord Web Components

293 lines (292 loc) 10.6 kB
/*! * Built with Stencil * By PostNord. */ import { h, Host } from "@stencil/core"; import { uuidv4 } from "../../../globals/helpers"; import { check } from "pn-design-assets/pn-assets/icons.js"; /** * The `pn-choice-chip` is built with a native `input[type="checkbox|radio"]` in the background. * This means you can use native events to listen to the changes. * * @nativeChange Use the `change` event to listen when the choice chip state is being toggled. Works for both checkbox/radio variant. */ export class PnChoiceChip { hostElement; moving = false; /** The choice chip label */ label; /** This will be emitted on change and input */ value; /** The name of the checkbox group */ name; /** Precheck the choice chip */ checked = false; /** Make the choice chip a radio */ radio = false; /** A unique HTML id */ choiceid = `pn-choice-chip-${uuidv4()}`; /** Include an icon */ icon; /** Set the choice chip as required. @category State */ required = false; /** Disable the choice chip. @category State */ disabled = false; /** Set the size to small. @category Size */ small = false; /** Set the size to large. @category Size */ large = false; render() { return (h(Host, { key: 'b74986fe1928d28a6a3eacfdb9919a33d847de89' }, h("div", { key: '6b25a1b32b29596c3862af80d22f5063e5a1d7be', class: "pn-choice-chip" }, h("input", { key: '58308564d6ee8ce60472fe037fe7bef42627733d', type: this.radio ? 'radio' : 'checkbox', id: this.choiceid, value: this.value, name: this.name, checked: this.checked, required: this.required, disabled: this.disabled }), h("div", { key: 'f1debc7c902d94df49dcdb8b0abeaab331c25073', class: "pn-choice-chip-container", "data-icon": !!this.icon, "data-small": this.small, "data-large": this.large }, h("div", { key: '9a5ed1e9107f5c63b54dea6943290e74c5b7aca8', class: "pn-choice-chip-icon" }, h("pn-icon", { key: '05631fab98155a693063d1576675fa4aa10e3081', color: "blue700", class: "pn-choice-chip-icon-check", icon: check }), !!this.icon && h("pn-icon", { key: '41e6de5e34ea3ba1115ab1a7d14f81c6154c3a5a', color: "blue700", class: "pn-choice-chip-icon-user", icon: this.icon })), h("label", { key: 'ba505e94891f9d8fe50c3c9364c6e12cc1e9e844', class: "pn-choice-chip-label", htmlFor: this.choiceid }, h("span", { key: 'd0e2ccf06db3d4fb19dc470b1b422dc1ca04c9d5' }, this.label), h("slot", { key: '25ffbcad9a5e81594d39dffc6d0b2421013ab89d' })))))); } static get is() { return "pn-choice-chip"; } static get originalStyleUrls() { return { "$": ["pn-choice-chip.scss"] }; } static get styleUrls() { return { "$": ["pn-choice-chip.css"] }; } static get properties() { return { "label": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": true, "optional": false, "docs": { "tags": [], "text": "The choice chip label" }, "getter": false, "setter": false, "attribute": "label", "reflect": false }, "value": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": true, "optional": false, "docs": { "tags": [], "text": "This will be emitted on change and input" }, "getter": false, "setter": false, "attribute": "value", "reflect": true }, "name": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The name of the checkbox group" }, "getter": false, "setter": false, "attribute": "name", "reflect": false }, "checked": { "type": "boolean", "mutable": true, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Precheck the choice chip" }, "getter": false, "setter": false, "attribute": "checked", "reflect": false, "defaultValue": "false" }, "radio": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Make the choice chip a radio" }, "getter": false, "setter": false, "attribute": "radio", "reflect": false, "defaultValue": "false" }, "choiceid": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "A unique HTML id" }, "getter": false, "setter": false, "attribute": "choiceid", "reflect": false, "defaultValue": "`pn-choice-chip-${uuidv4()}`" }, "icon": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Include an icon" }, "getter": false, "setter": false, "attribute": "icon", "reflect": false }, "required": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [{ "name": "category", "text": "State" }], "text": "Set the choice chip as required." }, "getter": false, "setter": false, "attribute": "required", "reflect": false, "defaultValue": "false" }, "disabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [{ "name": "category", "text": "State" }], "text": "Disable the choice chip." }, "getter": false, "setter": false, "attribute": "disabled", "reflect": false, "defaultValue": "false" }, "small": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [{ "name": "category", "text": "Size" }], "text": "Set the size to small." }, "getter": false, "setter": false, "attribute": "small", "reflect": false, "defaultValue": "false" }, "large": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [{ "name": "category", "text": "Size" }], "text": "Set the size to large." }, "getter": false, "setter": false, "attribute": "large", "reflect": false, "defaultValue": "false" } }; } static get states() { return { "moving": {} }; } static get elementRef() { return "hostElement"; } } //# sourceMappingURL=pn-choice-chip.js.map