@utrecht/web-component-library-stencil
Version:
Stencil component library bundle for the Municipality of Utrecht based on the NL Design System architecture
365 lines (364 loc) • 13.7 kB
JavaScript
/**
* @license EUPL-1.2
* Copyright (c) 2020-2024 Frameless B.V.
* Copyright (c) 2021-2024 Gemeente Utrecht
*/
import { h } from "@stencil/core";
import clsx from "clsx";
export class FormFieldTextbox {
constructor() {
this.autoComplete = '';
this.disabled = false;
this.invalid = false;
this.label = '';
this.min = '';
this.max = '';
this.name = '';
this.pattern = '';
this.placeholder = '';
this.readOnly = false;
this.required = false;
this.type = '';
this.value = '';
}
render() {
const { autoComplete, disabled, hostElement, invalid, label, min, max, name, pattern, placeholder, readOnly, required, type, value, } = this;
let input = hostElement.querySelector('input[type="hidden"]');
if (input && !name) {
input.parentNode.removeChild(input);
}
if (!input && name) {
input = hostElement.ownerDocument.createElement('input');
input.type = 'hidden';
input.ariaHidden = 'true';
hostElement.appendChild(input);
}
if (input && name) {
input.name = name;
input.value = value || '';
}
return (h("div", { key: 'c090a869092abec0630e756ee19fcd30e335d2c8', class: clsx('utrecht-form-field', 'utrecht-form-field--textbox', {
'utrecht-form-field--invalid': invalid,
}) }, h("p", { key: 'f274897a079478facb3acacb371ba3332f60e7dc', class: "utrecht-form-field__label" }, h("label", { key: 'f68cfd0cc55585dae91bce92a13de711430961a9', class: clsx('utrecht-form-label', {
'utrecht-form-label--disabled': disabled,
}), htmlFor: "input" }, label, h("slot", { key: '08aa7d40ef4d2c3b1b677fb520592a4d0af5529f', name: "label" }))), h("utrecht-form-field-description", { key: '08ab3afb09b3163d2ea8a48a8c7a13f2458b6582', id: "description" }, h("slot", { key: '60338c41dc3ce7856346a22bf0e09d252a5efbdc', name: "description" })), invalid && (h("utrecht-form-field-description", { key: '3570c86b8c3ba92dd7fbb9f32d0121b04911d17a', status: "invalid", class: "utrecht-form-field__error-message", id: "error-message" }, h("slot", { key: '6e2ac0a358e860556a368cff07d1687765538c2b', name: "error-message" }))), h("p", { key: 'f8dea2c3a9b9ac8611c9276f18623e89cb36b1f8', class: "utrecht-form-field__input" }, h("input", { key: '587a0be0dec1c9de86234e2b1f6898b6d9406843', id: "input", class: clsx('utrecht-form-field__input', 'utrecht-textbox', 'utrecht-textbox--html-input', disabled && 'utrecht-textbox--disabled', invalid && 'utrecht-textbox--invalid', readOnly && 'utrecht-textbox--readonly'), type: type || 'text', autoComplete: autoComplete ? autoComplete : null, "aria-describedby": clsx('description', 'status', { 'error-message': invalid }), "aria-invalid": invalid, dir: "auto", disabled: disabled, min: typeof min === 'number' ? String(min) : typeof min === 'string' ? min : null, max: typeof max === 'number' ? String(max) : typeof max === 'string' ? max : null, pattern: pattern ? pattern : null, placeholder: placeholder || null, readonly: readOnly, required: required, value: value, onBlur: (evt) => this.utrechtBlur.emit(evt), onChange: (evt) => this.utrechtChange.emit(evt), onFocus: (evt) => this.utrechtFocus.emit(evt), onInput: (evt) => {
this.value = evt.target.value;
this.utrechtInput.emit(evt);
} })), h("div", { key: 'd2dcb3f4dd9b36ccf1537f451e0a87e7bbf701d9', class: "utrecht-form-field__status", id: "status" }, h("div", { key: 'bf895ff5118e0ed6f9390ab1f8664df1484fa9a3', class: "utrecht-form-field-description utrecht-form-field-description--status" }, h("slot", { key: '50f0129c9ef48476bbd69549ae017012ca05023e', name: "status" })))));
}
static get is() { return "utrecht-form-field-textbox"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() {
return {
"$": ["form-field-textbox.scss"]
};
}
static get styleUrls() {
return {
"$": ["form-field-textbox.css"]
};
}
static get properties() {
return {
"autoComplete": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "autocomplete",
"reflect": true,
"defaultValue": "''"
},
"disabled": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "disabled",
"reflect": true,
"defaultValue": "false"
},
"invalid": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "invalid",
"reflect": true,
"defaultValue": "false"
},
"label": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "label",
"reflect": false,
"defaultValue": "''"
},
"min": {
"type": "any",
"mutable": false,
"complexType": {
"original": "number | string",
"resolved": "number | string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "min",
"reflect": false,
"defaultValue": "''"
},
"max": {
"type": "any",
"mutable": false,
"complexType": {
"original": "number | string",
"resolved": "number | string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "max",
"reflect": false,
"defaultValue": "''"
},
"name": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "name",
"reflect": false,
"defaultValue": "''"
},
"pattern": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "pattern",
"reflect": false,
"defaultValue": "''"
},
"placeholder": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "placeholder",
"reflect": false,
"defaultValue": "''"
},
"readOnly": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "readonly",
"reflect": true,
"defaultValue": "false"
},
"required": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "required",
"reflect": true,
"defaultValue": "false"
},
"type": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "type",
"reflect": true,
"defaultValue": "''"
},
"value": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "value",
"reflect": false,
"defaultValue": "''"
}
};
}
static get events() {
return [{
"method": "utrechtBlur",
"name": "utrechtBlur",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
}
}, {
"method": "utrechtChange",
"name": "utrechtChange",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
}
}, {
"method": "utrechtFocus",
"name": "utrechtFocus",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
}
}, {
"method": "utrechtInput",
"name": "utrechtInput",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
}
}];
}
static get elementRef() { return "hostElement"; }
}
//# sourceMappingURL=form-field-textbox.js.map