UNPKG

@postnord/web-components

Version:

PostNord Web Components

306 lines (305 loc) 11.7 kB
/*! * Built with Stencil * By PostNord. */ import { uuidv4 } from "../../../globals/helpers"; import { h, Host } from "@stencil/core"; /** * The `pn-checkbox` is built with a native `input[type="checkbox"]` in the background. * This means you can use native events to listen to the changes. * * @nativeChange Use the `change` event to listen when the checkbox state is being toggled. */ export class PnCheckbox { constructor() { this.label = undefined; this.value = undefined; this.name = undefined; this.checked = false; this.helpertext = undefined; this.checkboxid = this.id; this.disabled = false; this.required = false; this.invalid = false; this.indeterminate = false; this.tile = false; this.icon = null; } id = `pn-checkbox-${uuidv4()}`; idHelpertext = `${this.id}-helpertext`; hostElement; handleId() { this.idHelpertext = `${this.checkboxid}-helpertext`; } handlechange() { this.indeterminate = false; } componentWillLoad() { this.handleId(); } render() { return (h(Host, { key: '82fd05eac2c3b7032222bc666436b2cb75f0b698' }, h("input", { key: '4ff9c8fbe357e42997901325ebc78c4e0fc643e7', type: "checkbox", id: this.checkboxid, value: this.value, name: this.name || this.checkboxid, disabled: this.disabled, checked: this.checked, required: this.required, indeterminate: this.indeterminate, "aria-invalid": this.invalid?.toString(), "aria-describedby": this.helpertext && this.idHelpertext }), h("div", { key: 'f9d25890a66f6e45fad701f491d245b1ddbb2f76', class: "pn-checkbox", "data-tile": this.tile, "data-invalid": this.invalid }, h("div", { key: '1e1bb430eb787e0936ec591c960020e5355b1512', class: "pn-checkbox-outer" }, h("svg", { key: '88b8198cbed4c7bdbc715665b6816e6480c9e3cc', xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "none" }, h("polyline", { key: '36d57c92af17db48b068bc1da5a0adc8e34b8a1f', class: "pn-checkbox-checkmark-path", points: "4,12 9,17 20,6", "stroke-width": "3" }), h("polyline", { key: '350c7a6e7937e6ead3fb4b4728ba11c82bc39115', class: "pn-checkbox-indeterminate-path", points: "4,12 20,12", "stroke-width": "3" }))), (!!this.label || !!this.helpertext) && (h("p", { key: '3854e9296bcca7d347697442a9d927afea659b8b', class: "pn-checkbox-content" }, !!this.label && (h("label", { key: '231f5f054c2039cf1d10d44c25f4131862fcbe8d', htmlFor: this.checkboxid, class: "pn-checkbox-label" }, this.label)), !!this.helpertext && (h("span", { key: '0641a9caee84d5da2ecc17cac501ff4c8cc0bd6a', id: this.idHelpertext, class: "pn-checkbox-helpertext" }, this.helpertext)))), this.tile && this.icon && h("pn-icon", { key: '0ddcebee9d338136b43df1ef2afd292593898ea3', icon: this.icon, color: "gray900" })))); } static get is() { return "pn-checkbox"; } static get originalStyleUrls() { return { "$": ["pn-checkbox.scss"] }; } static get styleUrls() { return { "$": ["pn-checkbox.css"] }; } static get properties() { return { "label": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The checkbox label" }, "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, like a native checkbox" }, "attribute": "value", "reflect": true }, "name": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "The name of the checkbox group" }, "attribute": "name", "reflect": false }, "checked": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Check the radio button." }, "attribute": "checked", "reflect": false, "defaultValue": "false" }, "helpertext": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "This adds an optional helpertext element under the label" }, "attribute": "helpertext", "reflect": false }, "checkboxid": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "A unique HTML ID for the checkbox." }, "attribute": "checkboxid", "reflect": false, "defaultValue": "this.id" }, "disabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [{ "name": "category", "text": "State" }], "text": "Disable the radio button." }, "attribute": "disabled", "reflect": false, "defaultValue": "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 checkbox as required." }, "attribute": "required", "reflect": false, "defaultValue": "false" }, "invalid": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [{ "name": "category", "text": "State" }], "text": "If set to true, color scheme will turn red, indicating that there is an issue or incorrect input related the checkbox." }, "attribute": "invalid", "reflect": false, "defaultValue": "false" }, "indeterminate": { "type": "boolean", "mutable": true, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [{ "name": "category", "text": "State" }], "text": "Sets the checkbox to an indeterminate state, allowing for a mixed or intermediate checkbox state." }, "attribute": "indeterminate", "reflect": false, "defaultValue": "false" }, "tile": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [{ "name": "category", "text": "Tile" }], "text": "If set to true, this checkbox turns into a checkbox-tile." }, "attribute": "tile", "reflect": false, "defaultValue": "false" }, "icon": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "category", "text": "Tile" }], "text": "Add an icon on the right of your checkbox tile. The `tile` prop must be `true` for the icon to work." }, "attribute": "icon", "reflect": false, "defaultValue": "null" } }; } static get elementRef() { return "hostElement"; } static get watchers() { return [{ "propName": "checkboxid", "methodName": "handleId" }]; } static get listeners() { return [{ "name": "change", "method": "handlechange", "target": undefined, "capture": false, "passive": false }]; } } //# sourceMappingURL=pn-checkbox.js.map