@3t-transform/threeteeui 0.1.52 → 0.1.57

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.
Files changed (117) hide show
  1. package/dist/cjs/{domsanitiser.options-b2d88e35.js → domsanitiser.options-cd2932a9.js} +17 -17
  2. package/dist/cjs/tttx-button.cjs.entry.js +23 -23
  3. package/dist/cjs/tttx-dialog-box.cjs.entry.js +69 -69
  4. package/dist/cjs/tttx-filter.cjs.entry.js +182 -180
  5. package/dist/cjs/tttx-form.cjs.entry.js +457 -457
  6. package/dist/cjs/tttx-icon.cjs.entry.js +10 -10
  7. package/dist/cjs/tttx-keyvalue-block.cjs.entry.js +58 -58
  8. package/dist/cjs/tttx-list.cjs.entry.js +31 -31
  9. package/dist/cjs/tttx-loading-spinner.cjs.entry.js +15 -15
  10. package/dist/cjs/tttx-qrcode.cjs.entry.js +27 -27
  11. package/dist/cjs/tttx-sorter.cjs.entry.js +107 -104
  12. package/dist/cjs/tttx-standalone-input.cjs.entry.js +78 -78
  13. package/dist/cjs/tttx-toolbar.cjs.entry.js +9 -9
  14. package/dist/collection/components/atoms/tttx-button/tttx-button.js +110 -110
  15. package/dist/collection/components/atoms/tttx-button/tttx-button.stories.js +14 -14
  16. package/dist/collection/components/atoms/tttx-icon/tttx-icon.js +62 -62
  17. package/dist/collection/components/atoms/tttx-icon/tttx-icon.stories.js +22 -22
  18. package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.js +109 -109
  19. package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.stories.js +38 -38
  20. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.js +67 -67
  21. package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.js +17 -17
  22. package/dist/collection/components/atoms/tttx-qrcode/tttx-qrcode.js +81 -81
  23. package/dist/collection/components/atoms/tttx-qrcode/tttx-qrcode.stories.js +22 -22
  24. package/dist/collection/components/molecules/tttx-dialog-box/tttx-dialog-box.js +172 -172
  25. package/dist/collection/components/molecules/tttx-dialog-box/tttx-dialog-box.stories.js +289 -289
  26. package/dist/collection/components/molecules/tttx-filter/tttx-filter.js +416 -400
  27. package/dist/collection/components/molecules/tttx-filter/tttx-filter.stories.js +80 -80
  28. package/dist/collection/components/molecules/tttx-form/lib/setErrorState.js +37 -37
  29. package/dist/collection/components/molecules/tttx-form/lib/validityCheck.js +61 -61
  30. package/dist/collection/components/molecules/tttx-form/tttx-form.js +479 -479
  31. package/dist/collection/components/molecules/tttx-form/tttx-form.stories.js +272 -272
  32. package/dist/collection/components/molecules/tttx-list/tttx-list.js +105 -105
  33. package/dist/collection/components/molecules/tttx-list/tttx-list.stories.js +43 -43
  34. package/dist/collection/components/molecules/tttx-sorter/tttx-sorter.js +253 -236
  35. package/dist/collection/components/molecules/tttx-sorter/tttx-sorter.stories.js +42 -42
  36. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.js +759 -759
  37. package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.js +172 -172
  38. package/dist/collection/components/molecules/tttx-toolbar/tttx-toolbar.js +44 -44
  39. package/dist/collection/components/molecules/tttx-toolbar/tttx-toolbar.stories.js +14 -14
  40. package/dist/collection/components/palette.stories.js +7 -7
  41. package/dist/collection/docs/gettingstarted-developer.stories.js +5 -5
  42. package/dist/collection/icons.js +2838 -2838
  43. package/dist/collection/index.js +1 -1
  44. package/dist/collection/shared/domsanitiser.options.js +14 -14
  45. package/dist/components/domsanitiser.options.js +17 -17
  46. package/dist/components/tttx-button2.js +48 -48
  47. package/dist/components/tttx-dialog-box.js +97 -97
  48. package/dist/components/tttx-filter.js +217 -215
  49. package/dist/components/tttx-form.js +475 -475
  50. package/dist/components/tttx-icon2.js +28 -28
  51. package/dist/components/tttx-keyvalue-block.js +76 -76
  52. package/dist/components/tttx-list.js +53 -53
  53. package/dist/components/tttx-loading-spinner.js +33 -33
  54. package/dist/components/tttx-qrcode.js +45 -45
  55. package/dist/components/tttx-sorter.js +136 -133
  56. package/dist/components/tttx-standalone-input.js +130 -130
  57. package/dist/components/tttx-toolbar.js +26 -26
  58. package/dist/esm/{domsanitiser.options-81611f82.js → domsanitiser.options-563c1cf3.js} +17 -17
  59. package/dist/esm/polyfills/core-js.js +0 -0
  60. package/dist/esm/polyfills/dom.js +0 -0
  61. package/dist/esm/polyfills/es5-html-element.js +0 -0
  62. package/dist/esm/polyfills/index.js +0 -0
  63. package/dist/esm/polyfills/system.js +0 -0
  64. package/dist/esm/tttx-button.entry.js +23 -23
  65. package/dist/esm/tttx-dialog-box.entry.js +69 -69
  66. package/dist/esm/tttx-filter.entry.js +182 -180
  67. package/dist/esm/tttx-form.entry.js +457 -457
  68. package/dist/esm/tttx-icon.entry.js +10 -10
  69. package/dist/esm/tttx-keyvalue-block.entry.js +58 -58
  70. package/dist/esm/tttx-list.entry.js +31 -31
  71. package/dist/esm/tttx-loading-spinner.entry.js +15 -15
  72. package/dist/esm/tttx-qrcode.entry.js +27 -27
  73. package/dist/esm/tttx-sorter.entry.js +107 -104
  74. package/dist/esm/tttx-standalone-input.entry.js +78 -78
  75. package/dist/esm/tttx-toolbar.entry.js +9 -9
  76. package/dist/tttx/p-225e6fa6.entry.js +1 -0
  77. package/dist/tttx/{p-bc3b9283.entry.js → p-58d7c978.entry.js} +1 -1
  78. package/dist/tttx/{p-c751ebc2.entry.js → p-8b511fff.entry.js} +1 -1
  79. package/dist/tttx/{p-6a6ff7b7.entry.js → p-909c090d.entry.js} +1 -1
  80. package/dist/tttx/p-a658e1ac.entry.js +1 -0
  81. package/dist/tttx/{p-0b25ac9c.js → p-d3835fde.js} +2 -2
  82. package/dist/tttx/tttx.esm.js +1 -1
  83. package/dist/types/components/atoms/tttx-button/tttx-button.d.ts +10 -10
  84. package/dist/types/components/atoms/tttx-button/tttx-button.stories.d.ts +10 -10
  85. package/dist/types/components/atoms/tttx-icon/tttx-icon.d.ts +5 -5
  86. package/dist/types/components/atoms/tttx-icon/tttx-icon.stories.d.ts +20 -20
  87. package/dist/types/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.d.ts +7 -7
  88. package/dist/types/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.stories.d.ts +9 -9
  89. package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.d.ts +6 -6
  90. package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.d.ts +17 -17
  91. package/dist/types/components/atoms/tttx-qrcode/tttx-qrcode.d.ts +8 -8
  92. package/dist/types/components/atoms/tttx-qrcode/tttx-qrcode.stories.d.ts +23 -23
  93. package/dist/types/components/molecules/tttx-dialog-box/tttx-dialog-box.d.ts +18 -18
  94. package/dist/types/components/molecules/tttx-dialog-box/tttx-dialog-box.stories.d.ts +24 -24
  95. package/dist/types/components/molecules/tttx-filter/tttx-filter.d.ts +44 -43
  96. package/dist/types/components/molecules/tttx-filter/tttx-filter.stories.d.ts +76 -0
  97. package/dist/types/components/molecules/tttx-form/lib/setErrorState.d.ts +13 -13
  98. package/dist/types/components/molecules/tttx-form/lib/validityCheck.d.ts +17 -17
  99. package/dist/types/components/molecules/tttx-form/tttx-form.d.ts +133 -133
  100. package/dist/types/components/molecules/tttx-form/tttx-form.stories.d.ts +278 -0
  101. package/dist/types/components/molecules/tttx-list/tttx-list.d.ts +11 -11
  102. package/dist/types/components/molecules/tttx-list/tttx-list.stories.d.ts +14 -0
  103. package/dist/types/components/molecules/tttx-sorter/tttx-sorter.d.ts +21 -20
  104. package/dist/types/components/molecules/tttx-sorter/tttx-sorter.stories.d.ts +30 -0
  105. package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.d.ts +69 -69
  106. package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.d.ts +143 -143
  107. package/dist/types/components/molecules/tttx-toolbar/tttx-toolbar.d.ts +4 -4
  108. package/dist/types/components/molecules/tttx-toolbar/tttx-toolbar.stories.d.ts +13 -13
  109. package/dist/types/components/palette.stories.d.ts +6 -6
  110. package/dist/types/components.d.ts +2 -0
  111. package/dist/types/docs/gettingstarted-developer.stories.d.ts +5 -5
  112. package/dist/types/icons.d.ts +2 -2
  113. package/dist/types/index.d.ts +1 -1
  114. package/dist/types/shared/domsanitiser.options.d.ts +10 -10
  115. package/package.json +1 -1
  116. package/dist/tttx/p-3b29e8af.entry.js +0 -1
  117. package/dist/tttx/p-637e7e88.entry.js +0 -1
