UNPKG

gov-gui

Version:

Gov UI Component Library Typscript Build

266 lines (265 loc) 8.94 kB
import { h } from "@stencil/core"; import { getGlobalPropsClasses } from "../../global/global-styles-helper"; import { getAnimationClasses } from "../../global/animation-helpers"; export class GovChip { constructor() { this.selected = false; this.disabled = false; this.size = 'sm'; this.variant = 'primary'; this.hover = false; this.animationDelay = '2s'; this.allClasses = ''; this.handleClick = () => { if (!this.disabled) { this.selected = !this.selected; } }; this.handleMouseEnter = () => { if (!this.disabled) { this.hover = true; } }; this.handleMouseLeave = () => { this.hover = false; }; } //watching for any change in animations to trigger them watchAnimations() { this.provideClass(); } watchAnimationsDelay() { this.provideClass(); } watchAnimationsSpeed() { this.provideClass(); } // inject the animations and styles on component load componentWillLoad() { const animationClasses = getAnimationClasses({ animation: this.animation, animationDelay: this.animationDelay, animationSpeed: this.animationSpeed }); this.allClasses = getGlobalPropsClasses({ classes: ' ' + animationClasses, }); } //Called on change of any animation related property to trigger change provideClass() { const animationClasses = getAnimationClasses({ animation: this.animation, animationDelay: this.animationDelay, animationSpeed: this.animationSpeed }); this.allClasses = getGlobalPropsClasses({ classes: ' ' + animationClasses, }); } render() { const classes = { 'chip': true, 'chip--selected': this.selected, 'chip--hover': this.hover, 'chip--disabled': this.disabled, [`chip--${this.size}`]: true, [`chip--${this.variant}`]: true, }; // Convert the object to a string of space-separated class names const classesString = Object.keys(classes) .filter(key => classes[key]) .join(' '); return (h("div", { key: '67ebab5f87609ecf1f8c8e5c9d9dccc7b9b20b54', class: `${classesString} ${this.allClasses}`, onClick: this.handleClick, onMouseEnter: this.handleMouseEnter, onMouseLeave: this.handleMouseLeave, role: "button", tabindex: "0" }, this.selected && !this.disabled && (h("span", { key: 'b1c14ce8396b64f73cc71b741a4f73b290c04474', class: "chip__icon" }, "\u2714")), h("span", { key: 'ad501a0aa048556fe2a91eac8d558434203a95a4', class: "chip__label" }, this.label))); } static get is() { return "gov-chip"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["gov-chip.css"] }; } static get styleUrls() { return { "$": ["gov-chip.css"] }; } static get properties() { return { "label": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "label", "reflect": false }, "selected": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "selected", "reflect": true, "defaultValue": "false" }, "disabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "disabled", "reflect": true, "defaultValue": "false" }, "size": { "type": "string", "mutable": false, "complexType": { "original": "'sm' | 'md' | 'lg'", "resolved": "\"lg\" | \"md\" | \"sm\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "size", "reflect": true, "defaultValue": "'sm'" }, "variant": { "type": "string", "mutable": false, "complexType": { "original": "'primary' | 'secondary' | 'tertiary'", "resolved": "\"primary\" | \"secondary\" | \"tertiary\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "variant", "reflect": true, "defaultValue": "'primary'" }, "animation": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "animation", "reflect": false }, "animationDelay": { "type": "string", "mutable": false, "complexType": { "original": "'2s' | '3s' | '4s' | '5s'", "resolved": "\"2s\" | \"3s\" | \"4s\" | \"5s\"", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "animation-delay", "reflect": false, "defaultValue": "'2s'" }, "animationSpeed": { "type": "string", "mutable": false, "complexType": { "original": "'slow' | 'slower' | 'fast' | 'faster'", "resolved": "\"fast\" | \"faster\" | \"slow\" | \"slower\"", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "animation-speed", "reflect": false } }; } static get states() { return { "hover": {} }; } static get watchers() { return [{ "propName": "animation", "methodName": "watchAnimations" }, { "propName": "animationDelay", "methodName": "watchAnimationsDelay" }, { "propName": "animationSpeed", "methodName": "watchAnimationsSpeed" }]; } } //# sourceMappingURL=gov-chip.js.map