UNPKG

gov-gui

Version:

Gov UI Component Library Typscript Build

222 lines (221 loc) 8.06 kB
import { h } from "@stencil/core"; import { getGlobalPropsClasses } from "../../global/global-styles-helper"; import { getAnimationClasses } from "../../global/animation-helpers"; export class MyDropdown { constructor() { this.options = []; // Accept both string and array this.parsedOptions = []; // Hold the actual array of options this.isOpen = false; this.selectedOption = 'Filter by type'; this.animationDelay = '2s'; this.allClasses = ''; } //watching for any change in animations to trigger them watchAnimations() { this.provideClass(); } watchAnimationsDelay() { this.provideClass(); } watchAnimationsSpeed() { this.provideClass(); } componentWillLoad() { // Parse the options prop if it's a JSON string if (typeof this.options === 'string') { try { this.parsedOptions = JSON.parse(this.options); } catch (error) { console.error('Invalid options format:', error); this.parsedOptions = []; } } else { this.parsedOptions = this.options; } 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, }); console.log('Animation classes:', animationClasses); console.log('All classes:', this.allClasses); } toggleDropdown() { this.isOpen = !this.isOpen; } selectOption(option) { this.selectedOption = option; this.isOpen = false; } render() { return (h("div", { key: '0002a7d8f68b4bae69f20735cc5b8b4301a01b61', class: `dropdown-container ${this.allClasses}` }, h("h2", { key: 'd94e40453e26a4a0312e20e78b495eaed93d2593' }, this.heading), h("p", { key: '1abdf8ead452b127f0b78048e0dd0cb0dcc0476d' }, this.subtitle), h("div", { key: 'd9f0134901b1daf8d85c08b228043b92c2723d2c' }, h("div", { key: 'fe09d92d3cf5ffd8585fd268ac6967a2880bbf36', class: `dropdown ${this.isOpen ? 'open' : ''}` }, h("div", { key: '6607cebe58251d935243ebdf52f01921e60372a5', class: "dropdown-header", onClick: () => this.toggleDropdown() }, this.selectedOption, " ", h("span", { key: 'f263a7ba0a20fa14ea71eb490a5d0595c8b2b10d', class: "arrow" }, this.isOpen ? '▲' : '▼')), this.isOpen && (h("div", { key: '16c65e4982871349e9a1ace63a3a164e746f4f5c', class: "dropdown-options" }, this.parsedOptions.length > 0 ? (this.parsedOptions.map(option => (h("div", { class: "dropdown-option", onClick: () => this.selectOption(option) }, option)))) : (h("div", { class: "dropdown-option" }, "No options available")))))))); } static get is() { return "gov-drop"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["gov-drop.css"] }; } static get styleUrls() { return { "$": ["gov-drop.css"] }; } static get properties() { return { "heading": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "heading", "reflect": false }, "subtitle": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "subtitle", "reflect": false }, "options": { "type": "string", "mutable": false, "complexType": { "original": "string | string[]", "resolved": "string | string[]", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "attribute": "options", "reflect": false, "defaultValue": "[]" }, "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 { "parsedOptions": {}, "isOpen": {}, "selectedOption": {} }; } static get watchers() { return [{ "propName": "animation", "methodName": "watchAnimations" }, { "propName": "animationDelay", "methodName": "watchAnimationsDelay" }, { "propName": "animationSpeed", "methodName": "watchAnimationsSpeed" }]; } } //# sourceMappingURL=gov-drop.js.map