@cscfi/csc-ui 1.3.7 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/c-accordion-item.cjs.entry.js +1 -1
- package/dist/cjs/c-alert.cjs.entry.js +1 -1
- package/dist/cjs/c-autocomplete_34.cjs.entry.js +56 -22
- package/dist/cjs/c-autocomplete_34.cjs.entry.js.map +1 -1
- package/dist/cjs/c-data-table.cjs.entry.js +1 -1
- package/dist/cjs/c-menu_2.cjs.entry.js +25 -3
- package/dist/cjs/c-menu_2.cjs.entry.js.map +1 -1
- package/dist/cjs/c-pagination.cjs.entry.js +1 -1
- package/dist/cjs/c-swiper.cjs.entry.js +1 -1
- package/dist/cjs/c-tabs.cjs.entry.js +1 -1
- package/dist/cjs/c-tag.cjs.entry.js +4 -2
- package/dist/cjs/c-tag.cjs.entry.js.map +1 -1
- package/dist/cjs/c-tags.cjs.entry.js +11 -1
- package/dist/cjs/c-tags.cjs.entry.js.map +1 -1
- package/dist/cjs/c-toast.cjs.entry.js +1 -1
- package/dist/cjs/csc-ui.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{mdi-16842afc.js → mdi-66dcba4d.js} +21 -21
- package/dist/cjs/mdi-66dcba4d.js.map +1 -0
- package/dist/collection/components/c-button/c-button.css +1 -0
- package/dist/collection/components/c-dropdown/c-dropdown.js +21 -4
- package/dist/collection/components/c-dropdown/c-dropdown.js.map +1 -1
- package/dist/collection/components/c-input/c-input.js +2 -4
- package/dist/collection/components/c-input/c-input.js.map +1 -1
- package/dist/collection/components/c-otp-input/c-otp-input.js +69 -10
- package/dist/collection/components/c-otp-input/c-otp-input.js.map +1 -1
- package/dist/collection/components/c-side-navigation-item/c-side-navigation-item.css +1 -4
- package/dist/collection/components/c-side-navigation-item/c-side-navigation-item.js +1 -1
- package/dist/collection/components/c-side-navigation-item/c-side-navigation-item.js.map +1 -1
- package/dist/collection/components/c-tag/c-tag.css +24 -5
- package/dist/collection/components/c-tag/c-tag.js +20 -0
- package/dist/collection/components/c-tag/c-tag.js.map +1 -1
- package/dist/collection/components/c-tags/c-tags.css +1 -2
- package/dist/collection/components/c-tags/c-tags.js +34 -0
- package/dist/collection/components/c-tags/c-tags.js.map +1 -1
- package/dist/components/c-button.js +1 -1
- package/dist/components/c-button.js.map +1 -1
- package/dist/components/c-dropdown2.js +20 -3
- package/dist/components/c-dropdown2.js.map +1 -1
- package/dist/components/c-input2.js +2 -4
- package/dist/components/c-input2.js.map +1 -1
- package/dist/components/c-menu-items2.js +23 -1
- package/dist/components/c-menu-items2.js.map +1 -1
- package/dist/components/c-otp-input.js +35 -13
- package/dist/components/c-otp-input.js.map +1 -1
- package/dist/components/c-side-navigation-item.js +9 -3
- package/dist/components/c-side-navigation-item.js.map +1 -1
- package/dist/components/c-tag.js +5 -2
- package/dist/components/c-tag.js.map +1 -1
- package/dist/components/c-tags.js +14 -2
- package/dist/components/c-tags.js.map +1 -1
- package/dist/components/mdi.js +20 -20
- package/dist/components/mdi.js.map +1 -1
- package/dist/csc-ui/csc-ui.esm.js +1 -1
- package/dist/csc-ui/csc-ui.esm.js.map +1 -1
- package/dist/csc-ui/p-0ad7a08a.entry.js +2 -0
- package/dist/csc-ui/p-0ad7a08a.entry.js.map +1 -0
- package/dist/csc-ui/p-0bdcbdb4.entry.js +2 -0
- package/dist/csc-ui/p-0bdcbdb4.entry.js.map +1 -0
- package/dist/csc-ui/p-15830fd5.entry.js +2 -0
- package/dist/csc-ui/p-15830fd5.entry.js.map +1 -0
- package/dist/csc-ui/{p-ed924115.entry.js → p-1b131625.entry.js} +2 -2
- package/dist/csc-ui/{p-6a6a89ef.entry.js → p-512ab32d.entry.js} +2 -2
- package/dist/csc-ui/{p-ddff8326.entry.js → p-61b96bb4.entry.js} +2 -2
- package/dist/csc-ui/p-77ee7a57.entry.js +2 -0
- package/dist/csc-ui/p-77ee7a57.entry.js.map +1 -0
- package/dist/csc-ui/{p-a7aa8fcf.entry.js → p-91057659.entry.js} +2 -2
- package/dist/csc-ui/{p-c2767e00.entry.js → p-9b186504.entry.js} +2 -2
- package/dist/csc-ui/{p-49a7a96d.entry.js → p-b483a551.entry.js} +2 -2
- package/dist/csc-ui/{p-aae874cf.entry.js → p-c579ce63.entry.js} +2 -2
- package/dist/csc-ui/{p-1c767310.js → p-f2ecd5ac.js} +1 -1
- package/dist/csc-ui/p-f2ecd5ac.js.map +1 -0
- package/dist/esm/c-accordion-item.entry.js +1 -1
- package/dist/esm/c-alert.entry.js +1 -1
- package/dist/esm/c-autocomplete_34.entry.js +56 -22
- package/dist/esm/c-autocomplete_34.entry.js.map +1 -1
- package/dist/esm/c-data-table.entry.js +1 -1
- package/dist/esm/c-menu_2.entry.js +24 -2
- package/dist/esm/c-menu_2.entry.js.map +1 -1
- package/dist/esm/c-pagination.entry.js +1 -1
- package/dist/esm/c-swiper.entry.js +1 -1
- package/dist/esm/c-tabs.entry.js +1 -1
- package/dist/esm/c-tag.entry.js +4 -2
- package/dist/esm/c-tag.entry.js.map +1 -1
- package/dist/esm/c-tags.entry.js +12 -2
- package/dist/esm/c-tags.entry.js.map +1 -1
- package/dist/esm/c-toast.entry.js +1 -1
- package/dist/esm/csc-ui.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{mdi-e10c3ab4.js → mdi-b4859722.js} +21 -21
- package/dist/esm/mdi-b4859722.js.map +1 -0
- package/dist/types/components/c-dropdown/c-dropdown.d.ts +3 -1
- package/dist/types/components/c-otp-input/c-otp-input.d.ts +5 -1
- package/dist/types/components/c-tag/c-tag.d.ts +1 -0
- package/dist/types/components/c-tags/c-tags.d.ts +3 -0
- package/dist/types/components.d.ts +29 -1
- package/loader/index.d.ts +10 -2
- package/loader/package.json +2 -1
- package/package.json +1 -1
- package/vscode-data.json +30 -1
- package/dist/cjs/getScrollParent-5d488045.js +0 -28
- package/dist/cjs/getScrollParent-5d488045.js.map +0 -1
- package/dist/cjs/mdi-16842afc.js.map +0 -1
- package/dist/components/getScrollParent.js +0 -26
- package/dist/components/getScrollParent.js.map +0 -1
- package/dist/csc-ui/p-1c767310.js.map +0 -1
- package/dist/csc-ui/p-3f0e51ff.js +0 -2
- package/dist/csc-ui/p-3f0e51ff.js.map +0 -1
- package/dist/csc-ui/p-7f97a326.entry.js +0 -2
- package/dist/csc-ui/p-7f97a326.entry.js.map +0 -1
- package/dist/csc-ui/p-c28fe9f0.entry.js +0 -2
- package/dist/csc-ui/p-c28fe9f0.entry.js.map +0 -1
- package/dist/csc-ui/p-dd714111.entry.js +0 -2
- package/dist/csc-ui/p-dd714111.entry.js.map +0 -1
- package/dist/csc-ui/p-fc47b970.entry.js +0 -2
- package/dist/csc-ui/p-fc47b970.entry.js.map +0 -1
- package/dist/esm/getScrollParent-f876ad1b.js +0 -26
- package/dist/esm/getScrollParent-f876ad1b.js.map +0 -1
- package/dist/esm/mdi-e10c3ab4.js.map +0 -1
- /package/dist/csc-ui/{p-ed924115.entry.js.map → p-1b131625.entry.js.map} +0 -0
- /package/dist/csc-ui/{p-6a6a89ef.entry.js.map → p-512ab32d.entry.js.map} +0 -0
- /package/dist/csc-ui/{p-ddff8326.entry.js.map → p-61b96bb4.entry.js.map} +0 -0
- /package/dist/csc-ui/{p-a7aa8fcf.entry.js.map → p-91057659.entry.js.map} +0 -0
- /package/dist/csc-ui/{p-c2767e00.entry.js.map → p-9b186504.entry.js.map} +0 -0
- /package/dist/csc-ui/{p-49a7a96d.entry.js.map → p-b483a551.entry.js.map} +0 -0
- /package/dist/csc-ui/{p-aae874cf.entry.js.map → p-c579ce63.entry.js.map} +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { mdiAlert, mdiInformation } from "@mdi/js";
|
|
2
2
|
import { Host, h, } from "@stencil/core";
|
|
3
|
-
import { getScrollParent } from "../../utils";
|
|
4
3
|
export class CDropdown {
|
|
5
4
|
constructor() {
|
|
6
5
|
this._debounce = null;
|
|
@@ -30,10 +29,17 @@ export class CDropdown {
|
|
|
30
29
|
});
|
|
31
30
|
}
|
|
32
31
|
async stateWatcher(isOpen) {
|
|
33
|
-
|
|
32
|
+
this._originalOverflowValue =
|
|
33
|
+
this._originalOverflowValue ||
|
|
34
|
+
window.getComputedStyle(document.body).overflow;
|
|
35
|
+
if (isOpen) {
|
|
34
36
|
this._handleOpen();
|
|
37
|
+
this._disableScroll();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this._enableScroll();
|
|
41
|
+
}
|
|
35
42
|
this.dropdownStateChange.emit(isOpen);
|
|
36
|
-
this._scrollParent = this._scrollParent || (await getScrollParent(this.el));
|
|
37
43
|
}
|
|
38
44
|
handleIndexChange(index) {
|
|
39
45
|
requestAnimationFrame(() => {
|
|
@@ -82,6 +88,17 @@ export class CDropdown {
|
|
|
82
88
|
this._isOpening = false;
|
|
83
89
|
}, 500);
|
|
84
90
|
}
|
|
91
|
+
_disableScroll() {
|
|
92
|
+
document.body.style.overflow = 'hidden';
|
|
93
|
+
}
|
|
94
|
+
_enableScroll() {
|
|
95
|
+
if (this._originalOverflowValue &&
|
|
96
|
+
this._originalOverflowValue !== 'visible') {
|
|
97
|
+
document.body.style.overflow = this._originalOverflowValue;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
document.body.style.removeProperty('overflow');
|
|
101
|
+
}
|
|
85
102
|
componentDidLoad() {
|
|
86
103
|
this._setIsMobile();
|
|
87
104
|
this._hideDetails = this.parent.hideDetails;
|
|
@@ -549,7 +566,7 @@ export class CDropdown {
|
|
|
549
566
|
"return": "Promise<void>"
|
|
550
567
|
},
|
|
551
568
|
"docs": {
|
|
552
|
-
"text": "
|
|
569
|
+
"text": "Close dropdown",
|
|
553
570
|
"tags": []
|
|
554
571
|
}
|
|
555
572
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"c-dropdown.js","sourceRoot":"","sources":["../../../../src/components/c-dropdown/c-dropdown.tsx"],"names":[],"mappings":"AAAA,OAA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AM,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,EACtD,QAAQ,EAAC,IAAI,IAEZ,IAAI,CAAC,YAAY,CACf;UAEL,WACE,KAAK,EAAE;cACL,MAAM,EAAE,IAAI,CAAC,YAAY;cACzB,sBAAsB,EAAE,IAAI;aAC7B;YAED,YAAM,IAAI,EAAC,cAAc,GAAQ,CAC7B,CACF,CACC,CACJ,CACR,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { mdiAlert, mdiInformation } from '@mdi/js';\nimport {\n Component,\n Host,\n Prop,\n h,\n Element,\n Method,\n Watch,\n Event,\n EventEmitter,\n State,\n} from '@stencil/core';\nimport { CAutocompleteItem, CSelectItem } from '../../types';\nimport { getScrollParent } from '../../utils';\n\n@Component({\n tag: 'c-dropdown',\n styleUrl: 'c-dropdown.scss',\n shadow: true,\n})\nexport class CDropdown {\n @Element() el: HTMLCDropdownElement;\n\n /**\n * Items per page before adding scroll\n */\n @Prop() itemsPerPage: number;\n\n /**\n * Dropdown parent\n */\n @Prop() parent: HTMLCSelectElement | HTMLCAutocompleteElement;\n\n /**\n * Dropdown options\n */\n @Prop() items:\n | NodeListOf<HTMLCOptionElement>\n | CAutocompleteItem[]\n | CSelectItem[];\n\n /**\n * Current index value\n */\n @Prop() index: number;\n\n /**\n * Id of the element\n */\n @Prop({ attribute: 'id' }) hostId: string;\n\n /**\n * Triggered when option is selected\n */\n @Event() selectOption: EventEmitter;\n\n /**\n * Type of the parent element\n */\n @Prop() type: 'select' | 'autocomplete';\n\n /**\n * Type of items\n */\n @Prop() itemType: 'option' | 'item';\n\n /**\n * Triggered when dropdown opens or closes\n */\n @Event() dropdownStateChange: EventEmitter<boolean>;\n\n /**\n * Dropdown dialog element\n */\n private _dialog: HTMLDialogElement;\n\n private _debounce = null;\n\n private _list: HTMLUListElement;\n\n private _outsideClickFn: () => void;\n\n private _resizeObserver: ResizeObserver;\n\n private _inputElement: HTMLCInputElement;\n\n private _dummyElement: HTMLDivElement;\n\n private _scrollParent: HTMLElement;\n\n private _isMobile = false;\n\n private _listItems: HTMLLIElement[] = [];\n\n @State() renderedList = null;\n\n @State() isOpen = false;\n\n @State() statusText = '';\n\n @Watch('items')\n optionsWatcher() {\n requestAnimationFrame(() => {\n this.renderedList = this._renderList();\n });\n }\n\n @Watch('isOpen')\n async stateWatcher(isOpen) {\n if (isOpen) this._handleOpen();\n\n this.dropdownStateChange.emit(isOpen);\n\n this._scrollParent = this._scrollParent || (await getScrollParent(this.el));\n }\n\n @Watch('index')\n handleIndexChange(index) {\n requestAnimationFrame(() => {\n this._updateStatusText();\n\n this._listItems[index]?.focus();\n });\n }\n\n /**\n * @private\n */\n @Method()\n async setStatusText(text: string) {\n requestAnimationFrame(() => {\n this.statusText = text;\n });\n }\n\n /**\n * @private\n */\n @Method()\n async focusItem(index: number) {\n requestAnimationFrame(() => {\n this._listItems[index]?.focus();\n });\n }\n\n /**\n * Open dropdown\n */\n @Method()\n async open() {\n if (this._dialog.open) return;\n\n this._outsideClickFn = this._handleOutsideClick.bind(this);\n\n this._dialog.addEventListener('click', this._outsideClickFn);\n\n requestAnimationFrame(() => {\n this.isOpen = true;\n\n this._positionMenu();\n });\n }\n\n /**\n * Open dropdown\n */\n @Method()\n async close() {\n this._dialog.close();\n\n this.isOpen = false;\n\n this._inputElement.slot = 'default';\n\n this._inputElement.hideDetails = this._hideDetails;\n\n this._dummyElement.style.width = '0';\n this._dummyElement.style.display = 'none';\n this._dialog.style.width = '0';\n\n window.removeEventListener('click', this._outsideClickFn);\n }\n\n private _setIsMobile() {\n this._isMobile = window.matchMedia(\n 'only screen and (max-width: 760px)',\n ).matches;\n }\n\n private _isOpening = false;\n\n private _handleOpen() {\n this._isOpening = true;\n\n setTimeout(() => {\n this._isOpening = false;\n }, 500);\n }\n\n componentDidLoad() {\n this._setIsMobile();\n\n this._hideDetails = this.parent.hideDetails;\n\n this._inputElement = this.el.querySelector('c-input');\n\n this._resizeObserver = new ResizeObserver((entries) => {\n if (!this._dialog.open) return;\n\n requestAnimationFrame(() => {\n if (!Array.isArray(entries) || !entries.length || this._isOpening)\n return;\n\n this._setIsMobile();\n\n this.close();\n });\n });\n\n this._resizeObserver.observe(window.document.body);\n\n requestAnimationFrame(() => {\n this.renderedList = this._renderList();\n });\n }\n\n /**\n * Select item\n * @returns the disabled status of the input\n */\n @Method()\n async selectItem(index: number) {\n const item = this._listItems[index];\n\n if (item.classList.contains('disabled')) {\n return true;\n }\n\n this._listItems[index].click();\n\n return false;\n }\n\n /**\n * Update list items\n */\n @Method()\n async updateList() {\n requestAnimationFrame(() => {\n this.renderedList = this._renderList();\n });\n }\n\n private _handleOutsideClick() {\n if (!this.isOpen) return;\n\n this.close();\n }\n\n private _inputSize = {\n height: 0,\n width: 0,\n };\n\n private _openedOnTop = false;\n\n private _hideDetails = false;\n\n private _highlightMatchingText(value: string) {\n const { query } = this.parent as HTMLCAutocompleteElement;\n\n if (this.parent.tagName === 'C-SELECT' || query === '') return value;\n\n const regex = new RegExp(query, 'gi');\n\n const highlighted = value\n .replace(/(<([^>]+)>)/gi, '')\n .replace(regex, (match) => `<mark>${match}</mark>`);\n\n return highlighted;\n }\n\n private _getParentPosition() {\n return this.parent.shadowRoot\n .querySelector('.c-input__slot')\n .getBoundingClientRect();\n }\n\n private _positionMenu() {\n const { innerWidth, innerHeight } = window;\n\n this._dialog.style.width = 'auto';\n this._dialog.style.opacity = '0';\n\n this._dialog.showModal();\n\n requestAnimationFrame(() => {\n let inputSlot = 'input-top';\n\n const { top: parentTop, width } = this._getParentPosition();\n\n const inputSize = this.el.getBoundingClientRect();\n\n this._inputSize = {\n height: inputSize.height,\n width: inputSize.width,\n };\n\n if (!this._isMobile) {\n this._dialog.style.width = `${width}px`;\n this._dialog.style.top = `${inputSize.top}px`;\n this._dialog.style.bottom = 'auto';\n this._dialog.style.left = `${inputSize.left}px`;\n\n const { bottom, right, height } = this._dialog.getBoundingClientRect();\n\n const isInView = {\n x: right < innerWidth,\n y: bottom < innerHeight,\n };\n\n const fitsOnTop = parentTop - height > 0;\n\n if (!fitsOnTop && !isInView.y) {\n this._dialog.style.maxHeight = `${parentTop}px`;\n }\n\n if (!isInView.y || this._openedOnTop) {\n this._openedOnTop = true;\n\n this._inputElement.hideDetails = true;\n inputSlot = 'input-bottom';\n\n this._dialog.style.top = 'auto';\n this._dialog.style.bottom = `${innerHeight - inputSize.top - 44}px`;\n }\n }\n\n this._dummyElement.style.width = `${this._getParentPosition().width}px`;\n this._dummyElement.style.height = `${this._inputSize.height}px`;\n this._dummyElement.style.display = 'block';\n this._dummyElement.slot = 'default';\n\n this._inputElement.slot = inputSlot;\n\n this._inputElement.hideDetails = true;\n\n this._dialog.style.opacity = '1';\n\n const input = this.parent.shadowRoot.querySelector('input');\n\n input.focus();\n });\n }\n\n private _minimumQueryItem() {\n const { query, loading, minimumQueryLength, minimumQueryLengthMessage } =\n this.parent as HTMLCAutocompleteElement;\n\n if (query.length > minimumQueryLength || loading) return;\n\n return (\n <li>\n <c-icon\n path={mdiInformation}\n size={18}\n color=\"var(--c-info-600)\"\n ></c-icon>\n {minimumQueryLengthMessage.replace(\n '{n}',\n minimumQueryLength.toString(),\n )}\n </li>\n );\n }\n\n private _emptyItem() {\n const { query, loading, noMatchingItemsMessage } = this\n .parent as HTMLCAutocompleteElement;\n\n if (!query || loading) return;\n\n return (\n <li>\n <c-icon path={mdiAlert} size={18} color=\"var(--c-warning-600)\"></c-icon>\n {noMatchingItemsMessage}\n </li>\n );\n }\n\n private _renderList() {\n return this.itemType === 'option'\n ? this._renderOptionsList()\n : this._renderItemsList();\n }\n\n private _renderOptionsList() {\n if (!this.items.length)\n return this._minimumQueryItem() || this._emptyItem();\n\n const options = Array.from(this.items) as HTMLCOptionElement[];\n\n this._listItems.length = 0;\n\n return options.map((option, index) => {\n const optionValue = option.querySelector('c-option-value');\n\n if (optionValue) {\n optionValue.innerHTML = this._highlightMatchingText(\n optionValue.textContent,\n );\n }\n\n return (\n <li\n ref={(el) => this._listItems.push(el)}\n id={`${this.hostId}-option-${option.value}`}\n tabindex=\"-1\"\n role=\"option\"\n aria-set-size={this.items.length.toString()}\n aria-pos-in-set={(index + 1).toString()}\n aria-selected={(!!option.selected).toString()}\n class={{ disabled: !!option.disabled }}\n data-name={option.name}\n onClick={(event) => {\n if (option.disabled) {\n event.preventDefault();\n\n return;\n }\n\n this.selectOption.emit({ name: option.name, value: option.value });\n }}\n innerHTML={option.outerHTML}\n ></li>\n );\n });\n }\n\n private _renderItemsList() {\n if (!this.items.length)\n return this._minimumQueryItem() || this._emptyItem();\n\n this._listItems.length = 0;\n\n return (this.items as unknown as CAutocompleteItem[]).map((item, index) => {\n return (\n <li\n ref={(el) => this._listItems.push(el)}\n id={`${this.hostId}-option-${item.value}`}\n tabindex=\"-1\"\n role=\"option\"\n aria-set-size={this.items.length.toString()}\n aria-pos-in-set={(index + 1).toString()}\n aria-selected={(this.index === index).toString()}\n class={{ disabled: !!item.disabled }}\n data-name={item.name}\n onClick={(event) => {\n if (item.disabled) {\n event.preventDefault();\n\n return;\n }\n\n this.selectOption.emit({ name: item.name, value: item.value });\n }}\n >\n <span innerHTML={this._highlightMatchingText(item.name)}></span>\n </li>\n );\n });\n }\n\n private _updateStatusText() {\n if (this._debounce !== null) {\n clearTimeout(this._debounce);\n this._debounce = null;\n }\n\n this._debounce = window.setTimeout(() => {\n const selection = this._listItems[this.index];\n\n const ending = !!this.items.length\n ? ', to navigate use up and down arrows'\n : '';\n\n const total = this._listItems.length;\n\n const position = this.index + 1;\n\n const isDisabled = !!selection?.classList?.contains('disabled');\n\n const beginning = isDisabled ? 'Disabled option - ' : '';\n\n let selectionText = !!selection\n ? `${beginning}${selection.dataset.name} - ${position} of ${total} is highlighted`\n : null;\n\n if (this.index === null && this.type === 'autocomplete') {\n selectionText = this.items.length\n ? `${this.items.length} result${\n this.items.length !== 1 ? 's' : ''\n } available`\n : 'No search results available';\n }\n\n this.statusText = `${selectionText || ending}`;\n\n this._debounce = null;\n }, 1400);\n }\n\n render() {\n if (\n !this._isMobile &&\n this._dialog &&\n this.itemsPerPage &&\n this.itemsPerPage > 0 &&\n this.items.length > this.itemsPerPage\n ) {\n this._dialog.style.maxHeight = 42 * (this.itemsPerPage + 0.5) + 60 + 'px';\n this._list.style.maxHeight = 42 * (this.itemsPerPage + 0.5) + 'px';\n }\n\n return (\n <Host>\n <slot name=\"default\"></slot>\n\n <div class=\"dummy\" ref={(el) => (this._dummyElement = el)}></div>\n\n <dialog\n tabindex=\"-1\"\n ref={(el) => (this._dialog = el)}\n class={{ mobile: this._isMobile }}\n onCancel={() => this.close()}\n >\n <div onClick={(event) => event.stopPropagation()}>\n <div\n id={'announce-' + this.hostId}\n class=\"visuallyhidden\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {this.statusText}\n </div>\n\n <div class=\"input-top-wrapper\">\n <slot name=\"input-top\"></slot>\n </div>\n\n <ul\n ref={(el) => (this._list = el)}\n id={`${this.hostId}--results`}\n role=\"listbox\"\n aria-expanded={this.isOpen.toString()}\n class={{ active: this.isOpen, mobile: this._isMobile }}\n tabindex=\"-1\"\n >\n {this.renderedList}\n </ul>\n\n <div\n class={{\n active: this._openedOnTop,\n 'input-bottom-wrapper': true,\n }}\n >\n <slot name=\"input-bottom\"></slot>\n </div>\n </div>\n </dialog>\n </Host>\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,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,\n Prop,\n h,\n Element,\n Method,\n Watch,\n Event,\n EventEmitter,\n State,\n} from '@stencil/core';\nimport { CAutocompleteItem, CSelectItem } from '../../types';\n\n@Component({\n tag: 'c-dropdown',\n styleUrl: 'c-dropdown.scss',\n shadow: true,\n})\nexport class CDropdown {\n @Element() el: HTMLCDropdownElement;\n\n /**\n * Items per page before adding scroll\n */\n @Prop() itemsPerPage: number;\n\n /**\n * Dropdown parent\n */\n @Prop() parent: HTMLCSelectElement | HTMLCAutocompleteElement;\n\n /**\n * Dropdown options\n */\n @Prop() items:\n | NodeListOf<HTMLCOptionElement>\n | CAutocompleteItem[]\n | CSelectItem[];\n\n /**\n * Current index value\n */\n @Prop() index: number;\n\n /**\n * Id of the element\n */\n @Prop({ attribute: 'id' }) hostId: string;\n\n /**\n * Triggered when option is selected\n */\n @Event() selectOption: EventEmitter;\n\n /**\n * Type of the parent element\n */\n @Prop() type: 'select' | 'autocomplete';\n\n /**\n * Type of items\n */\n @Prop() itemType: 'option' | 'item';\n\n /**\n * Triggered when dropdown opens or closes\n */\n @Event() dropdownStateChange: EventEmitter<boolean>;\n\n /**\n * Dropdown dialog element\n */\n private _dialog: HTMLDialogElement;\n\n private _debounce = null;\n\n private _list: HTMLUListElement;\n\n private _outsideClickFn: () => void;\n\n private _resizeObserver: ResizeObserver;\n\n private _inputElement: HTMLCInputElement;\n\n private _dummyElement: HTMLDivElement;\n\n private _isMobile = false;\n\n private _listItems: HTMLLIElement[] = [];\n\n private _originalOverflowValue: string;\n\n @State() renderedList = null;\n\n @State() isOpen = false;\n\n @State() statusText = '';\n\n @Watch('items')\n optionsWatcher() {\n requestAnimationFrame(() => {\n this.renderedList = this._renderList();\n });\n }\n\n @Watch('isOpen')\n async stateWatcher(isOpen) {\n this._originalOverflowValue =\n this._originalOverflowValue ||\n window.getComputedStyle(document.body).overflow;\n\n if (isOpen) {\n this._handleOpen();\n this._disableScroll();\n } else {\n this._enableScroll();\n }\n\n this.dropdownStateChange.emit(isOpen);\n }\n\n @Watch('index')\n handleIndexChange(index) {\n requestAnimationFrame(() => {\n this._updateStatusText();\n\n this._listItems[index]?.focus();\n });\n }\n\n /**\n * @private\n */\n @Method()\n async setStatusText(text: string) {\n requestAnimationFrame(() => {\n this.statusText = text;\n });\n }\n\n /**\n * @private\n */\n @Method()\n async focusItem(index: number) {\n requestAnimationFrame(() => {\n this._listItems[index]?.focus();\n });\n }\n\n /**\n * Open dropdown\n */\n @Method()\n async open() {\n if (this._dialog.open) return;\n\n this._outsideClickFn = this._handleOutsideClick.bind(this);\n\n this._dialog.addEventListener('click', this._outsideClickFn);\n\n requestAnimationFrame(() => {\n this.isOpen = true;\n\n this._positionMenu();\n });\n }\n\n /**\n * Close dropdown\n */\n @Method()\n async close() {\n this._dialog.close();\n\n this.isOpen = false;\n\n this._inputElement.slot = 'default';\n\n this._inputElement.hideDetails = this._hideDetails;\n\n this._dummyElement.style.width = '0';\n this._dummyElement.style.display = 'none';\n this._dialog.style.width = '0';\n\n window.removeEventListener('click', this._outsideClickFn);\n }\n\n private _setIsMobile() {\n this._isMobile = window.matchMedia(\n 'only screen and (max-width: 760px)',\n ).matches;\n }\n\n private _isOpening = false;\n\n private _handleOpen() {\n this._isOpening = true;\n\n setTimeout(() => {\n this._isOpening = false;\n }, 500);\n }\n\n private _disableScroll() {\n document.body.style.overflow = 'hidden';\n }\n\n private _enableScroll() {\n if (\n this._originalOverflowValue &&\n this._originalOverflowValue !== 'visible'\n ) {\n document.body.style.overflow = this._originalOverflowValue;\n\n return;\n }\n\n document.body.style.removeProperty('overflow');\n }\n\n componentDidLoad() {\n this._setIsMobile();\n\n this._hideDetails = this.parent.hideDetails;\n\n this._inputElement = this.el.querySelector('c-input');\n\n this._resizeObserver = new ResizeObserver((entries) => {\n if (!this._dialog.open) return;\n\n requestAnimationFrame(() => {\n if (!Array.isArray(entries) || !entries.length || this._isOpening)\n return;\n\n this._setIsMobile();\n\n this.close();\n });\n });\n\n this._resizeObserver.observe(window.document.body);\n\n requestAnimationFrame(() => {\n this.renderedList = this._renderList();\n });\n }\n\n /**\n * Select item\n * @returns the disabled status of the input\n */\n @Method()\n async selectItem(index: number) {\n const item = this._listItems[index];\n\n if (item.classList.contains('disabled')) {\n return true;\n }\n\n this._listItems[index].click();\n\n return false;\n }\n\n /**\n * Update list items\n */\n @Method()\n async updateList() {\n requestAnimationFrame(() => {\n this.renderedList = this._renderList();\n });\n }\n\n private _handleOutsideClick() {\n if (!this.isOpen) return;\n\n this.close();\n }\n\n private _inputSize = {\n height: 0,\n width: 0,\n };\n\n private _openedOnTop = false;\n\n private _hideDetails = false;\n\n private _highlightMatchingText(value: string) {\n const { query } = this.parent as HTMLCAutocompleteElement;\n\n if (this.parent.tagName === 'C-SELECT' || query === '') return value;\n\n const regex = new RegExp(query, 'gi');\n\n const highlighted = value\n .replace(/(<([^>]+)>)/gi, '')\n .replace(regex, (match) => `<mark>${match}</mark>`);\n\n return highlighted;\n }\n\n private _getParentPosition() {\n return this.parent.shadowRoot\n .querySelector('.c-input__slot')\n .getBoundingClientRect();\n }\n\n private _positionMenu() {\n const { innerWidth, innerHeight } = window;\n\n this._dialog.style.width = 'auto';\n this._dialog.style.opacity = '0';\n\n this._dialog.showModal();\n\n requestAnimationFrame(() => {\n let inputSlot = 'input-top';\n\n const { top: parentTop, width } = this._getParentPosition();\n\n const inputSize = this.el.getBoundingClientRect();\n\n this._inputSize = {\n height: inputSize.height,\n width: inputSize.width,\n };\n\n if (!this._isMobile) {\n this._dialog.style.width = `${width}px`;\n this._dialog.style.top = `${inputSize.top}px`;\n this._dialog.style.bottom = 'auto';\n this._dialog.style.left = `${inputSize.left}px`;\n\n const { bottom, right, height } = this._dialog.getBoundingClientRect();\n\n const isInView = {\n x: right < innerWidth,\n y: bottom < innerHeight,\n };\n\n const fitsOnTop = parentTop - height > 0;\n\n if (!fitsOnTop && !isInView.y) {\n this._dialog.style.maxHeight = `${parentTop}px`;\n }\n\n if (!isInView.y || this._openedOnTop) {\n this._openedOnTop = true;\n\n this._inputElement.hideDetails = true;\n inputSlot = 'input-bottom';\n\n this._dialog.style.top = 'auto';\n this._dialog.style.bottom = `${innerHeight - inputSize.top - 44}px`;\n }\n }\n\n this._dummyElement.style.width = `${this._getParentPosition().width}px`;\n this._dummyElement.style.height = `${this._inputSize.height}px`;\n this._dummyElement.style.display = 'block';\n this._dummyElement.slot = 'default';\n\n this._inputElement.slot = inputSlot;\n\n this._inputElement.hideDetails = true;\n\n this._dialog.style.opacity = '1';\n\n const input = this.parent.shadowRoot.querySelector('input');\n\n input.focus();\n });\n }\n\n private _minimumQueryItem() {\n const { query, loading, minimumQueryLength, minimumQueryLengthMessage } =\n this.parent as HTMLCAutocompleteElement;\n\n if (query.length > minimumQueryLength || loading) return;\n\n return (\n <li>\n <c-icon\n path={mdiInformation}\n size={18}\n color=\"var(--c-info-600)\"\n ></c-icon>\n {minimumQueryLengthMessage.replace(\n '{n}',\n minimumQueryLength.toString(),\n )}\n </li>\n );\n }\n\n private _emptyItem() {\n const { query, loading, noMatchingItemsMessage } = this\n .parent as HTMLCAutocompleteElement;\n\n if (!query || loading) return;\n\n return (\n <li>\n <c-icon path={mdiAlert} size={18} color=\"var(--c-warning-600)\"></c-icon>\n {noMatchingItemsMessage}\n </li>\n );\n }\n\n private _renderList() {\n return this.itemType === 'option'\n ? this._renderOptionsList()\n : this._renderItemsList();\n }\n\n private _renderOptionsList() {\n if (!this.items.length)\n return this._minimumQueryItem() || this._emptyItem();\n\n const options = Array.from(this.items) as HTMLCOptionElement[];\n\n this._listItems.length = 0;\n\n return options.map((option, index) => {\n const optionValue = option.querySelector('c-option-value');\n\n if (optionValue) {\n optionValue.innerHTML = this._highlightMatchingText(\n optionValue.textContent,\n );\n }\n\n return (\n <li\n ref={(el) => this._listItems.push(el)}\n id={`${this.hostId}-option-${option.value}`}\n tabindex=\"-1\"\n role=\"option\"\n aria-set-size={this.items.length.toString()}\n aria-pos-in-set={(index + 1).toString()}\n aria-selected={(!!option.selected).toString()}\n class={{ disabled: !!option.disabled }}\n data-name={option.name}\n onClick={(event) => {\n if (option.disabled) {\n event.preventDefault();\n\n return;\n }\n\n this.selectOption.emit({ name: option.name, value: option.value });\n }}\n innerHTML={option.outerHTML}\n ></li>\n );\n });\n }\n\n private _renderItemsList() {\n if (!this.items.length)\n return this._minimumQueryItem() || this._emptyItem();\n\n this._listItems.length = 0;\n\n return (this.items as unknown as CAutocompleteItem[]).map((item, index) => {\n return (\n <li\n ref={(el) => this._listItems.push(el)}\n id={`${this.hostId}-option-${item.value}`}\n tabindex=\"-1\"\n role=\"option\"\n aria-set-size={this.items.length.toString()}\n aria-pos-in-set={(index + 1).toString()}\n aria-selected={(this.index === index).toString()}\n class={{ disabled: !!item.disabled }}\n data-name={item.name}\n onClick={(event) => {\n if (item.disabled) {\n event.preventDefault();\n\n return;\n }\n\n this.selectOption.emit({ name: item.name, value: item.value });\n }}\n >\n <span innerHTML={this._highlightMatchingText(item.name)}></span>\n </li>\n );\n });\n }\n\n private _updateStatusText() {\n if (this._debounce !== null) {\n clearTimeout(this._debounce);\n this._debounce = null;\n }\n\n this._debounce = window.setTimeout(() => {\n const selection = this._listItems[this.index];\n\n const ending = !!this.items.length\n ? ', to navigate use up and down arrows'\n : '';\n\n const total = this._listItems.length;\n\n const position = this.index + 1;\n\n const isDisabled = !!selection?.classList?.contains('disabled');\n\n const beginning = isDisabled ? 'Disabled option - ' : '';\n\n let selectionText = !!selection\n ? `${beginning}${selection.dataset.name} - ${position} of ${total} is highlighted`\n : null;\n\n if (this.index === null && this.type === 'autocomplete') {\n selectionText = this.items.length\n ? `${this.items.length} result${\n this.items.length !== 1 ? 's' : ''\n } available`\n : 'No search results available';\n }\n\n this.statusText = `${selectionText || ending}`;\n\n this._debounce = null;\n }, 1400);\n }\n\n render() {\n if (\n !this._isMobile &&\n this._dialog &&\n this.itemsPerPage &&\n this.itemsPerPage > 0 &&\n this.items.length > this.itemsPerPage\n ) {\n this._dialog.style.maxHeight = 42 * (this.itemsPerPage + 0.5) + 60 + 'px';\n this._list.style.maxHeight = 42 * (this.itemsPerPage + 0.5) + 'px';\n }\n\n return (\n <Host>\n <slot name=\"default\"></slot>\n\n <div class=\"dummy\" ref={(el) => (this._dummyElement = el)}></div>\n\n <dialog\n tabindex=\"-1\"\n ref={(el) => (this._dialog = el)}\n class={{ mobile: this._isMobile }}\n onCancel={() => this.close()}\n >\n <div onClick={(event) => event.stopPropagation()}>\n <div\n id={'announce-' + this.hostId}\n class=\"visuallyhidden\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {this.statusText}\n </div>\n\n <div class=\"input-top-wrapper\">\n <slot name=\"input-top\"></slot>\n </div>\n\n <ul\n ref={(el) => (this._list = el)}\n id={`${this.hostId}--results`}\n role=\"listbox\"\n aria-expanded={this.isOpen.toString()}\n class={{ active: this.isOpen, mobile: this._isMobile }}\n tabindex=\"-1\"\n >\n {this.renderedList}\n </ul>\n\n <div\n class={{\n active: this._openedOnTop,\n 'input-bottom-wrapper': true,\n }}\n >\n <slot name=\"input-bottom\"></slot>\n </div>\n </div>\n </dialog>\n </Host>\n );\n }\n}\n"]}
|
|
@@ -13,10 +13,8 @@ export class CInput {
|
|
|
13
13
|
}, { threshold: 1 });
|
|
14
14
|
this._onBlur = () => {
|
|
15
15
|
setTimeout(() => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this._hasBlurred = true;
|
|
19
|
-
}
|
|
16
|
+
this.isFocused = false;
|
|
17
|
+
this._hasBlurred = true;
|
|
20
18
|
this._onReset();
|
|
21
19
|
}, 100);
|
|
22
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"c-input.js","sourceRoot":"","sources":["../../../../src/components/c-input/c-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,IAAI,EACJ,CAAC,EACD,KAAK,EACL,IAAI,EACJ,KAAK,EAEL,OAAO,EACP,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AAWvB,MAAM,O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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import {\n Component,\n Host,\n h,\n State,\n Prop,\n Event,\n EventEmitter,\n Element,\n Watch,\n Method,\n} from '@stencil/core';\nimport { CAutocompleteItem, CSelectItem } from '../../types';\n\n/**\n * @parent None\n */\n@Component({\n tag: 'c-input',\n styleUrl: 'c-input.scss',\n shadow: false,\n})\nexport class CInput {\n @Element() el!: HTMLCInputElement;\n\n /**\n * Active state\n */\n @Prop() active = false;\n\n /**\n * Auto focus the input\n */\n @Prop() autofocus = false;\n\n /**\n * Disable the input\n */\n @Prop() disabled = false;\n\n /**\n * Render a hidden input outside the shadow dom\n */\n @Prop() form = false;\n\n /**\n * Hide the hint and error messages\n */\n @Prop() hideDetails = false;\n\n /**\n * Hint text for the input\n */\n @Prop() hint = '';\n\n /**\n * Id of the input\n */\n @Prop({ attribute: 'id' }) hostId: string;\n\n /**\n * Id of the input element\n */\n @Prop() inputId: string;\n\n /**\n * Items for the dropdown\n */\n @Prop() items: CSelectItem[];\n\n /**\n * Items per page before adding scroll\n */\n @Prop() itemsPerPage = 6;\n\n /**\n * Label of the input\n */\n @Prop() label: string;\n\n /**\n * Maximum value on a numeric input\n */\n @Prop() max: number = null;\n\n /**\n * Minimum value on a numeric input\n */\n @Prop() min: number = null;\n\n /**\n * Name of the input\n */\n @Prop() name: string;\n\n /**\n * Placeholder of the input\n */\n @Prop() placeholder: string;\n\n /**\n * Mark as readonly\n */\n @Prop() readonly = false;\n\n /**\n * Set the input as required\n */\n @Prop() required = false;\n\n /**\n * Rows on the input\n */\n @Prop() rows = 1;\n\n /**\n * Shadow variant of the input\n */\n @Prop() shadow = false;\n\n /**\n * Step size on a numeric input\n */\n @Prop() step: number = null;\n\n /**\n * Type of the input\n */\n @Prop() type: string;\n\n /**\n * Set the validíty of the input\n */\n @Prop() valid = true;\n\n /**\n * Manual validation\n */\n @Prop() validate = false;\n\n /**\n * Validate the input on blur\n */\n @Prop() validateOnBlur = false;\n\n /**\n * Custom validation message\n */\n @Prop() validation = 'Required field';\n\n /**\n * Value of the input\n */\n @Prop() value: string | number | boolean | CSelectItem | CAutocompleteItem;\n\n /**\n * Variant\n */\n @Prop() variant: 'text' | 'select' = 'text';\n\n /**\n * Emit changes to the parent\n */\n @Event({ bubbles: false }) changeValue: EventEmitter;\n\n /**\n * Emit click to the parent\n * @private\n */\n @Event({ bubbles: false }) itemClick: EventEmitter;\n\n /**\n * Emit close to the parent\n * @private\n */\n @Event({ bubbles: false }) dropdownClose: EventEmitter;\n\n @State() isFocused = false;\n\n @State() labelWidth = 0;\n\n @State() preSlotWidth = 0;\n\n @State() statusText = '';\n\n @State() currentIndex: number = null;\n\n @Watch('valid')\n onValidChange() {\n if (this.validateOnBlur && !this._hasBlurred) return;\n\n this._setAriaDescriptionId();\n }\n\n @Watch('validation')\n onValidationMessageChange() {\n this._updateStatusText();\n }\n\n @Watch('value')\n onValueChange(value) {\n if (!value) {\n this._onReset();\n }\n }\n\n @Watch('placeholder')\n onPlaceholderChange(placeholder) {\n if (placeholder) this._onReset();\n }\n\n private _hasBlurred = false;\n\n private _labelRef: HTMLLabelElement;\n\n private _debounce = null;\n\n private _dropdownElement: HTMLCDropdownElement;\n\n /**\n * @private\n */\n @Method()\n async reset() {\n this._onReset();\n }\n\n componentDidLoad() {\n if (this.autofocus) {\n setTimeout(() => {\n this._onFocus(false);\n }, 500);\n }\n\n this._calculateElementWidths();\n this._setAriaDescriptionId();\n\n if (this.label) {\n this._observer.observe(this._labelRef);\n }\n\n this.inputField?.addEventListener('focus', () => this._onFocus(false));\n this.inputField?.addEventListener('blur', () => this._onBlur());\n this.inputField?.addEventListener(\n 'keypress',\n this._preventNonNumericalInput,\n );\n\n // hide the placeholder text initially if there is a label\n if (this.inputField) {\n this.inputField.placeholder =\n !!this.label || !this.placeholder ? '' : this.placeholder;\n\n this.inputField.title = this.label ?? this.placeholder;\n\n requestAnimationFrame(() => {\n const container = this.inputField.closest(\n '.c-input-menu__input',\n ) as HTMLDivElement;\n\n if (!container) return;\n\n container.dataset.placeholder = this.placeholder;\n });\n }\n }\n\n disconnectedCallback() {\n this.inputField?.removeEventListener('focus', () => this._onFocus(false));\n this.inputField?.removeEventListener('blur', () => this._onBlur());\n this.inputField?.removeEventListener(\n 'keypress',\n this._preventNonNumericalInput,\n );\n\n this._observer.disconnect();\n\n this._dropdownElement?.remove();\n }\n\n get isActive() {\n return !!this.value || typeof this.value === 'boolean' || this.isFocused;\n }\n\n private _setAriaDescriptionId() {\n this.inputField.removeAttribute('aria-describedby');\n\n let type = null;\n\n if (this.valid && !this.value && this.hint) {\n type = 'hint';\n }\n\n if (!this.valid) {\n type = 'error';\n }\n\n if (type) {\n this.inputField.setAttribute(\n 'aria-describedby',\n `${type}-${this.inputId}`,\n );\n }\n }\n\n private _observer = new IntersectionObserver(\n (entries, observer) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n this._calculateElementWidths();\n observer.unobserve(entry.target);\n }\n });\n },\n { threshold: 1 },\n );\n\n private _calculateElementWidths() {\n this.labelWidth = !!this.label ? this._labelRef.scrollWidth * 0.75 + 6 : 0;\n this.preSlotWidth = this.inputField.offsetLeft;\n }\n\n private _onBlur = () => {\n // delay the blur event to prevent the label from 'flashing' on c-select selection\n setTimeout(() => {\n if (!this.active) {\n this.isFocused = false;\n this._hasBlurred = true;\n }\n\n // show the label if there's no label or value\n this._onReset();\n }, 100);\n };\n\n private _onFocus = (click = true) => {\n if (this.disabled) return;\n\n this.isFocused = true;\n\n this.inputField?.focus();\n\n if (click) {\n this.inputField?.click();\n\n if (this.variant === 'select') {\n this.itemClick.emit();\n }\n }\n\n // show the label if there's no value\n if (this.inputField) {\n this.inputField.placeholder =\n !!this.value || !this.placeholder ? '' : this.placeholder;\n }\n };\n\n private _onReset() {\n if (this.inputField) {\n if (\n !!this.placeholder &&\n !this.value &&\n (this.active || this.isFocused)\n ) {\n this.inputField.placeholder = this.placeholder;\n\n return;\n }\n\n this.inputField.placeholder =\n !this.label && !this.value && !!this.placeholder\n ? this.placeholder\n : '';\n }\n }\n\n /**\n * Prevent non numeric values in the numeric fields\n */\n private _preventNonNumericalInput(event: KeyboardEvent) {\n if (this.type !== 'number') return;\n\n if (!event.key.match(/^[0-9,\\.-]+$/)) {\n event.preventDefault();\n }\n }\n\n private _renderBorders() {\n if (this.shadow) return;\n\n const classes = {\n active: this.isActive || this.active,\n };\n\n return (\n <fieldset aria-hidden=\"true\">\n <legend\n class={classes}\n style={{\n '--_c-input-legend-width': this.labelWidth + 'px',\n }}\n >\n <span class=\"notranslate\"></span>\n </legend>\n </fieldset>\n );\n }\n\n private _renderLabel() {\n if (!this.label) return;\n\n const classes = {\n active: this.isActive,\n };\n\n return (\n <label\n htmlFor={this.inputId}\n ref={(el) => (this._labelRef = el as HTMLLabelElement)}\n class={classes}\n >\n {this.label}\n {this.required && <span> *</span>}\n </label>\n );\n }\n\n get inputField() {\n return this.el?.querySelector('.c-input__input') as\n | HTMLInputElement\n | HTMLTextAreaElement;\n }\n\n private _updateStatusText() {\n if (this._debounce !== null) {\n clearTimeout(this._debounce);\n this._debounce = null;\n }\n\n this._debounce = window.setTimeout(() => {\n this.statusText = this.valid ? '' : `Error: ${this.validation}`;\n\n this._debounce = null;\n }, 1400);\n }\n\n render() {\n const containerClasses = {\n 'c-input': true,\n 'c-input--disabled': this.disabled,\n 'c-input--shadow': this.shadow,\n 'c-input--textarea': this.rows > 1,\n 'c-input--error': !this.valid,\n 'c-input--active': this.isFocused || this.active,\n filled: !!this.value,\n [`c-input--${this.variant}`]: true,\n };\n\n return (\n <Host disabled={this.disabled}>\n <div\n id={'announce-' + this.inputId}\n class=\"visuallyhidden\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {this.statusText}\n </div>\n\n <div class={containerClasses}>\n <div class=\"c-input__control\">\n <div class=\"c-input__slot\" onClick={() => this._onFocus()}>\n {this._renderBorders()}\n\n <div\n class=\"c-input__field\"\n style={{\n '--_c-input-label-position': this.preSlotWidth + 'px',\n }}\n >\n <slot name=\"pre\"></slot>\n\n {this._renderLabel()}\n\n <slot></slot>\n </div>\n </div>\n\n {this.variant === 'select' && <slot name=\"dropdown\"></slot>}\n\n {!this.hideDetails && (\n <c-message\n hint={this.hint}\n inputId={this.inputId}\n valid={this.valid}\n validation={this.validation}\n />\n )}\n </div>\n </div>\n </Host>\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"c-input.js","sourceRoot":"","sources":["../../../../src/components/c-input/c-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,IAAI,EACJ,CAAC,EACD,KAAK,EACL,IAAI,EACJ,KAAK,EAEL,OAAO,EACP,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AAWvB,MAAM,OAAO,MAAM;;IA6LT,gBAAW,GAAG,KAAK,CAAC;IAIpB,cAAS,GAAG,IAAI,CAAC;IA0FjB,cAAS,GAAG,IAAI,oBAAoB,CAC1C,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;MACpB,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACxB,IAAI,KAAK,CAAC,cAAc,EAAE;UACxB,IAAI,CAAC,uBAAuB,EAAE,CAAC;UAC/B,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;SAClC;MACH,CAAC,CAAC,CAAC;IACL,CAAC,EACD,EAAE,SAAS,EAAE,CAAC,EAAE,CACjB,CAAC;IAOM,YAAO,GAAG,GAAG,EAAE;MAErB,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QAEvB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAGxB,IAAI,CAAC,QAAQ,EAAE,CAAC;MAClB,CA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C;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import {\n Component,\n Host,\n h,\n State,\n Prop,\n Event,\n EventEmitter,\n Element,\n Watch,\n Method,\n} from '@stencil/core';\nimport { CAutocompleteItem, CSelectItem } from '../../types';\n\n/**\n * @parent None\n */\n@Component({\n tag: 'c-input',\n styleUrl: 'c-input.scss',\n shadow: false,\n})\nexport class CInput {\n @Element() el!: HTMLCInputElement;\n\n /**\n * Active state\n */\n @Prop() active = false;\n\n /**\n * Auto focus the input\n */\n @Prop() autofocus = false;\n\n /**\n * Disable the input\n */\n @Prop() disabled = false;\n\n /**\n * Render a hidden input outside the shadow dom\n */\n @Prop() form = false;\n\n /**\n * Hide the hint and error messages\n */\n @Prop() hideDetails = false;\n\n /**\n * Hint text for the input\n */\n @Prop() hint = '';\n\n /**\n * Id of the input\n */\n @Prop({ attribute: 'id' }) hostId: string;\n\n /**\n * Id of the input element\n */\n @Prop() inputId: string;\n\n /**\n * Items for the dropdown\n */\n @Prop() items: CSelectItem[];\n\n /**\n * Items per page before adding scroll\n */\n @Prop() itemsPerPage = 6;\n\n /**\n * Label of the input\n */\n @Prop() label: string;\n\n /**\n * Maximum value on a numeric input\n */\n @Prop() max: number = null;\n\n /**\n * Minimum value on a numeric input\n */\n @Prop() min: number = null;\n\n /**\n * Name of the input\n */\n @Prop() name: string;\n\n /**\n * Placeholder of the input\n */\n @Prop() placeholder: string;\n\n /**\n * Mark as readonly\n */\n @Prop() readonly = false;\n\n /**\n * Set the input as required\n */\n @Prop() required = false;\n\n /**\n * Rows on the input\n */\n @Prop() rows = 1;\n\n /**\n * Shadow variant of the input\n */\n @Prop() shadow = false;\n\n /**\n * Step size on a numeric input\n */\n @Prop() step: number = null;\n\n /**\n * Type of the input\n */\n @Prop() type: string;\n\n /**\n * Set the validíty of the input\n */\n @Prop() valid = true;\n\n /**\n * Manual validation\n */\n @Prop() validate = false;\n\n /**\n * Validate the input on blur\n */\n @Prop() validateOnBlur = false;\n\n /**\n * Custom validation message\n */\n @Prop() validation = 'Required field';\n\n /**\n * Value of the input\n */\n @Prop() value: string | number | boolean | CSelectItem | CAutocompleteItem;\n\n /**\n * Variant\n */\n @Prop() variant: 'text' | 'select' = 'text';\n\n /**\n * Emit changes to the parent\n */\n @Event({ bubbles: false }) changeValue: EventEmitter;\n\n /**\n * Emit click to the parent\n * @private\n */\n @Event({ bubbles: false }) itemClick: EventEmitter;\n\n /**\n * Emit close to the parent\n * @private\n */\n @Event({ bubbles: false }) dropdownClose: EventEmitter;\n\n @State() isFocused = false;\n\n @State() labelWidth = 0;\n\n @State() preSlotWidth = 0;\n\n @State() statusText = '';\n\n @State() currentIndex: number = null;\n\n @Watch('valid')\n onValidChange() {\n if (this.validateOnBlur && !this._hasBlurred) return;\n\n this._setAriaDescriptionId();\n }\n\n @Watch('validation')\n onValidationMessageChange() {\n this._updateStatusText();\n }\n\n @Watch('value')\n onValueChange(value) {\n if (!value) {\n this._onReset();\n }\n }\n\n @Watch('placeholder')\n onPlaceholderChange(placeholder) {\n if (placeholder) this._onReset();\n }\n\n private _hasBlurred = false;\n\n private _labelRef: HTMLLabelElement;\n\n private _debounce = null;\n\n private _dropdownElement: HTMLCDropdownElement;\n\n /**\n * @private\n */\n @Method()\n async reset() {\n this._onReset();\n }\n\n componentDidLoad() {\n if (this.autofocus) {\n setTimeout(() => {\n this._onFocus(false);\n }, 500);\n }\n\n this._calculateElementWidths();\n this._setAriaDescriptionId();\n\n if (this.label) {\n this._observer.observe(this._labelRef);\n }\n\n this.inputField?.addEventListener('focus', () => this._onFocus(false));\n this.inputField?.addEventListener('blur', () => this._onBlur());\n this.inputField?.addEventListener(\n 'keypress',\n this._preventNonNumericalInput,\n );\n\n // hide the placeholder text initially if there is a label\n if (this.inputField) {\n this.inputField.placeholder =\n !!this.label || !this.placeholder ? '' : this.placeholder;\n\n this.inputField.title = this.label ?? this.placeholder;\n\n requestAnimationFrame(() => {\n const container = this.inputField.closest(\n '.c-input-menu__input',\n ) as HTMLDivElement;\n\n if (!container) return;\n\n container.dataset.placeholder = this.placeholder;\n });\n }\n }\n\n disconnectedCallback() {\n this.inputField?.removeEventListener('focus', () => this._onFocus(false));\n this.inputField?.removeEventListener('blur', () => this._onBlur());\n this.inputField?.removeEventListener(\n 'keypress',\n this._preventNonNumericalInput,\n );\n\n this._observer.disconnect();\n\n this._dropdownElement?.remove();\n }\n\n get isActive() {\n return !!this.value || typeof this.value === 'boolean' || this.isFocused;\n }\n\n private _setAriaDescriptionId() {\n this.inputField.removeAttribute('aria-describedby');\n\n let type = null;\n\n if (this.valid && !this.value && this.hint) {\n type = 'hint';\n }\n\n if (!this.valid) {\n type = 'error';\n }\n\n if (type) {\n this.inputField.setAttribute(\n 'aria-describedby',\n `${type}-${this.inputId}`,\n );\n }\n }\n\n private _observer = new IntersectionObserver(\n (entries, observer) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n this._calculateElementWidths();\n observer.unobserve(entry.target);\n }\n });\n },\n { threshold: 1 },\n );\n\n private _calculateElementWidths() {\n this.labelWidth = !!this.label ? this._labelRef.scrollWidth * 0.75 + 6 : 0;\n this.preSlotWidth = this.inputField.offsetLeft;\n }\n\n private _onBlur = () => {\n // delay the blur event to prevent the label from 'flashing' on c-select selection\n setTimeout(() => {\n this.isFocused = false;\n\n this._hasBlurred = true;\n\n // show the label if there's no label or value\n this._onReset();\n }, 100);\n };\n\n private _onFocus = (click = true) => {\n if (this.disabled) return;\n\n this.isFocused = true;\n\n this.inputField?.focus();\n\n if (click) {\n this.inputField?.click();\n\n if (this.variant === 'select') {\n this.itemClick.emit();\n }\n }\n\n // show the label if there's no value\n if (this.inputField) {\n this.inputField.placeholder =\n !!this.value || !this.placeholder ? '' : this.placeholder;\n }\n };\n\n private _onReset() {\n if (this.inputField) {\n if (\n !!this.placeholder &&\n !this.value &&\n (this.active || this.isFocused)\n ) {\n this.inputField.placeholder = this.placeholder;\n\n return;\n }\n\n this.inputField.placeholder =\n !this.label && !this.value && !!this.placeholder\n ? this.placeholder\n : '';\n }\n }\n\n /**\n * Prevent non numeric values in the numeric fields\n */\n private _preventNonNumericalInput(event: KeyboardEvent) {\n if (this.type !== 'number') return;\n\n if (!event.key.match(/^[0-9,\\.-]+$/)) {\n event.preventDefault();\n }\n }\n\n private _renderBorders() {\n if (this.shadow) return;\n\n const classes = {\n active: this.isActive || this.active,\n };\n\n return (\n <fieldset aria-hidden=\"true\">\n <legend\n class={classes}\n style={{\n '--_c-input-legend-width': this.labelWidth + 'px',\n }}\n >\n <span class=\"notranslate\"></span>\n </legend>\n </fieldset>\n );\n }\n\n private _renderLabel() {\n if (!this.label) return;\n\n const classes = {\n active: this.isActive,\n };\n\n return (\n <label\n htmlFor={this.inputId}\n ref={(el) => (this._labelRef = el as HTMLLabelElement)}\n class={classes}\n >\n {this.label}\n {this.required && <span> *</span>}\n </label>\n );\n }\n\n get inputField() {\n return this.el?.querySelector('.c-input__input') as\n | HTMLInputElement\n | HTMLTextAreaElement;\n }\n\n private _updateStatusText() {\n if (this._debounce !== null) {\n clearTimeout(this._debounce);\n this._debounce = null;\n }\n\n this._debounce = window.setTimeout(() => {\n this.statusText = this.valid ? '' : `Error: ${this.validation}`;\n\n this._debounce = null;\n }, 1400);\n }\n\n render() {\n const containerClasses = {\n 'c-input': true,\n 'c-input--disabled': this.disabled,\n 'c-input--shadow': this.shadow,\n 'c-input--textarea': this.rows > 1,\n 'c-input--error': !this.valid,\n 'c-input--active': this.isFocused || this.active,\n filled: !!this.value,\n [`c-input--${this.variant}`]: true,\n };\n\n return (\n <Host disabled={this.disabled}>\n <div\n id={'announce-' + this.inputId}\n class=\"visuallyhidden\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {this.statusText}\n </div>\n\n <div class={containerClasses}>\n <div class=\"c-input__control\">\n <div class=\"c-input__slot\" onClick={() => this._onFocus()}>\n {this._renderBorders()}\n\n <div\n class=\"c-input__field\"\n style={{\n '--_c-input-label-position': this.preSlotWidth + 'px',\n }}\n >\n <slot name=\"pre\"></slot>\n\n {this._renderLabel()}\n\n <slot></slot>\n </div>\n </div>\n\n {this.variant === 'select' && <slot name=\"dropdown\"></slot>}\n\n {!this.hideDetails && (\n <c-message\n hint={this.hint}\n inputId={this.inputId}\n valid={this.valid}\n validation={this.validation}\n />\n )}\n </div>\n </div>\n </Host>\n );\n }\n}\n"]}
|
|
@@ -5,27 +5,36 @@ export class COtpInput {
|
|
|
5
5
|
this._debounce = null;
|
|
6
6
|
this._isPasting = false;
|
|
7
7
|
this._inputs = new Array(this.length).fill(null);
|
|
8
|
-
this._value = '';
|
|
9
8
|
this.hideDetails = false;
|
|
10
9
|
this.hint = '';
|
|
11
10
|
this.elementId = undefined;
|
|
12
11
|
this.length = 6;
|
|
13
12
|
this.valid = true;
|
|
14
13
|
this.validation = 'Required field';
|
|
14
|
+
this.value = undefined;
|
|
15
15
|
this.statusText = '';
|
|
16
16
|
}
|
|
17
|
+
async reset() {
|
|
18
|
+
this.value = '';
|
|
19
|
+
this._handleValueChange(this.value, true);
|
|
20
|
+
this.internals.setFormValue(this.value);
|
|
21
|
+
}
|
|
17
22
|
onValidationMessageChange() {
|
|
18
23
|
this._updateStatusText();
|
|
19
24
|
}
|
|
25
|
+
onValueChange(value) {
|
|
26
|
+
this._handleValueChange(value);
|
|
27
|
+
this._updateStatusText();
|
|
28
|
+
}
|
|
20
29
|
_emitValue() {
|
|
21
30
|
requestAnimationFrame(() => {
|
|
22
|
-
this.
|
|
23
|
-
const isFullyFilled = this.
|
|
24
|
-
this.changeValue.emit(isFullyFilled ? this.
|
|
31
|
+
this.value = [...this._inputs].map((input) => input.value).join('');
|
|
32
|
+
const isFullyFilled = this.value.length === this.length;
|
|
33
|
+
this.changeValue.emit(isFullyFilled ? this.value : null);
|
|
25
34
|
if (isFullyFilled) {
|
|
26
|
-
this.completion.emit(this.
|
|
35
|
+
this.completion.emit(this.value || null);
|
|
27
36
|
}
|
|
28
|
-
this.internals.setFormValue(this.
|
|
37
|
+
this.internals.setFormValue(this.value);
|
|
29
38
|
this._updateStatusText();
|
|
30
39
|
});
|
|
31
40
|
}
|
|
@@ -100,20 +109,29 @@ export class COtpInput {
|
|
|
100
109
|
this._debounce = null;
|
|
101
110
|
}
|
|
102
111
|
this._debounce = window.setTimeout(() => {
|
|
112
|
+
const value = [...this._inputs].map((input) => input.value).join('');
|
|
103
113
|
this.statusText = this.valid ? '' : `Error: ${this.validation} `;
|
|
104
|
-
this.statusText += `Currently entered - ${
|
|
105
|
-
.split('')
|
|
106
|
-
.join(' - ')}`;
|
|
114
|
+
this.statusText += `Currently entered - ${!value.length ? 'nothing' : value.split('').join(' - ')}`;
|
|
107
115
|
this.statusText = this.statusText.trim();
|
|
108
116
|
this._debounce = null;
|
|
109
117
|
}, 1400);
|
|
110
118
|
}
|
|
119
|
+
_handleValueChange(value, forceEmpty = false) {
|
|
120
|
+
if (!value && !forceEmpty)
|
|
121
|
+
return;
|
|
122
|
+
const digits = value.split('');
|
|
123
|
+
this._inputs.map((input, index) => (input.value = digits[index] || ''));
|
|
124
|
+
this.internals.setFormValue(value);
|
|
125
|
+
}
|
|
111
126
|
_renderInput(index) {
|
|
112
127
|
return (h("input", { id: `${this.id}--input-${index + 1}`, ref: (el) => (this._inputs[index] = el), "aria-label": `Enter code - digit number - ${index + 1} of ${this.length}`, type: "tel", maxlength: "1", onFocus: () => this._onFocus(index), onInput: (event) => this._onInput(event), onKeyDown: (event) => this._onKeyDown(event), onPaste: (event) => index === 0 && this._onPaste(event) }));
|
|
113
128
|
}
|
|
114
129
|
componentWillLoad() {
|
|
115
130
|
COtpInput._uniqueId += 1;
|
|
116
|
-
|
|
131
|
+
}
|
|
132
|
+
componentDidLoad() {
|
|
133
|
+
this._handleValueChange(this.value);
|
|
134
|
+
this.internals.setFormValue(this.value);
|
|
117
135
|
}
|
|
118
136
|
render() {
|
|
119
137
|
const classes = {
|
|
@@ -245,6 +263,23 @@ export class COtpInput {
|
|
|
245
263
|
"attribute": "validation",
|
|
246
264
|
"reflect": false,
|
|
247
265
|
"defaultValue": "'Required field'"
|
|
266
|
+
},
|
|
267
|
+
"value": {
|
|
268
|
+
"type": "string",
|
|
269
|
+
"mutable": true,
|
|
270
|
+
"complexType": {
|
|
271
|
+
"original": "string",
|
|
272
|
+
"resolved": "string",
|
|
273
|
+
"references": {}
|
|
274
|
+
},
|
|
275
|
+
"required": false,
|
|
276
|
+
"optional": false,
|
|
277
|
+
"docs": {
|
|
278
|
+
"tags": [],
|
|
279
|
+
"text": "Value of the input"
|
|
280
|
+
},
|
|
281
|
+
"attribute": "value",
|
|
282
|
+
"reflect": false
|
|
248
283
|
}
|
|
249
284
|
};
|
|
250
285
|
}
|
|
@@ -286,10 +321,34 @@ export class COtpInput {
|
|
|
286
321
|
}
|
|
287
322
|
}];
|
|
288
323
|
}
|
|
324
|
+
static get methods() {
|
|
325
|
+
return {
|
|
326
|
+
"reset": {
|
|
327
|
+
"complexType": {
|
|
328
|
+
"signature": "() => Promise<void>",
|
|
329
|
+
"parameters": [],
|
|
330
|
+
"references": {
|
|
331
|
+
"Promise": {
|
|
332
|
+
"location": "global",
|
|
333
|
+
"id": "global::Promise"
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
"return": "Promise<void>"
|
|
337
|
+
},
|
|
338
|
+
"docs": {
|
|
339
|
+
"text": "Reset input value",
|
|
340
|
+
"tags": []
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
}
|
|
289
345
|
static get watchers() {
|
|
290
346
|
return [{
|
|
291
347
|
"propName": "validation",
|
|
292
348
|
"methodName": "onValidationMessageChange"
|
|
349
|
+
}, {
|
|
350
|
+
"propName": "value",
|
|
351
|
+
"methodName": "onValueChange"
|
|
293
352
|
}];
|
|
294
353
|
}
|
|
295
354
|
static get attachInternalsMemberName() { return "internals"; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"c-otp-input.js","sourceRoot":"","sources":["../../../../src/components/c-otp-input/c-otp-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,SAAS,EACT,KAAK,EAEL,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,KAAK,EACL,CAAC,GACF,MAAM,eAAe,CAAC;AAWvB,MAAM,OAAO,SAAS;;IA8CZ,sBAAiB,GAAG,KAAK,CAAC;IAE1B,cAAS,GAAG,IAAI,CAAC;IAEjB,eAAU,GAAG,KAAK,CAAC;IAEnB,YAAO,GAAuB,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAIhE,WAAM,GAAG,EAAE,CAAC;uBAjDE,KAAK;gBAKZ,EAAE;;kBAUA,CAAC;iBAKF,IAAI;sBAKC,gBAAgB;sBAYf,EAAE;;EAexB,yBAAyB;IACvB,IAAI,CAAC,iBAAiB,EAAE,CAAC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WACE,EAAE,EAAE,WAAW,GAAG,IAAI,CAAC,EAAE,EACzB,KAAK,EAAC,gBAAgB,eACZ,QAAQ,iBACN,MAAM,IAEjB,IAAI,CAAC,UAAU,CACZ;MAEN,WAAK,KAAK,EAAE,OAAO;QAChB,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;WACpB,IAAI,CAAC,CAAC,CAAC;WACP,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAE9C,iBACE,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,OAAO,EAAE,IAAI,CAAC,SAAS,EACvB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,UAAU,EAAE,IAAI,CAAC,UAAU,GAC3B,CACE,CACD,CACR,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAzMc,mBAAS,GAAG,CAAC,AAAJ,CAAK","sourcesContent":["import {\n AttachInternals,\n Component,\n Event,\n EventEmitter,\n Host,\n Prop,\n State,\n Watch,\n h,\n} from '@stencil/core';\n\n/**\n * @group Form\n */\n@Component({\n tag: 'c-otp-input',\n styleUrl: 'c-otp-input.scss',\n shadow: true,\n formAssociated: true,\n})\nexport class COtpInput {\n // eslint-disable-next-line\n @AttachInternals() internals: ElementInternals;\n\n /**\n * Hide the hint and error messages\n */\n @Prop() hideDetails = false;\n\n /**\n * Hint text for the input\n */\n @Prop() hint = '';\n\n /**\n * Id of the element\n */\n @Prop({ attribute: 'id' }) elementId!: string;\n\n /**\n * Length of the OTP code\n */\n @Prop() length = 6;\n\n /**\n * Set the validíty of the input\n */\n @Prop() valid = true;\n\n /**\n * Custom validation message\n */\n @Prop() validation = 'Required field';\n\n /**\n * Run on input - returns the current value\n */\n @Event({ bubbles: false }) changeValue: EventEmitter<string>;\n\n /**\n * Run on completion - returns the current value\n */\n @Event({ bubbles: false }) completion: EventEmitter<string>;\n\n @State() statusText = '';\n\n private _backSpacePressed = false;\n\n private _debounce = null;\n\n private _isPasting = false;\n\n private _inputs: HTMLInputElement[] = new Array(this.length).fill(null);\n\n private static _uniqueId = 0;\n\n private _value = '';\n\n @Watch('validation')\n onValidationMessageChange() {\n this._updateStatusText();\n }\n\n private _emitValue() {\n requestAnimationFrame(() => {\n this._value = [...this._inputs].map((input) => input.value).join('');\n\n const isFullyFilled = this._value.length === this.length;\n\n this.changeValue.emit(isFullyFilled ? this._value : null);\n\n if (isFullyFilled) {\n this.completion.emit(this._value || null);\n }\n\n this.internals.setFormValue(this._value);\n\n this._updateStatusText();\n });\n }\n\n private _getElements(event: InputEvent | KeyboardEvent) {\n const target = event.target as HTMLInputElement;\n const nextElement = target.nextElementSibling as HTMLInputElement;\n const previousElement = target.previousElementSibling as HTMLInputElement;\n\n return { target, nextElement, previousElement };\n }\n\n /**\n * Select value in an input on focus\n */\n private _onFocus(index: number) {\n this._inputs[index].select();\n }\n\n private _onKeyDown(event: KeyboardEvent) {\n this._backSpacePressed = false;\n\n const { target, previousElement } = this._getElements(event);\n\n if (event.key === 'Backspace') {\n this._backSpacePressed = true;\n\n // go to the previous element if the input is empty\n if (previousElement && !target.value) {\n previousElement.focus();\n }\n\n this._emitValue();\n }\n }\n\n get id() {\n return this.elementId || `c-otp-input--${COtpInput._uniqueId}`;\n }\n\n private _onInput(event: InputEvent) {\n const { target, nextElement, previousElement } = this._getElements(event);\n\n // exclude non numeric input values\n if (isNaN(+target.value)) {\n event.preventDefault();\n\n target.value = null;\n\n return;\n }\n\n if (this._isPasting) {\n this._isPasting = false;\n\n return;\n }\n\n if (this._backSpacePressed) {\n return;\n }\n\n if (event.data) {\n nextElement?.focus();\n } else {\n previousElement?.focus();\n }\n\n this._emitValue();\n }\n\n // TODO: prevent pasting non numeric values and iclude validation\n private _onPaste(event: ClipboardEvent) {\n event.preventDefault();\n\n const pasteData = event.clipboardData.getData('text');\n\n if (isNaN(+pasteData)) {\n return;\n }\n\n this._isPasting = true;\n\n for (const [index, value] of pasteData.split('').entries()) {\n // prevent pasting too long codes\n if (index >= this._inputs.length) {\n continue;\n }\n\n this._inputs[index].value = null;\n this._inputs[index].value = value;\n }\n\n const nextElementIndex = Math.min(this.length, pasteData.length) - 1;\n\n requestAnimationFrame(() => {\n this._inputs[nextElementIndex].focus();\n\n this._emitValue();\n });\n }\n\n private _updateStatusText() {\n if (this._debounce !== null) {\n clearTimeout(this._debounce);\n this._debounce = null;\n }\n\n this._debounce = window.setTimeout(() => {\n this.statusText = this.valid ? '' : `Error: ${this.validation} `;\n this.statusText += `Currently entered - ${this._value\n .split('')\n .join(' - ')}`;\n this.statusText = this.statusText.trim();\n\n this._debounce = null;\n }, 1400);\n }\n\n private _renderInput(index: number) {\n return (\n <input\n id={`${this.id}--input-${index + 1}`}\n ref={(el) => (this._inputs[index] = el as HTMLInputElement)}\n aria-label={`Enter code - digit number - ${index + 1} of ${\n this.length\n }`}\n type=\"tel\"\n maxlength=\"1\"\n onFocus={() => this._onFocus(index)}\n onInput={(event) => this._onInput(event)}\n onKeyDown={(event) => this._onKeyDown(event)}\n onPaste={(event) => index === 0 && this._onPaste(event)}\n />\n );\n }\n\n componentWillLoad() {\n COtpInput._uniqueId += 1;\n\n this.internals.setFormValue(this._value);\n }\n\n render() {\n const classes = {\n 'c-otp-input': true,\n 'c-otp-input--hide-details': this.hideDetails,\n };\n\n return (\n <Host\n id={this.id}\n style={{ '--_c-otp-input-count': this.length.toString() }}\n class={{ error: !this.valid }}\n >\n <div\n id={'announce-' + this.id}\n class=\"visuallyhidden\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {this.statusText}\n </div>\n\n <div class={classes}>\n {new Array(this.length)\n .fill(0)\n .map((_, index) => this._renderInput(index))}\n\n <c-message\n hint={this.hint}\n inputId={this.elementId}\n valid={this.valid}\n validation={this.validation}\n />\n </div>\n </Host>\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"c-otp-input.js","sourceRoot":"","sources":["../../../../src/components/c-otp-input/c-otp-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,SAAS,EACT,KAAK,EAEL,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,KAAK,EACL,CAAC,GACF,MAAM,eAAe,CAAC;AAWvB,MAAM,OAAO,SAAS;;IA+DZ,sBAAiB,GAAG,KAAK,CAAC;IAE1B,cAAS,GAAG,IAAI,CAAC;IAEjB,eAAU,GAAG,KAAK,CAAC;IAEnB,YAAO,GAAuB,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;uBA9DlD,KAAK;gBAKZ,EAAE;;kBAUA,CAAC;iBAKF,IAAI;sBAKC,gBAAgB;;sBAiBf,EAAE;;EAMxB,KAAK,CAAC,KAAK;IACT,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAEhB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAE1C,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;EAC1C,CAAC;EAaD,yBAAyB;IACvB,IAAI,CAAC,iBAAiB,EAAE,CAAC;EAC3B,CAAC;EAGD,aAAa,CAAC,KAAa;IACzB,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC/B,IAAI,CAAC,iBAAiB,EAAE,CAAC;EAC3B,CAAC;EAEO,UAAU;IAChB,qBAAqB,CAAC,GAAG,EAAE;MACzB,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA7Nc,mBAAS,GAAG,CAAC,AAAJ,CAAK","sourcesContent":["import {\n AttachInternals,\n Component,\n Event,\n EventEmitter,\n Host,\n Method,\n Prop,\n State,\n Watch,\n h,\n} from '@stencil/core';\n\n/**\n * @group Form\n */\n@Component({\n tag: 'c-otp-input',\n styleUrl: 'c-otp-input.scss',\n shadow: true,\n formAssociated: true,\n})\nexport class COtpInput {\n // eslint-disable-next-line\n @AttachInternals() internals: ElementInternals;\n\n /**\n * Hide the hint and error messages\n */\n @Prop() hideDetails = false;\n\n /**\n * Hint text for the input\n */\n @Prop() hint = '';\n\n /**\n * Id of the element\n */\n @Prop({ attribute: 'id' }) elementId!: string;\n\n /**\n * Length of the OTP code\n */\n @Prop() length = 6;\n\n /**\n * Set the validíty of the input\n */\n @Prop() valid = true;\n\n /**\n * Custom validation message\n */\n @Prop() validation = 'Required field';\n\n /**\n * Value of the input\n */\n @Prop({ mutable: true }) value: string;\n\n /**\n * Run on input - returns the current value\n */\n @Event({ bubbles: false }) changeValue: EventEmitter<string>;\n\n /**\n * Run on completion - returns the current value\n */\n @Event({ bubbles: false }) completion: EventEmitter<string>;\n\n @State() statusText = '';\n\n /**\n * Reset input value\n */\n @Method()\n async reset() {\n this.value = '';\n\n this._handleValueChange(this.value, true);\n\n this.internals.setFormValue(this.value);\n }\n\n private _backSpacePressed = false;\n\n private _debounce = null;\n\n private _isPasting = false;\n\n private _inputs: HTMLInputElement[] = new Array(this.length).fill(null);\n\n private static _uniqueId = 0;\n\n @Watch('validation')\n onValidationMessageChange() {\n this._updateStatusText();\n }\n\n @Watch('value')\n onValueChange(value: string) {\n this._handleValueChange(value);\n this._updateStatusText();\n }\n\n private _emitValue() {\n requestAnimationFrame(() => {\n this.value = [...this._inputs].map((input) => input.value).join('');\n\n const isFullyFilled = this.value.length === this.length;\n\n this.changeValue.emit(isFullyFilled ? this.value : null);\n\n if (isFullyFilled) {\n this.completion.emit(this.value || null);\n }\n\n this.internals.setFormValue(this.value);\n\n this._updateStatusText();\n });\n }\n\n private _getElements(event: InputEvent | KeyboardEvent) {\n const target = event.target as HTMLInputElement;\n const nextElement = target.nextElementSibling as HTMLInputElement;\n const previousElement = target.previousElementSibling as HTMLInputElement;\n\n return { target, nextElement, previousElement };\n }\n\n /**\n * Select value in an input on focus\n */\n private _onFocus(index: number) {\n this._inputs[index].select();\n }\n\n private _onKeyDown(event: KeyboardEvent) {\n this._backSpacePressed = false;\n\n const { target, previousElement } = this._getElements(event);\n\n if (event.key === 'Backspace') {\n this._backSpacePressed = true;\n\n // go to the previous element if the input is empty\n if (previousElement && !target.value) {\n previousElement.focus();\n }\n\n this._emitValue();\n }\n }\n\n get id() {\n return this.elementId || `c-otp-input--${COtpInput._uniqueId}`;\n }\n\n private _onInput(event: InputEvent) {\n const { target, nextElement, previousElement } = this._getElements(event);\n\n // exclude non numeric input values\n if (isNaN(+target.value)) {\n event.preventDefault();\n\n target.value = null;\n\n return;\n }\n\n if (this._isPasting) {\n this._isPasting = false;\n\n return;\n }\n\n if (this._backSpacePressed) {\n return;\n }\n\n if (event.data) {\n nextElement?.focus();\n } else {\n previousElement?.focus();\n }\n\n this._emitValue();\n }\n\n // TODO: prevent pasting non numeric values and iclude validation\n private _onPaste(event: ClipboardEvent) {\n event.preventDefault();\n\n const pasteData = event.clipboardData.getData('text');\n\n if (isNaN(+pasteData)) {\n return;\n }\n\n this._isPasting = true;\n\n for (const [index, value] of pasteData.split('').entries()) {\n // prevent pasting too long codes\n if (index >= this._inputs.length) {\n continue;\n }\n\n this._inputs[index].value = null;\n this._inputs[index].value = value;\n }\n\n const nextElementIndex = Math.min(this.length, pasteData.length) - 1;\n\n requestAnimationFrame(() => {\n this._inputs[nextElementIndex].focus();\n\n this._emitValue();\n });\n }\n\n private _updateStatusText() {\n if (this._debounce !== null) {\n clearTimeout(this._debounce);\n this._debounce = null;\n }\n\n this._debounce = window.setTimeout(() => {\n const value = [...this._inputs].map((input) => input.value).join('');\n\n this.statusText = this.valid ? '' : `Error: ${this.validation} `;\n this.statusText += `Currently entered - ${\n !value.length ? 'nothing' : value.split('').join(' - ')\n }`;\n this.statusText = this.statusText.trim();\n\n this._debounce = null;\n }, 1400);\n }\n\n private _handleValueChange(value: string | null, forceEmpty = false) {\n if (!value && !forceEmpty) return;\n\n const digits = value.split('');\n\n this._inputs.map((input, index) => (input.value = digits[index] || ''));\n\n this.internals.setFormValue(value);\n }\n\n private _renderInput(index: number) {\n return (\n <input\n id={`${this.id}--input-${index + 1}`}\n ref={(el) => (this._inputs[index] = el as HTMLInputElement)}\n aria-label={`Enter code - digit number - ${index + 1} of ${\n this.length\n }`}\n type=\"tel\"\n maxlength=\"1\"\n onFocus={() => this._onFocus(index)}\n onInput={(event) => this._onInput(event)}\n onKeyDown={(event) => this._onKeyDown(event)}\n onPaste={(event) => index === 0 && this._onPaste(event)}\n />\n );\n }\n\n componentWillLoad() {\n COtpInput._uniqueId += 1;\n }\n\n componentDidLoad() {\n this._handleValueChange(this.value);\n\n this.internals.setFormValue(this.value);\n }\n\n render() {\n const classes = {\n 'c-otp-input': true,\n 'c-otp-input--hide-details': this.hideDetails,\n };\n\n return (\n <Host\n id={this.id}\n style={{ '--_c-otp-input-count': this.length.toString() }}\n class={{ error: !this.valid }}\n >\n <div\n id={'announce-' + this.id}\n class=\"visuallyhidden\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n >\n {this.statusText}\n </div>\n\n <div class={classes}>\n {new Array(this.length)\n .fill(0)\n .map((_, index) => this._renderInput(index))}\n\n <c-message\n hint={this.hint}\n inputId={this.elementId}\n valid={this.valid}\n validation={this.validation}\n />\n </div>\n </Host>\n );\n }\n}\n"]}
|
|
@@ -99,7 +99,7 @@ body {
|
|
|
99
99
|
gap: 8px;
|
|
100
100
|
grid-template-columns: 1fr;
|
|
101
101
|
min-height: 46px;
|
|
102
|
-
padding:
|
|
102
|
+
padding: 8px 12px;
|
|
103
103
|
}
|
|
104
104
|
.c-side-navigation-item__header--expandable {
|
|
105
105
|
grid-template-columns: auto 1fr;
|
|
@@ -110,9 +110,6 @@ body {
|
|
|
110
110
|
gap: 8px;
|
|
111
111
|
line-height: normal;
|
|
112
112
|
max-width: 100%;
|
|
113
|
-
overflow: hidden;
|
|
114
|
-
text-overflow: ellipsis;
|
|
115
|
-
white-space: nowrap;
|
|
116
113
|
}
|
|
117
114
|
|
|
118
115
|
:host(.c-side-navigation-item--parent.active) {
|
|
@@ -106,7 +106,7 @@ export class CSideNavigationItem {
|
|
|
106
106
|
return (h(Host, Object.assign({}, a11y, { class: classes, onClick: (e) => this._redirect(e), onKeyDown: (e) => this._redirect(e) }), h("div", { class: {
|
|
107
107
|
'c-side-navigation-item__header': true,
|
|
108
108
|
'c-side-navigation-item__header--expandable': this._slotHasContent,
|
|
109
|
-
} }, this._slotHasContent && (h("
|
|
109
|
+
} }, this._slotHasContent && (h("c-icon", { class: "svg", path: mdiChevronRight })), h("div", { class: "c-side-navigation-item__slot" }, h("slot", null))), this._slotHasContent && (h("nav", { role: "menubar", "aria-label": this._ariaLabel, "aria-expanded": (_b = (!!this.active)) === null || _b === void 0 ? void 0 : _b.toString(), class: subNavigationClasses }, h("slot", { name: "sub-item" }))), h("c-loader", { size: 32, hide: !this.loading, style: { pointerEvents: 'none' } })));
|
|
110
110
|
}
|
|
111
111
|
static get is() { return "c-side-navigation-item"; }
|
|
112
112
|
static get encapsulation() { return "shadow"; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"c-side-navigation-item.js","sourceRoot":"","sources":["../../../../src/components/c-side-navigation-item/c-side-navigation-item.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,CAAC,EACD,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,KAAK,EAEL,MAAM,EACN,KAAK,GACN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAU1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C,CAAC;MAEnC,WACE,KAAK,EAAE;UACL,gCAAgC,EAAE,IAAI;UACtC,4CAA4C,EAAE,IAAI,CAAC,eAAe;SACnE;QAEA,IAAI,CAAC,eAAe,IAAI,CACvB,
|
|
1
|
+
{"version":3,"file":"c-side-navigation-item.js","sourceRoot":"","sources":["../../../../src/components/c-side-navigation-item/c-side-navigation-item.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,CAAC,EACD,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,KAAK,EAEL,MAAM,EACN,KAAK,GACN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAU1C,MAAM,OAAO,mBAAmB;;IA+CtB,eAAU,GAAG,KAAK,CAAC;IAyCnB,oBAAe,GAAG,KAAK,CAAC;;;kBAxEP,IAAI;mBAKX,KAAK;;EASvB,YAAY,CAAC,KAAY;IACvB,IAAI,IAAI,CAAC,UAAU,EAAE;MACnB,KAAK,CAAC,eAAe,EAAE,CAAC;MACxB,KAAK,CAAC,wBAAwB,EAAE,CAAC;MACjC,KAAK,CAAC,cAAc,EAAE,CAAC;MAEvB,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;KAC5B;EACH,CAAC;EAGD,cAAc,CAAC,MAAe;IAC5B,IAAI,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;EAC3C,CAAC;EAMO,2BAA2B,CAAC,SAAkB;IACpD,IAAI,CAAC,IAAI,CAAC,eAAe;MAAE,OAAO;IAElC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAAC,CAAC,OAAO,CACxE,CAAC,KAAoC,EAAE,EAAE;MACvC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;MAC3C,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,CAAC,CAC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\n Prop,\n Element,\n Event,\n EventEmitter,\n Listen,\n Watch,\n} from '@stencil/core';\nimport { mdiChevronRight } from '@mdi/js';\n\n/**\n * @parent c-side-navigation\n */\n@Component({\n tag: 'c-side-navigation-item',\n styleUrl: 'c-side-navigation-item.scss',\n shadow: true,\n})\nexport class CSideNavigationItem {\n @Element() hostElement: HTMLCSideNavigationItemElement;\n\n /**\n * Indicate active state\n */\n @Prop() active: boolean;\n\n /**\n * Hyperlink url\n */\n @Prop() href: string;\n\n /**\n * Hyperlink target\n */\n @Prop() target: string = null;\n\n /**\n * Loading state\n */\n @Prop() loading = false;\n\n /**\n * Emit changes to the c-accordion\n * @private\n */\n @Event() itemChange: EventEmitter;\n\n @Listen('itemChange')\n handleChange(event: Event) {\n if (this._isSubItem) {\n event.stopPropagation();\n event.stopImmediatePropagation();\n event.preventDefault();\n\n this.active = !this.active;\n }\n }\n\n @Watch('active')\n onActiveChange(active: boolean) {\n this._handleChildFocusableChange(active);\n }\n\n private _ariaLabel: string;\n\n private _isSubItem = false;\n\n private _handleChildFocusableChange(focusable: boolean) {\n if (!this._slotHasContent) return;\n\n Array.from(this.hostElement.querySelectorAll('[slot=\"sub-item\"]')).forEach(\n (child: HTMLCSubNavigationItemElement) => {\n child.ariaHidden = (!focusable).toString();\n child.focusable = focusable;\n },\n );\n }\n\n private _redirect(event: KeyboardEvent | Event) {\n if (\n (event instanceof KeyboardEvent && event?.key === 'Enter') ||\n !(event instanceof KeyboardEvent)\n ) {\n if (this._isSubItem) {\n event.stopPropagation();\n event.stopImmediatePropagation();\n event.preventDefault();\n }\n\n this.itemChange.emit(event);\n\n if (!this._slotHasContent) {\n const sidenav = document.querySelector('c-side-navigation');\n sidenav.menuVisible = false;\n }\n\n if (this.href) {\n if (this.target) {\n window.open(this.href, this.target);\n } else {\n window.location.href = this.href;\n }\n }\n }\n }\n\n private _slotHasContent = false;\n\n private _assignSubItemSlots() {\n const subItems = this.hostElement.querySelectorAll(\n 'c-side-navigation-item',\n );\n\n Array.from(subItems).forEach((item) => {\n item.setAttribute('slot', 'sub-item');\n });\n }\n\n componentWillLoad() {\n this._assignSubItemSlots();\n\n this._slotHasContent =\n !!this.hostElement.querySelector('[slot=\"sub-item\"]');\n\n this._isSubItem = !!this.hostElement.getAttribute('slot');\n\n this._handleChildFocusableChange(this.active);\n }\n\n componentDidLoad() {\n for (const node of this.hostElement.childNodes) {\n if (node.nodeName === '#text') {\n this._ariaLabel = node.nodeValue.trim();\n break;\n }\n }\n\n this._handleChildClasses();\n }\n\n private _handleChildClasses() {\n if (!this._isSubItem) return;\n\n Array.from(this.hostElement.children)\n .filter((child) => child.tagName === 'C-SUB-NAVIGATION-ITEM')\n .forEach((child: HTMLCSubNavigationItemElement) => {\n child.classList.add('c-sub-navigation-item--sub-level');\n });\n }\n\n render() {\n const classes = {\n 'c-side-navigation-item': true,\n 'c-side-navigation-item--parent': this._slotHasContent,\n active: this.active,\n };\n\n const subNavigationClasses = {\n subnavactive: this.active,\n 'sub-item': !this.active,\n };\n\n const a11y = {\n role: 'menuitem',\n tabindex: '0',\n };\n\n if (this._slotHasContent) {\n a11y['aria-expanded'] = (!!this.active)?.toString();\n } else if (this.active) {\n a11y['aria-current'] = 'page';\n }\n\n return (\n <Host\n {...a11y}\n class={classes}\n onClick={(e) => this._redirect(e)}\n onKeyDown={(e) => this._redirect(e)}\n >\n <div\n class={{\n 'c-side-navigation-item__header': true,\n 'c-side-navigation-item__header--expandable': this._slotHasContent,\n }}\n >\n {this._slotHasContent && (\n <c-icon class=\"svg\" path={mdiChevronRight}></c-icon>\n )}\n <div class=\"c-side-navigation-item__slot\">\n <slot></slot>\n </div>\n </div>\n\n {this._slotHasContent && (\n <nav\n role=\"menubar\"\n aria-label={this._ariaLabel}\n aria-expanded={(!!this.active)?.toString()}\n class={subNavigationClasses}\n >\n <slot name=\"sub-item\"></slot>\n </nav>\n )}\n\n <c-loader\n size={32}\n hide={!this.loading}\n style={{ pointerEvents: 'none' }}\n ></c-loader>\n </Host>\n );\n }\n}\n"]}
|