@@ -1,400 +1,416 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { h, Host } from '@stencil/core';
3
- export class TttxFilter {
4
- constructor() {
5
- this.filterKey = undefined;
6
- this.filterOptions = [
7
- { optionIcon: 'cancel', optionIconColor: 'darkred', optionText: 'Expired' },
8
- { optionIcon: 'warning', optionIconColor: 'orange', optionText: 'Expiring soon' },
9
- { optionIcon: 'check_circle', optionIconColor: 'green', optionText: 'Active' },
10
- ];
11
- this.showSelectAll = true;
12
- this.showSearchField = false;
13
- this.showOptionIcons = true;
14
- this.filterButtonStyle = 'list filter';
15
- this.filterHeader = 'Qualification status';
16
- this.defaultFilterOptions = undefined;
17
- this.popoverWidth = '193px';
18
- this.showPopover = false;
19
- this.displayedFilterSettings = undefined;
20
- this.selectedFilters = undefined;
21
- this.filterSearchTerm = '';
22
- this.allSelected = undefined;
23
- }
24
- handleCloseFilter() {
25
- this.showPopover = false;
26
- }
27
- emitFilterEvent() {
28
- this.filterChangeEvent.emit({
29
- selectedFilters: this.selectedFilters,
30
- filterKey: this.filterKey,
31
- allSelected: this.allSelected,
32
- });
33
- }
34
- onFilterButtonClick() {
35
- this.togglePopover();
36
- }
37
- onCloseButtonClick() {
38
- this.togglePopover();
39
- }
40
- onApplyFilterButtonClick() {
41
- this.emitFilterEvent();
42
- this.togglePopover();
43
- }
44
- onFilterOptionSelected(selectedOption) {
45
- this.allSelected = false;
46
- if (this.selectedFilters.includes(selectedOption)) {
47
- this.selectedFilters = this.selectedFilters.filter((filter) => filter != selectedOption);
48
- }
49
- else {
50
- this.selectedFilters = [...this.selectedFilters, selectedOption];
51
- }
52
- }
53
- componentWillLoad() {
54
- this.displayedFilterSettings = this.parseFilterOptions();
55
- if (this.defaultFilterOptions !== undefined) {
56
- const parsedDefaultFilterOptions = this.parseDefaultFilterOptions();
57
- this.selectedFilters = parsedDefaultFilterOptions;
58
- let allSelected = true;
59
- this.parseFilterOptions().map(filterOption => {
60
- if (!this.selectedFilters.includes(filterOption.optionText)) {
61
- allSelected = false;
62
- }
63
- });
64
- this.allSelected = allSelected;
65
- }
66
- else {
67
- this.allSelected = true;
68
- this.selectedFilters = this.displayedFilterSettings.map((filterOption) => filterOption.optionText);
69
- }
70
- }
71
- togglePopover() {
72
- this.showPopover = !this.showPopover;
73
- // if(!this.showPopover) {
74
- // // this._focussedElementIndex = -1;
75
- // }
76
- }
77
- // Commented out keyboard interaction for now
78
- // @Listen('keyup')
79
- // handleKeyUp(event: KeyboardEvent) {
80
- // const keyboardEventValue = event.key;
81
- // if (document.activeElement.id != `filter__${this.filterKey}`) return;
82
- // if (event.key == " " || event.code == "Space" || event.keyCode == 32) {
83
- // if (this._focussedElementIndex == 0) {
84
- // this.onSelectAllClick()
85
- // } else {
86
- // const options = this.el.shadowRoot.querySelectorAll('.filter-option') as HTMLElement[];
87
- // this.onFilterOptionSelected(options[this._focussedElementIndex].textContent)
88
- // }
89
- // return;
90
- // }
91
- // switch (keyboardEventValue) {
92
- // case 'Enter':
93
- // if(!this.showPopover) {
94
- // this.showPopover=true
95
- // } else {
96
- // this.emitFilterEvent()
97
- // }
98
- // break;
99
- // case 'Escape':
100
- // this.showPopover = false;
101
- // this._focussedElementIndex = -1;
102
- // break;
103
- // case 'ArrowDown':
104
- // this.showPopover = true;
105
- // if (this._focussedElementIndex == -1) {
106
- // this._focussedElementIndex = 0;
107
- // } else {
108
- // const options = this.el.shadowRoot.querySelectorAll('.filter-option') as HTMLElement[];
109
- // const currentOption = options[this._focussedElementIndex] as HTMLElement;
110
- // currentOption.blur();
111
- // // options[this._focussedElementIndex].focus();
112
- // this._focussedElementIndex + 1 < options.length ? this._focussedElementIndex++ : (this._focussedElementIndex = 0);
113
- // }
114
- // break;
115
- // case 'ArrowUp':
116
- // if (this._focussedElementIndex == -1) {
117
- // this.showPopover = true;
118
- // this._focussedElementIndex = 0;
119
- // } else {
120
- // const options = this.el.shadowRoot.querySelectorAll('.filter-option') as HTMLElement[];
121
- // const currentOption = options[this._focussedElementIndex] as HTMLElement;
122
- // currentOption.blur();
123
- // // options[this._focussedElementIndex].focus();
124
- // this._focussedElementIndex > 0 ? this._focussedElementIndex-- : (this._focussedElementIndex = options.length - 1);
125
- // }
126
- // break;
127
- // }
128
- // }
129
- handleFilterChange(event) {
130
- const target = event.target;
131
- this.filterSearchTerm = target.value;
132
- const filteredResults = this.parseFilterOptions().filter((filterOption) => {
133
- const lowercaseOption = filterOption.optionText.toLowerCase();
134
- const filterTerm = this.filterSearchTerm.toLowerCase();
135
- return lowercaseOption.includes(filterTerm);
136
- });
137
- this.displayedFilterSettings = filteredResults;
138
- }
139
- onSelectAllClick() {
140
- this.allSelected = !this.allSelected;
141
- if (this.allSelected) {
142
- this.displayedFilterSettings.forEach((filterSetting) => { this.selectedFilters = [...this.selectedFilters, filterSetting.optionText]; });
143
- }
144
- else {
145
- this.selectedFilters = [];
146
- }
147
- }
148
- getFilterButtonClassName(buttonStyle) {
149
- switch (buttonStyle) {
150
- case 'table icon': {
151
- return '--table-icon';
152
- }
153
- case 'list icon': {
154
- return '--list-icon';
155
- }
156
- default: {
157
- return '';
158
- }
159
- }
160
- }
161
- parseFilterOptions() {
162
- return typeof this.filterOptions === 'string' ? JSON.parse(this.filterOptions) : this.filterOptions;
163
- }
164
- parseDefaultFilterOptions() {
165
- return typeof this.defaultFilterOptions === 'string' ? JSON.parse(this.defaultFilterOptions) : this.defaultFilterOptions;
166
- }
167
- render() {
168
- const filterPopoverContainerClassNameModifier = this.showSearchField ? '--with-search-field' : '';
169
- const selectAllCheckboxIcon = this.allSelected ? 'check_box' : 'check_box_outline_blank';
170
- const selectAllCheckboxColor = this.allSelected ? 'blue' : 'grey';
171
- const buttonStyleClassNameModifier = this.getFilterButtonClassName(this.filterButtonStyle);
172
- const filterKey = `filter__${this.filterKey}`;
173
- return (h(Host, { id: filterKey }, h("div", { class: 'filter-container' }, h("button", { class: `filter-button ${buttonStyleClassNameModifier}`, type: 'button', onClick: this.onFilterButtonClick.bind(this) }, h("tttx-icon", { icon: 'filter_list', class: 'filter-icon', color: 'black' }), "Filter"), this.showPopover && (h("div", { class: `filter-popover-container ${filterPopoverContainerClassNameModifier}`, style: { width: this.popoverWidth } }, h("div", { class: 'filter-header' }, this.filterHeader), this.showSearchField ? (h("div", { class: 'search-field-container' }, h("tttx-icon", { icon: 'search', class: 'search-icon' }), h("input", { type: 'text', class: 'search-input', placeholder: 'Search', value: this.filterSearchTerm, onInput: this.handleFilterChange.bind(this) }))) : (''), h("div", { class: 'filter-options-container' }, this.showSelectAll ? (h("div", { class: 'filter-option', tabIndex: -1, onClick: this.onSelectAllClick.bind(this) }, h("tttx-icon", { icon: selectAllCheckboxIcon, color: selectAllCheckboxColor, class: 'select-all-icon' }), h("label", { class: 'filter-label' }, "Select all"))) : (''), this.displayedFilterSettings.map((option) => {
174
- const checkboxIcon = this.selectedFilters.includes(option.optionText) ? 'check_box' : 'check_box_outline_blank';
175
- const checkboxColor = this.selectedFilters.includes(option.optionText) ? 'blue' : 'grey';
176
- return h("div", { class: 'filter-option', tabIndex: -1, onClick: () => this.onFilterOptionSelected(option.optionText), key: option.optionText }, h("tttx-icon", { icon: checkboxIcon, color: checkboxColor, class: 'checkbox-icon' }), this.showOptionIcons && h("tttx-icon", { icon: option.optionIcon, color: option.optionIconColor }), h("label", { class: 'filter-label' }, option.optionText));
177
- })), h("div", { class: 'filter-popover-button-container' }, h("button", { type: 'button', class: 'close-button', onClick: this.onCloseButtonClick.bind(this) }, "Close"), h("button", { type: 'button', class: 'apply-button', onClick: this.onApplyFilterButtonClick.bind(this) }, "Apply")))))));
178
- }
179
- static get is() { return "tttx-filter"; }
180
- static get encapsulation() { return "shadow"; }
181
- static get originalStyleUrls() {
182
- return {
183
- "$": ["tttx-filter.scss"]
184
- };
185
- }
186
- static get styleUrls() {
187
- return {
188
- "$": ["tttx-filter.css"]
189
- };
190
- }
191
- static get properties() {
192
- return {
193
- "filterKey": {
194
- "type": "string",
195
- "mutable": false,
196
- "complexType": {
197
- "original": "string",
198
- "resolved": "string",
199
- "references": {}
200
- },
201
- "required": false,
202
- "optional": false,
203
- "docs": {
204
- "tags": [],
205
- "text": ""
206
- },
207
- "attribute": "filter-key",
208
- "reflect": false
209
- },
210
- "filterOptions": {
211
- "type": "string",
212
- "mutable": false,
213
- "complexType": {
214
- "original": "string | FilterSettings[]",
215
- "resolved": "FilterSettings[] | string",
216
- "references": {
217
- "FilterSettings": {
218
- "location": "local"
219
- }
220
- }
221
- },
222
- "required": false,
223
- "optional": false,
224
- "docs": {
225
- "tags": [],
226
- "text": ""
227
- },
228
- "attribute": "filter-options",
229
- "reflect": false,
230
- "defaultValue": "[\n { optionIcon: 'cancel', optionIconColor: 'darkred', optionText: 'Expired' },\n { optionIcon: 'warning', optionIconColor: 'orange', optionText: 'Expiring soon' },\n { optionIcon: 'check_circle', optionIconColor: 'green', optionText: 'Active' },\n ]"
231
- },
232
- "showSelectAll": {
233
- "type": "boolean",
234
- "mutable": false,
235
- "complexType": {
236
- "original": "boolean",
237
- "resolved": "boolean",
238
- "references": {}
239
- },
240
- "required": false,
241
- "optional": false,
242
- "docs": {
243
- "tags": [],
244
- "text": ""
245
- },
246
- "attribute": "show-select-all",
247
- "reflect": false,
248
- "defaultValue": "true"
249
- },
250
- "showSearchField": {
251
- "type": "boolean",
252
- "mutable": false,
253
- "complexType": {
254
- "original": "boolean",
255
- "resolved": "boolean",
256
- "references": {}
257
- },
258
- "required": false,
259
- "optional": false,
260
- "docs": {
261
- "tags": [],
262
- "text": ""
263
- },
264
- "attribute": "show-search-field",
265
- "reflect": false,
266
- "defaultValue": "false"
267
- },
268
- "showOptionIcons": {
269
- "type": "boolean",
270
- "mutable": false,
271
- "complexType": {
272
- "original": "boolean",
273
- "resolved": "boolean",
274
- "references": {}
275
- },
276
- "required": false,
277
- "optional": false,
278
- "docs": {
279
- "tags": [],
280
- "text": ""
281
- },
282
- "attribute": "show-option-icons",
283
- "reflect": false,
284
- "defaultValue": "true"
285
- },
286
- "filterButtonStyle": {
287
- "type": "string",
288
- "mutable": false,
289
- "complexType": {
290
- "original": "'list filter' | 'list icon' | 'table icon'",
291
- "resolved": "\"list filter\" | \"list icon\" | \"table icon\"",
292
- "references": {}
293
- },
294
- "required": false,
295
- "optional": false,
296
- "docs": {
297
- "tags": [],
298
- "text": ""
299
- },
300
- "attribute": "filter-button-style",
301
- "reflect": false,
302
- "defaultValue": "'list filter'"
303
- },
304
- "filterHeader": {
305
- "type": "string",
306
- "mutable": false,
307
- "complexType": {
308
- "original": "string",
309
- "resolved": "string",
310
- "references": {}
311
- },
312
- "required": false,
313
- "optional": false,
314
- "docs": {
315
- "tags": [],
316
- "text": ""
317
- },
318
- "attribute": "filter-header",
319
- "reflect": false,
320
- "defaultValue": "'Qualification status'"
321
- },
322
- "defaultFilterOptions": {
323
- "type": "string",
324
- "mutable": false,
325
- "complexType": {
326
- "original": "string[] | string",
327
- "resolved": "string | string[]",
328
- "references": {}
329
- },
330
- "required": false,
331
- "optional": false,
332
- "docs": {
333
- "tags": [],
334
- "text": ""
335
- },
336
- "attribute": "default-filter-options",
337
- "reflect": false
338
- },
339
- "popoverWidth": {
340
- "type": "string",
341
- "mutable": false,
342
- "complexType": {
343
- "original": "string",
344
- "resolved": "string",
345
- "references": {}
346
- },
347
- "required": false,
348
- "optional": false,
349
- "docs": {
350
- "tags": [],
351
- "text": ""
352
- },
353
- "attribute": "popover-width",
354
- "reflect": false,
355
- "defaultValue": "'193px'"
356
- }
357
- };
358
- }
359
- static get states() {
360
- return {
361
- "showPopover": {},
362
- "displayedFilterSettings": {},
363
- "selectedFilters": {},
364
- "filterSearchTerm": {},
365
- "allSelected": {}
366
- };
367
- }
368
- static get events() {
369
- return [{
370
- "method": "filterChangeEvent",
371
- "name": "filterChangeEvent",
372
- "bubbles": true,
373
- "cancelable": true,
374
- "composed": true,
375
- "docs": {
376
- "tags": [],
377
- "text": ""
378
- },
379
- "complexType": {
380
- "original": "FilterChangeEvent",
381
- "resolved": "FilterChangeEvent",
382
- "references": {
383
- "FilterChangeEvent": {
384
- "location": "local"
385
- }
386
- }
387
- }
388
- }];
389
- }
390
- static get elementRef() { return "el"; }
391
- static get listeners() {
392
- return [{
393
- "name": "closeFilter",
394
- "method": "handleCloseFilter",
395
- "target": undefined,
396
- "capture": false,
397
- "passive": false
398
- }];
399
- }
400
- }
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import { h, Host } from '@stencil/core';
3
+ export class TttxFilter {
4
+ constructor() {
5
+ this.filterKey = undefined;
6
+ this.filterOptions = [
7
+ { optionIcon: 'cancel', optionIconColor: 'darkred', optionText: 'Expired' },
8
+ { optionIcon: 'warning', optionIconColor: 'orange', optionText: 'Expiring soon' },
9
+ { optionIcon: 'check_circle', optionIconColor: 'green', optionText: 'Active' },
10
+ ];
11
+ this.showSelectAll = true;
12
+ this.showSearchField = false;
13
+ this.showOptionIcons = true;
14
+ this.filterButtonStyle = 'list filter';
15
+ this.filterHeader = 'Qualification status';
16
+ this.defaultFilterOptions = undefined;
17
+ this.popoverWidth = '193px';
18
+ this.showPopover = false;
19
+ this.displayedFilterSettings = undefined;
20
+ this.selectedFilters = undefined;
21
+ this.filterSearchTerm = '';
22
+ this.allSelected = undefined;
23
+ }
24
+ handleCloseFilter() {
25
+ this.showPopover = false;
26
+ }
27
+ emitFilterEvent() {
28
+ this.filterChangeEvent.emit({
29
+ selectedFilters: this.selectedFilters,
30
+ filterKey: this.filterKey,
31
+ allSelected: this.allSelected,
32
+ });
33
+ }
34
+ onFilterButtonClick() {
35
+ this.togglePopover();
36
+ }
37
+ onCloseButtonClick() {
38
+ this.togglePopover();
39
+ }
40
+ onApplyFilterButtonClick() {
41
+ this.emitFilterEvent();
42
+ this.togglePopover();
43
+ }
44
+ onFilterOptionSelected(selectedOption) {
45
+ this.allSelected = false;
46
+ if (this.selectedFilters.includes(selectedOption)) {
47
+ this.selectedFilters = this.selectedFilters.filter((filter) => filter != selectedOption);
48
+ }
49
+ else {
50
+ this.selectedFilters = [...this.selectedFilters, selectedOption];
51
+ }
52
+ }
53
+ componentWillLoad() {
54
+ this.displayedFilterSettings = this.parseFilterOptions();
55
+ if (this.defaultFilterOptions !== undefined) {
56
+ const parsedDefaultFilterOptions = this.parseDefaultFilterOptions();
57
+ this.selectedFilters = parsedDefaultFilterOptions;
58
+ let allSelected = true;
59
+ this.parseFilterOptions().map(filterOption => {
60
+ if (!this.selectedFilters.includes(filterOption.optionText)) {
61
+ allSelected = false;
62
+ }
63
+ });
64
+ this.allSelected = allSelected;
65
+ }
66
+ else {
67
+ this.allSelected = true;
68
+ this.selectedFilters = this.displayedFilterSettings.map((filterOption) => filterOption.optionText);
69
+ }
70
+ }
71
+ togglePopover() {
72
+ this.showPopover = !this.showPopover;
73
+ this.toggleFilter.emit(this.showPopover);
74
+ // if(!this.showPopover) {
75
+ // // this._focussedElementIndex = -1;
76
+ // }
77
+ }
78
+ // Commented out keyboard interaction for now
79
+ // @Listen('keyup')
80
+ // handleKeyUp(event: KeyboardEvent) {
81
+ // const keyboardEventValue = event.key;
82
+ // if (document.activeElement.id != `filter__${this.filterKey}`) return;
83
+ // if (event.key == " " || event.code == "Space" || event.keyCode == 32) {
84
+ // if (this._focussedElementIndex == 0) {
85
+ // this.onSelectAllClick()
86
+ // } else {
87
+ // const options = this.el.shadowRoot.querySelectorAll('.filter-option') as HTMLElement[];
88
+ // this.onFilterOptionSelected(options[this._focussedElementIndex].textContent)
89
+ // }
90
+ // return;
91
+ // }
92
+ // switch (keyboardEventValue) {
93
+ // case 'Enter':
94
+ // if(!this.showPopover) {
95
+ // this.showPopover=true
96
+ // } else {
97
+ // this.emitFilterEvent()
98
+ // }
99
+ // break;
100
+ // case 'Escape':
101
+ // this.showPopover = false;
102
+ // this._focussedElementIndex = -1;
103
+ // break;
104
+ // case 'ArrowDown':
105
+ // this.showPopover = true;
106
+ // if (this._focussedElementIndex == -1) {
107
+ // this._focussedElementIndex = 0;
108
+ // } else {
109
+ // const options = this.el.shadowRoot.querySelectorAll('.filter-option') as HTMLElement[];
110
+ // const currentOption = options[this._focussedElementIndex] as HTMLElement;
111
+ // currentOption.blur();
112
+ // // options[this._focussedElementIndex].focus();
113
+ // this._focussedElementIndex + 1 < options.length ? this._focussedElementIndex++ : (this._focussedElementIndex = 0);
114
+ // }
115
+ // break;
116
+ // case 'ArrowUp':
117
+ // if (this._focussedElementIndex == -1) {
118
+ // this.showPopover = true;
119
+ // this._focussedElementIndex = 0;
120
+ // } else {
121
+ // const options = this.el.shadowRoot.querySelectorAll('.filter-option') as HTMLElement[];
122
+ // const currentOption = options[this._focussedElementIndex] as HTMLElement;
123
+ // currentOption.blur();
124
+ // // options[this._focussedElementIndex].focus();
125
+ // this._focussedElementIndex > 0 ? this._focussedElementIndex-- : (this._focussedElementIndex = options.length - 1);
126
+ // }
127
+ // break;
128
+ // }
129
+ // }
130
+ handleFilterChange(event) {
131
+ const target = event.target;
132
+ this.filterSearchTerm = target.value;
133
+ const filteredResults = this.parseFilterOptions().filter((filterOption) => {
134
+ const lowercaseOption = filterOption.optionText.toLowerCase();
135
+ const filterTerm = this.filterSearchTerm.toLowerCase();
136
+ return lowercaseOption.includes(filterTerm);
137
+ });
138
+ this.displayedFilterSettings = filteredResults;
139
+ }
140
+ onSelectAllClick() {
141
+ this.allSelected = !this.allSelected;
142
+ if (this.allSelected) {
143
+ this.displayedFilterSettings.forEach((filterSetting) => { this.selectedFilters = [...this.selectedFilters, filterSetting.optionText]; });
144
+ }
145
+ else {
146
+ this.selectedFilters = [];
147
+ }
148
+ }
149
+ getFilterButtonClassName(buttonStyle) {
150
+ switch (buttonStyle) {
151
+ case 'table icon': {
152
+ return '--table-icon';
153
+ }
154
+ case 'list icon': {
155
+ return '--list-icon';
156
+ }
157
+ default: {
158
+ return '';
159
+ }
160
+ }
161
+ }
162
+ parseFilterOptions() {
163
+ return typeof this.filterOptions === 'string' ? JSON.parse(this.filterOptions) : this.filterOptions;
164
+ }
165
+ parseDefaultFilterOptions() {
166
+ return typeof this.defaultFilterOptions === 'string' ? JSON.parse(this.defaultFilterOptions) : this.defaultFilterOptions;
167
+ }
168
+ render() {
169
+ const filterPopoverContainerClassNameModifier = this.showSearchField ? '--with-search-field' : '';
170
+ const selectAllCheckboxIcon = this.allSelected ? 'check_box' : 'check_box_outline_blank';
171
+ const selectAllCheckboxColor = this.allSelected ? 'blue' : 'grey';
172
+ const buttonStyleClassNameModifier = this.getFilterButtonClassName(this.filterButtonStyle);
173
+ const filterKey = `filter__${this.filterKey}`;
174
+ return (h(Host, { id: filterKey }, h("div", { class: 'filter-container' }, h("button", { class: `filter-button ${buttonStyleClassNameModifier}`, type: 'button', onClick: this.onFilterButtonClick.bind(this) }, h("tttx-icon", { icon: 'filter_list', class: 'filter-icon', color: 'black' }), "Filter"), this.showPopover && (h("div", { class: `filter-popover-container ${filterPopoverContainerClassNameModifier}`, style: { width: this.popoverWidth } }, h("div", { class: 'filter-header' }, this.filterHeader), this.showSearchField ? (h("div", { class: 'search-field-container' }, h("tttx-icon", { icon: 'search', class: 'search-icon' }), h("input", { type: 'text', class: 'search-input', placeholder: 'Search', value: this.filterSearchTerm, onInput: this.handleFilterChange.bind(this) }))) : (''), h("div", { class: 'filter-options-container' }, this.showSelectAll ? (h("div", { class: 'filter-option', tabIndex: -1, onClick: this.onSelectAllClick.bind(this) }, h("tttx-icon", { icon: selectAllCheckboxIcon, color: selectAllCheckboxColor, class: 'select-all-icon' }), h("label", { class: 'filter-label' }, "Select all"))) : (''), this.displayedFilterSettings.map((option) => {
175
+ const checkboxIcon = this.selectedFilters.includes(option.optionText) ? 'check_box' : 'check_box_outline_blank';
176
+ const checkboxColor = this.selectedFilters.includes(option.optionText) ? 'blue' : 'grey';
177
+ return h("div", { class: 'filter-option', tabIndex: -1, onClick: () => this.onFilterOptionSelected(option.optionText), key: option.optionText }, h("tttx-icon", { icon: checkboxIcon, color: checkboxColor, class: 'checkbox-icon' }), this.showOptionIcons && h("tttx-icon", { icon: option.optionIcon, color: option.optionIconColor }), h("label", { class: 'filter-label' }, option.optionText));
178
+ })), h("div", { class: 'filter-popover-button-container' }, h("button", { type: 'button', class: 'close-button', onClick: this.onCloseButtonClick.bind(this) }, "Close"), h("button", { type: 'button', class: 'apply-button', onClick: this.onApplyFilterButtonClick.bind(this) }, "Apply")))))));
179
+ }
180
+ static get is() { return "tttx-filter"; }
181
+ static get encapsulation() { return "shadow"; }
182
+ static get originalStyleUrls() {
183
+ return {
184
+ "$": ["tttx-filter.scss"]
185
+ };
186
+ }
187
+ static get styleUrls() {
188
+ return {
189
+ "$": ["tttx-filter.css"]
190
+ };
191
+ }
192
+ static get properties() {
193
+ return {
194
+ "filterKey": {
195
+ "type": "string",
196
+ "mutable": false,
197
+ "complexType": {
198
+ "original": "string",
199
+ "resolved": "string",
200
+ "references": {}
201
+ },
202
+ "required": false,
203
+ "optional": false,
204
+ "docs": {
205
+ "tags": [],
206
+ "text": ""
207
+ },
208
+ "attribute": "filter-key",
209
+ "reflect": false
210
+ },
211
+ "filterOptions": {
212
+ "type": "string",
213
+ "mutable": false,
214
+ "complexType": {
215
+ "original": "string | FilterSettings[]",
216
+ "resolved": "FilterSettings[] | string",
217
+ "references": {
218
+ "FilterSettings": {
219
+ "location": "local"
220
+ }
221
+ }
222
+ },
223
+ "required": false,
224
+ "optional": false,
225
+ "docs": {
226
+ "tags": [],
227
+ "text": ""
228
+ },
229
+ "attribute": "filter-options",
230
+ "reflect": false,
231
+ "defaultValue": "[\n { optionIcon: 'cancel', optionIconColor: 'darkred', optionText: 'Expired' },\n { optionIcon: 'warning', optionIconColor: 'orange', optionText: 'Expiring soon' },\n { optionIcon: 'check_circle', optionIconColor: 'green', optionText: 'Active' },\n ]"
232
+ },
233
+ "showSelectAll": {
234
+ "type": "boolean",
235
+ "mutable": false,
236
+ "complexType": {
237
+ "original": "boolean",
238
+ "resolved": "boolean",
239
+ "references": {}
240
+ },
241
+ "required": false,
242
+ "optional": false,
243
+ "docs": {
244
+ "tags": [],
245
+ "text": ""
246
+ },
247
+ "attribute": "show-select-all",
248
+ "reflect": false,
249
+ "defaultValue": "true"
250
+ },
251
+ "showSearchField": {
252
+ "type": "boolean",
253
+ "mutable": false,
254
+ "complexType": {
255
+ "original": "boolean",
256
+ "resolved": "boolean",
257
+ "references": {}
258
+ },
259
+ "required": false,
260
+ "optional": false,
261
+ "docs": {
262
+ "tags": [],
263
+ "text": ""
264
+ },
265
+ "attribute": "show-search-field",
266
+ "reflect": false,
267
+ "defaultValue": "false"
268
+ },
269
+ "showOptionIcons": {
270
+ "type": "boolean",
271
+ "mutable": false,
272
+ "complexType": {
273
+ "original": "boolean",
274
+ "resolved": "boolean",
275
+ "references": {}
276
+ },
277
+ "required": false,
278
+ "optional": false,
279
+ "docs": {
280
+ "tags": [],
281
+ "text": ""
282
+ },
283
+ "attribute": "show-option-icons",
284
+ "reflect": false,
285
+ "defaultValue": "true"
286
+ },
287
+ "filterButtonStyle": {
288
+ "type": "string",
289
+ "mutable": false,
290
+ "complexType": {
291
+ "original": "'list filter' | 'list icon' | 'table icon'",
292
+ "resolved": "\"list filter\" | \"list icon\" | \"table icon\"",
293
+ "references": {}
294
+ },
295
+ "required": false,
296
+ "optional": false,
297
+ "docs": {
298
+ "tags": [],
299
+ "text": ""
300
+ },
301
+ "attribute": "filter-button-style",
302
+ "reflect": false,
303
+ "defaultValue": "'list filter'"
304
+ },
305
+ "filterHeader": {
306
+ "type": "string",
307
+ "mutable": false,
308
+ "complexType": {
309
+ "original": "string",
310
+ "resolved": "string",
311
+ "references": {}
312
+ },
313
+ "required": false,
314
+ "optional": false,
315
+ "docs": {
316
+ "tags": [],
317
+ "text": ""
318
+ },
319
+ "attribute": "filter-header",
320
+ "reflect": false,
321
+ "defaultValue": "'Qualification status'"
322
+ },
323
+ "defaultFilterOptions": {
324
+ "type": "string",
325
+ "mutable": false,
326
+ "complexType": {
327
+ "original": "string[] | string",
328
+ "resolved": "string | string[]",
329
+ "references": {}
330
+ },
331
+ "required": false,
332
+ "optional": false,
333
+ "docs": {
334
+ "tags": [],
335
+ "text": ""
336
+ },
337
+ "attribute": "default-filter-options",
338
+ "reflect": false
339
+ },
340
+ "popoverWidth": {
341
+ "type": "string",
342
+ "mutable": false,
343
+ "complexType": {
344
+ "original": "string",
345
+ "resolved": "string",
346
+ "references": {}
347
+ },
348
+ "required": false,
349
+ "optional": false,
350
+ "docs": {
351
+ "tags": [],
352
+ "text": ""
353
+ },
354
+ "attribute": "popover-width",
355
+ "reflect": false,
356
+ "defaultValue": "'193px'"
357
+ }
358
+ };
359
+ }
360
+ static get states() {
361
+ return {
362
+ "showPopover": {},
363
+ "displayedFilterSettings": {},
364
+ "selectedFilters": {},
365
+ "filterSearchTerm": {},
366
+ "allSelected": {}
367
+ };
368
+ }
369
+ static get events() {
370
+ return [{
371
+ "method": "filterChangeEvent",
372
+ "name": "filterChangeEvent",
373
+ "bubbles": true,
374
+ "cancelable": true,
375
+ "composed": true,
376
+ "docs": {
377
+ "tags": [],
378
+ "text": ""
379
+ },
380
+ "complexType": {
381
+ "original": "FilterChangeEvent",
382
+ "resolved": "FilterChangeEvent",
383
+ "references": {
384
+ "FilterChangeEvent": {
385
+ "location": "local"
386
+ }
387
+ }
388
+ }
389
+ }, {
390
+ "method": "toggleFilter",
391
+ "name": "toggleFilter",
392
+ "bubbles": true,
393
+ "cancelable": true,
394
+ "composed": true,
395
+ "docs": {
396
+ "tags": [],
397
+ "text": ""
398
+ },
399
+ "complexType": {
400
+ "original": "boolean",
401
+ "resolved": "boolean",
402
+ "references": {}
403
+ }
404
+ }];
405
+ }
406
+ static get elementRef() { return "el"; }
407
+ static get listeners() {
408
+ return [{
409
+ "name": "closeFilter",
410
+ "method": "handleCloseFilter",
411
+ "target": undefined,
412
+ "capture": false,
413
+ "passive": false
414
+ }];
415
+ }
416
+ }