@trimble-oss/moduswebcomponents
Version:
Modus Web Components is a modern, accessible UI library built with Stencil JS that provides reusable web components following Trimble's Modus design system. This updated version focuses on improved flexibility, enhanced theming options, comprehensive cust
342 lines (341 loc) • 12.4 kB
JavaScript
import { h, Host, } from "@stencil/core";
import { convertPropsToClasses } from "./modus-wc-checkbox.tailwind";
import { inheritAriaAttributes } from "../utils";
/**
* A customizable checkbox component
*/
export class ModusWcCheckbox {
constructor() {
this.inheritedAttributes = {};
/** Custom CSS class to apply to the inner div. */
this.customClass = '';
/** The disabled state of the checkbox. */
this.disabled = false;
/** The indeterminate state of the checkbox. */
this.indeterminate = false;
/** Name of the form control. Submitted with the form as part of a name/value pair. */
this.name = '';
/** A value is required for the form to be submittable. */
this.required = false;
/** The size of the input. */
this.size = 'md';
/** The value of the checkbox. */
this.value = false;
this.handleBlur = (event) => {
this.inputBlur.emit(event);
};
this.handleFocus = (event) => {
this.inputFocus.emit(event);
};
this.handleInput = (event) => {
this.inputChange.emit(event);
};
}
componentDidRender() {
const checkbox = this.el.querySelector('input[type="checkbox"]');
if (checkbox) {
checkbox.indeterminate = this.indeterminate;
}
}
componentWillLoad() {
if (!this.el.ariaLabel) {
this.el.ariaLabel = 'Checkbox';
}
this.inheritedAttributes = inheritAriaAttributes(this.el);
}
getClasses() {
const classList = ['modus-wc-checkbox'];
const propClasses = convertPropsToClasses({ size: this.size });
// The order CSS classes are added matters to CSS specificity
if (propClasses)
classList.push(propClasses);
if (this.customClass)
classList.push(this.customClass);
return classList.join(' ');
}
render() {
return (h(Host, { key: '2c42aefb37c871d59894fce4b06d5f6a7e89fd6e', class: "modus-wc-checkbox-host" }, h("input", Object.assign({ key: '7a15adf0ff6e852ab15f4223f3a8910b8cc8e62d', "aria-checked": this.indeterminate ? 'mixed' : this.value, "aria-disabled": this.disabled, checked: this.value, class: this.getClasses(), disabled: this.disabled, id: this.inputId, name: this.name, onBlur: this.handleBlur, onFocus: this.handleFocus, onInput: this.handleInput, required: this.required, tabIndex: this.inputTabIndex, type: "checkbox" }, this.inheritedAttributes)), this.label && (h("modus-wc-input-label", { key: '210f63d3ae893ca446b9b52199cc4e22832767af', forId: this.inputId, labelText: this.label, required: this.required, size: this.size }))));
}
static get is() { return "modus-wc-checkbox"; }
static get originalStyleUrls() {
return {
"$": ["modus-wc-checkbox.scss"]
};
}
static get styleUrls() {
return {
"$": ["modus-wc-checkbox.css"]
};
}
static get properties() {
return {
"customClass": {
"type": "string",
"attribute": "custom-class",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Custom CSS class to apply to the inner div."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"disabled": {
"type": "boolean",
"attribute": "disabled",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The disabled state of the checkbox."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "false"
},
"indeterminate": {
"type": "boolean",
"attribute": "indeterminate",
"mutable": true,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "The indeterminate state of the checkbox."
},
"getter": false,
"setter": false,
"reflect": true,
"defaultValue": "false"
},
"inputId": {
"type": "string",
"attribute": "input-id",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The ID of the input element."
},
"getter": false,
"setter": false,
"reflect": false
},
"inputTabIndex": {
"type": "number",
"attribute": "input-tab-index",
"mutable": false,
"complexType": {
"original": "number",
"resolved": "number | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The tabindex of the input."
},
"getter": false,
"setter": false,
"reflect": false
},
"label": {
"type": "string",
"attribute": "label",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The text to display within the label."
},
"getter": false,
"setter": false,
"reflect": false
},
"name": {
"type": "string",
"attribute": "name",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Name of the form control. Submitted with the form as part of a name/value pair."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"required": {
"type": "boolean",
"attribute": "required",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "A value is required for the form to be submittable."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "false"
},
"size": {
"type": "string",
"attribute": "size",
"mutable": false,
"complexType": {
"original": "ModusSize",
"resolved": "\"lg\" | \"md\" | \"sm\" | undefined",
"references": {
"ModusSize": {
"location": "import",
"path": "../types",
"id": "src/components/types.ts::ModusSize"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The size of the input."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'md'"
},
"value": {
"type": "boolean",
"attribute": "value",
"mutable": true,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "The value of the checkbox."
},
"getter": false,
"setter": false,
"reflect": true,
"defaultValue": "false"
}
};
}
static get events() {
return [{
"method": "inputBlur",
"name": "inputBlur",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": "Emitted when the input loses focus."
},
"complexType": {
"original": "FocusEvent",
"resolved": "FocusEvent",
"references": {
"FocusEvent": {
"location": "global",
"id": "global::FocusEvent"
}
}
}
}, {
"method": "inputChange",
"name": "inputChange",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": "Emitted when the input value changes."
},
"complexType": {
"original": "InputEvent",
"resolved": "InputEvent",
"references": {
"InputEvent": {
"location": "global",
"id": "global::InputEvent"
}
}
}
}, {
"method": "inputFocus",
"name": "inputFocus",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": "Emitted when the input gains focus."
},
"complexType": {
"original": "FocusEvent",
"resolved": "FocusEvent",
"references": {
"FocusEvent": {
"location": "global",
"id": "global::FocusEvent"
}
}
}
}];
}
static get elementRef() { return "el"; }
}