nve-designsystem 3.2.0 → 3.3.0

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 (197) hide show
  1. package/chunks/chunk.2PCBEMQZ.js +163 -226
  2. package/chunks/chunk.36O46B5H.js +15 -15
  3. package/chunks/chunk.4TUIT776.js +78 -96
  4. package/chunks/chunk.5JY5FUCG.js +965 -1245
  5. package/chunks/chunk.5P45LHIX.js +668 -96
  6. package/chunks/chunk.6CTB5ZDJ.js +107 -100
  7. package/chunks/chunk.B4BZKR24.js +29 -39
  8. package/chunks/chunk.D5YQDJ7X.js +122 -166
  9. package/chunks/chunk.EA437WHD.js +5 -5
  10. package/chunks/chunk.GI7VDIWX.js +14 -15
  11. package/chunks/chunk.GMYPQTFK.js +18 -20
  12. package/chunks/chunk.HVTXQL7M.js +191 -215
  13. package/chunks/chunk.IKV4VH3T.js +18 -16
  14. package/chunks/chunk.IVVHNXMC.js +26 -27
  15. package/chunks/chunk.JHOXTQXA.js +65 -74
  16. package/chunks/chunk.JXOKFADN.js +63 -90
  17. package/chunks/chunk.K7JGTRV7.js +24 -23
  18. package/chunks/chunk.KPLQLAWP.js +132 -147
  19. package/chunks/chunk.LD4M4QGE.js +61 -74
  20. package/chunks/chunk.MSKEYBDI.js +53 -71
  21. package/chunks/chunk.NYIIDP5N.js +39 -45
  22. package/chunks/chunk.RWUUFNUL.js +91 -114
  23. package/chunks/chunk.SAPQLUO4.js +249 -228
  24. package/chunks/chunk.SI4ACBFK.js +139 -5
  25. package/chunks/chunk.TP2GB2HO.js +361 -460
  26. package/chunks/chunk.UDWRA64J.js +185 -223
  27. package/chunks/chunk.URTPIBTY.js +119 -151
  28. package/chunks/chunk.VESXC477.js +63 -66
  29. package/chunks/chunk.XA43ZQPC.js +198 -313
  30. package/chunks/chunk.XQ2OKYYA.js +25 -26
  31. package/chunks/chunk.XZNBUGX7.js +6 -6
  32. package/chunks/chunk.YHLNUJ7P.js +93 -116
  33. package/chunks/chunk.ZH2AND3P.js +340 -399
  34. package/chunks/chunk.ZL53POKZ.js +61 -156
  35. package/chunks/chunk.js +20 -0
  36. package/chunks/class-map.js +49 -45
  37. package/chunks/decorate.js +105 -0
  38. package/chunks/directive-helpers.js +5 -7
  39. package/chunks/if-defined.js +5 -5
  40. package/chunks/lit.js +525 -0
  41. package/chunks/live.js +24 -24
  42. package/chunks/nve-alert.component.js +163 -0
  43. package/chunks/nve-carousel-item.component.js +36 -0
  44. package/chunks/nve-carousel.component.js +41 -0
  45. package/chunks/nve-checkbox-group.component.js +114 -0
  46. package/chunks/nve-checkbox.component.js +28 -0
  47. package/chunks/nve-dialog.component.js +39 -0
  48. package/chunks/nve-divider.component.js +23 -0
  49. package/chunks/nve-drawer.component.js +40 -0
  50. package/chunks/nve-dropdown.component.js +83 -0
  51. package/chunks/nve-input.component.js +80 -0
  52. package/chunks/nve-label.component.js +89 -0
  53. package/chunks/nve-menu-item.component.js +35 -0
  54. package/chunks/nve-menu.component.js +17 -0
  55. package/chunks/nve-option.component.js +27 -0
  56. package/chunks/nve-popup.component.js +15 -0
  57. package/chunks/nve-radio-button.component.js +20 -0
  58. package/chunks/nve-radio-group.component.js +78 -0
  59. package/chunks/nve-radio.component.js +18 -0
  60. package/chunks/nve-select.component.js +58 -0
  61. package/chunks/nve-skeleton.component.js +20 -0
  62. package/chunks/nve-spinner.component.js +23 -0
  63. package/chunks/nve-tooltip.component.js +20 -0
  64. package/chunks/nve-warning-level.component.js +57 -0
  65. package/chunks/ref.js +75 -84
  66. package/chunks/shoelace.js +10006 -0
  67. package/chunks/static-html.js +27 -0
  68. package/chunks/unsafe-html.js +24 -20
  69. package/chunks/updateInvalidProperty.js +7 -7
  70. package/chunks/watch.js +20 -20
  71. package/components/nve-accordion/nve-accordion.component.js +24 -30
  72. package/components/nve-accordion-item/nve-accordion-item.component.js +30 -64
  73. package/components/nve-accordion-item/nve-accordion-item.styles.js +5 -5
  74. package/components/nve-alert/nve-alert.component.js +2 -227
  75. package/components/nve-alert/nve-alert.styles.js +45 -27
  76. package/components/nve-badge/nve-badge.component.js +41 -45
  77. package/components/nve-badge/nve-badge.styles.js +33 -31
  78. package/components/nve-button/nve-button.component.d.ts +110 -10
  79. package/components/nve-button/nve-button.component.js +146 -39
  80. package/components/nve-button/nve-button.styles.js +214 -157
  81. package/components/nve-carousel/nve-carousel.component.js +2 -47
  82. package/components/nve-carousel/nve-carousel.styles.js +6 -6
  83. package/components/nve-carousel-item/nve-carousel-item.component.js +2 -40
  84. package/components/nve-carousel-item/nve-carousel-item.styles.js +5 -5
  85. package/components/nve-carousel-thumbnail/nve-carousel-thumbnail.component.js +44 -54
  86. package/components/nve-carousel-thumbnail/nve-carousel-thumbnail.styles.js +5 -5
  87. package/components/nve-checkbox/nve-checkbox.component.js +2 -34
  88. package/components/nve-checkbox/nve-checkbox.styles.js +7 -7
  89. package/components/nve-checkbox-group/nve-checkbox-group.component.js +2 -152
  90. package/components/nve-checkbox-group/nve-checkbox-group.styles.js +5 -5
  91. package/components/nve-combobox/nve-combobox.component.js +222 -440
  92. package/components/nve-combobox/nve-combobox.styles.js +6 -6
  93. package/components/nve-darkmode-switch/nve-darkmode-switch.component.js +32 -38
  94. package/components/nve-dialog/nve-dialog-styles.js +6 -6
  95. package/components/nve-dialog/nve-dialog.component.js +2 -54
  96. package/components/nve-divider/nve-divider.component.js +2 -30
  97. package/components/nve-drawer/nve-drawer.component.js +2 -44
  98. package/components/nve-drawer/nve-drawer.styles.js +6 -6
  99. package/components/nve-dropdown/nve-dropdown.component.js +2 -79
  100. package/components/nve-dropdown/nve-dropdown.styles.js +5 -5
  101. package/components/nve-heading/nve-heading.component.d.ts +29 -0
  102. package/components/nve-heading/nve-heading.component.js +45 -0
  103. package/components/nve-heading/nve-heading.styles.d.ts +2 -0
  104. package/components/nve-heading/nve-heading.styles.js +41 -0
  105. package/components/nve-icon/nve-icon.component.js +145 -164
  106. package/components/nve-icon/nve-icon.styles.js +11 -6
  107. package/components/nve-icon/offline-icons.js +16 -13
  108. package/components/nve-input/nve-input.component.js +2 -100
  109. package/components/nve-input/nve-input.styles.js +5 -5
  110. package/components/nve-label/nve-label.component.js +2 -115
  111. package/components/nve-label/nve-label.styles.js +5 -5
  112. package/components/nve-link-card/nve-link-card.component.d.ts +5 -2
  113. package/components/nve-link-card/nve-link-card.component.js +44 -80
  114. package/components/nve-link-card/nve-link-card.styles.js +71 -66
  115. package/components/nve-menu/nve-menu.component.js +2 -22
  116. package/components/nve-menu/nve-menu.styles.js +5 -5
  117. package/components/nve-menu-item/nve-menu-item.component.js +2 -43
  118. package/components/nve-menu-item/nve-menu-item.styles.js +7 -7
  119. package/components/nve-message-card/nve-message-card.component.js +61 -91
  120. package/components/nve-message-card/nve-message-card.styles.js +24 -27
  121. package/components/nve-navigation-card/nve-navigation-card.component.d.ts +52 -0
  122. package/components/nve-navigation-card/nve-navigation-card.component.js +60 -0
  123. package/components/nve-navigation-card/nve-navigation-card.styles.d.ts +2 -0
  124. package/components/nve-navigation-card/nve-navigation-card.styles.js +112 -0
  125. package/components/nve-option/nve-option.component.js +2 -41
  126. package/components/nve-option/nve-option.styles.js +5 -5
  127. package/components/nve-paragraph/nve-paragraph.component.d.ts +26 -0
  128. package/components/nve-paragraph/nve-paragraph.component.js +26 -0
  129. package/components/nve-paragraph/nve-paragraph.styles.d.ts +2 -0
  130. package/components/nve-paragraph/nve-paragraph.styles.js +105 -0
  131. package/components/nve-popup/nve-popup.component.js +2 -22
  132. package/components/nve-radio/nve-radio.component.js +2 -23
  133. package/components/nve-radio/nve-radio.styles.js +5 -5
  134. package/components/nve-radio-button/nve-radio-button.component.js +2 -25
  135. package/components/nve-radio-button/nve-radio-button.styles.js +5 -5
  136. package/components/nve-radio-group/nve-radio-group.component.js +2 -119
  137. package/components/nve-radio-group/nve-radio-group.styles.js +5 -5
  138. package/components/nve-relative-time/nve-relative-time.component.js +21 -56
  139. package/components/nve-relative-time/nve-relative-time.styles.js +5 -5
  140. package/components/nve-select/nve-select.component.js +2 -80
  141. package/components/nve-select/nve-select.styles.js +5 -5
  142. package/components/nve-skeleton/nve-skeleton.component.js +2 -27
  143. package/components/nve-skeleton/nve-skeleton.styles.js +5 -5
  144. package/components/nve-spinner/nve-spinner.component.js +2 -31
  145. package/components/nve-stepper/nve-step/nve-step.component.js +113 -173
  146. package/components/nve-stepper/nve-step/nve-step.styles.js +12 -12
  147. package/components/nve-stepper/nve-stepper-mobile.component.js +37 -49
  148. package/components/nve-stepper/nve-stepper-mobile.styles.js +7 -7
  149. package/components/nve-stepper/nve-stepper.component.js +94 -139
  150. package/components/nve-stepper/nve-stepper.styles.js +5 -5
  151. package/components/nve-switch/nve-switch.component.js +75 -107
  152. package/components/nve-switch/nve-switch.styles.js +7 -7
  153. package/components/nve-tab/nve-tab.component.js +30 -42
  154. package/components/nve-tab/nve-tab.styles.js +7 -7
  155. package/components/nve-tab-group/nve-tab-group.component.js +180 -260
  156. package/components/nve-tab-group/nve-tab-group.styles.js +5 -5
  157. package/components/nve-tab-panel/nve-tab-panel.component.js +21 -31
  158. package/components/nve-tab-panel/nve-tab-panel.styles.js +5 -5
  159. package/components/nve-tag/nve-tag.component.d.ts +3 -3
  160. package/components/nve-tag/nve-tag.component.js +71 -72
  161. package/components/nve-tag/nve-tag.styles.js +23 -22
  162. package/components/nve-textarea/nve-textarea.component.d.ts +3 -1
  163. package/components/nve-textarea/nve-textarea.component.js +112 -173
  164. package/components/nve-textarea/nve-textarea.styles.js +10 -5
  165. package/components/nve-tooltip/nve-tooltip.component.js +2 -30
  166. package/components/nve-tooltip/nve-tooltip.styles.js +5 -5
  167. package/components/nve-warning-level/nve-warning-level.component.js +2 -78
  168. package/components/nve-warning-level/nve-warning-level.styles.js +7 -7
  169. package/css/global.css +13 -55
  170. package/css/nve.css +1048 -393
  171. package/css/nve_dark.css +406 -305
  172. package/css/rme.css +1050 -395
  173. package/css/rme_dark.css +408 -307
  174. package/css/shoelace-styles.css +539 -0
  175. package/css/varsom.css +1046 -391
  176. package/css/varsom_dark.css +404 -303
  177. package/custom-elements.json +2905 -12389
  178. package/fonts/LICENSE.txt +37 -0
  179. package/fonts/SourceSans3-VariableFont_wght.woff2 +0 -0
  180. package/interfaces/NveComponent.interface.js +0 -1
  181. package/nve-designsystem.d.ts +5 -0
  182. package/nve-designsystem.js +46 -86
  183. package/package.json +26 -8
  184. package/registerIcons/systemLibraryCustomization.js +23 -91
  185. package/vite-env.d.js +0 -1
  186. package/chunks/chunk.3RPBFEDE.js +0 -162
  187. package/chunks/chunk.JCXLDPQF.js +0 -225
  188. package/chunks/chunk.JQBT7BOV.js +0 -8446
  189. package/chunks/chunk.MAQXLKQ7.js +0 -598
  190. package/chunks/lit-element.js +0 -508
  191. package/chunks/property.js +0 -37
  192. package/chunks/query.js +0 -13
  193. package/chunks/state.js +0 -7
  194. package/chunks/static.js +0 -26
  195. package/nve-designsystem.css +0 -1
  196. package/vscode.css-custom-data.json +0 -621
  197. package/vscode.html-custom-data.json +0 -2354
@@ -1,351 +1,194 @@
1
- import u from "./nve-combobox.styles.js";
2
- import { a as d, x as h } from "../../chunks/lit-element.js";
3
- import { e as f, n as b } from "../../chunks/ref.js";
4
- import { o as v } from "../../chunks/unsafe-html.js";
5
- import { n as r, t as y } from "../../chunks/property.js";
6
- import { r as p } from "../../chunks/state.js";
7
- import "../nve-popup/nve-popup.component.js";
8
- import "../nve-input/nve-input.component.js";
9
- import "../nve-menu/nve-menu.component.js";
10
- import "../nve-option/nve-option.component.js";
1
+ import { a as e, t } from "../../chunks/lit.js";
2
+ import { a as n, o as r, s as i, t as a } from "../../chunks/decorate.js";
3
+ import { t as o } from "../../chunks/unsafe-html.js";
4
+ import { n as s, t as c } from "../../chunks/ref.js";
11
5
  import "../nve-icon/nve-icon.component.js";
12
- var m = Object.defineProperty, g = Object.getOwnPropertyDescriptor, o = (e, t, i, l) => {
13
- for (var a = l > 1 ? void 0 : l ? g(t, i) : t, n = e.length - 1, c; n >= 0; n--)
14
- (c = e[n]) && (a = (l ? c(t, i, a) : c(a)) || a);
15
- return l && a && m(t, i, a), a;
16
- };
17
- let s = class extends d {
18
- /**
19
- * Oppretter en ny instans av NveCombobox.
20
- */
21
- constructor() {
22
- super(), this.helpText = void 0, this.requiredLabel = "*Obligatorisk", this.errorMessage = "-!ERROR!-", this.options = [], this.max = 1 / 0, this.min = void 0, this.disabled = !1, this.filled = !1, this.required = !1, this.size = "medium", this.testId = void 0, this.listWithSearchHits = [], this.displaySearchResult = !1, this.selectedOptions = [], this.inputValue = "", this.isPopupActive = !1, this.error = !1, this.prefixInputRef = f(), this.boundHandleOutsideClick = this.handleOutsideClick.bind(this);
23
- }
24
- /**
25
- * Kalles første gang komponenten er rendret.
26
- * Setter selectedOptions basert options med selected=true.
27
- */
28
- firstUpdated() {
29
- this.selectedOptions = this.options.filter((e) => e?.selected);
30
- }
31
- /**
32
- * Legger til event listener for å håndtere klikk utenfor komponenten.
33
- */
34
- connectedCallback() {
35
- super.connectedCallback(), document.addEventListener("click", this.boundHandleOutsideClick, !0), this.closest("form")?.addEventListener("submit", this.handleSubmit.bind(this));
36
- }
37
- /**
38
- * Fjerner event listener når komponenten fjernes fra DOM.
39
- */
40
- disconnectedCallback() {
41
- document.removeEventListener("click", this.boundHandleOutsideClick, !0), this.closest("form")?.removeEventListener("submit", this.handleSubmit.bind(this)), super.disconnectedCallback();
42
- }
43
- /**
44
- * Håndterer klikk utenfor komponenten for å lukke popupen.
45
- * @param event MouseEvent
46
- */
47
- handleOutsideClick(e) {
48
- !this.shadowRoot?.contains(e.target) && !this.contains(e.target) && this.isPopupActive && (this.setPopupActive(!1), this.listWithSearchHits = [], this.inputValue = "", this.displaySearchResult = !1);
49
- }
50
- /**
51
- * Sender et custom event med de valgte alternativene.
52
- * @param options Valgte alternativer som skal sendes med eventet
53
- * @event value Returnerer de valgte alternativene
54
- */
55
- emitValueEvent(e) {
56
- this.dispatchEvent(
57
- new CustomEvent("value", {
58
- bubbles: !0,
59
- cancelable: !1,
60
- composed: !0,
61
- detail: {
62
- value: e
63
- }
64
- })
65
- );
66
- }
67
- /**
68
- * Sender et custom event som indikerer valideringsfeil.
69
- * @event invalid Indikerer at validering har feilet
70
- */
71
- emitInvalidEvent() {
72
- this.dispatchEvent(
73
- new CustomEvent("invalid", {
74
- bubbles: !0,
75
- cancelable: !1,
76
- composed: !0
77
- })
78
- );
79
- }
80
- /**
81
- * Setter fokus på input feltet som er inne i prefix slotten
82
- * og oppdaterer listen med søketreff.
83
- * @returns {void}
84
- */
85
- handleFocus() {
86
- this.displaySearchResult = !1, this.focusPrefixInputField(), this.handleInput(), this.setPopupActive(!0);
87
- }
88
- /**
89
- * Setter fokus på input feltet som er inne i prefix slotten
90
- * og åpner popupen.
91
- * @returns {void}
92
- */
93
- handleClick() {
94
- this.focusPrefixInputField(), this.setPopupActive(!0);
95
- }
96
- /**
97
- * Toggle for å aktivere eller deaktivere popupen.
98
- * @param event Event
99
- * @returns {void}
100
- */
101
- togglePopupActive(e) {
102
- e.stopPropagation(), this.setPopupActive(!this.isPopupActive);
103
- }
104
- handleSubmit(e) {
105
- e.preventDefault(), this.checkValidity();
106
- }
107
- checkValidity() {
108
- const e = this.selectedOptions.length, t = this.min !== void 0 ? this.min : 0;
109
- e >= t && e <= this.max ? this.resetValidation() : this.makeInvalid();
110
- }
111
- makeInvalid() {
112
- this.errorMessage = this.errorMessage, this.error = !0, this.emitInvalidEvent(), this.toggleValidationAttributes(!1);
113
- }
114
- resetValidation() {
115
- this.error = !1, this.toggleValidationAttributes(!0);
116
- }
117
- toggleValidationAttributes(e) {
118
- this.toggleAttribute("data-valid", e), this.toggleAttribute("data-user-valid", e), this.toggleAttribute("data-invalid", !e), this.toggleAttribute("data-user-invalid", !e);
119
- }
120
- /**
121
- * Håndterer input i søkefeltet og oppdaterer søkeresultater.
122
- * @returns {void}
123
- */
124
- handleInput() {
125
- const e = this.prefixInputRef.value;
126
- if (e && e.value) {
127
- this.inputValue = e.value;
128
- const t = this.searchForOptions(e.value);
129
- this.updateListWithSearchHits(t);
130
- } else
131
- this.displaySearchResult = !1;
132
- }
133
- /**
134
- * Håndterer tastaturnavigasjon i inputfeltet, ikke popupen.
135
- * @param event KeyboardEvent
136
- * @returns {void}
137
- */
138
- handleKeyboardNavigationInput(e) {
139
- if (!this.disabled)
140
- switch (e.key) {
141
- case "ArrowDown":
142
- e.preventDefault(), this.setPopupActive(!0), this.shadowRoot?.querySelector("nve-option")?.focus();
143
- return;
144
- case "ArrowUp":
145
- e.preventDefault(), this.setPopupActive(!0);
146
- const t = this.shadowRoot?.querySelectorAll("nve-option");
147
- t && setTimeout(() => {
148
- t[t.length - 1].focus();
149
- }, 0);
150
- return;
151
- case "Escape":
152
- !this.isPopupActive && this.inputValue.length > 0 && (this.inputValue = ""), this.setPopupActive(!1);
153
- return;
154
- case "Enter":
155
- case "Space":
156
- this.setPopupActive(!this.isPopupActive);
157
- return;
158
- case "Backspace":
159
- this.inputValue === "" && this.focusLastTag();
160
- return;
161
- default:
162
- this.isAPrintableCharacterPressed(e) && this.focusPrefixInputField();
163
- }
164
- }
165
- /**
166
- * Håndterer tastaturnavigasjon i popupen, ikke inputfeltet. selectOptionKeyDown håndterer enter .
167
- * @param event KeyboardEvent
168
- * @returns {void}
169
- */
170
- handleKeyboardNavigationListBox(e) {
171
- if (!this.disabled)
172
- switch (e.key) {
173
- case "Escape":
174
- this.setPopupActive(!1);
175
- return;
176
- case "ArrowUp":
177
- case "ArrowDown":
178
- this.focusNextOption(e.key), e.preventDefault();
179
- return;
180
- case "ArrowRight":
181
- case "ArrowLeft":
182
- case "BackSpace":
183
- this.focusPrefixInputField();
184
- return;
185
- default:
186
- this.isAPrintableCharacterPressed(e) && this.focusPrefixInputField();
187
- }
188
- }
189
- /**
190
- * Oppdaterer listen med søkeresultater og viser popupen.
191
- * @param options Liste med søkeresultater
192
- * @returns {void}
193
- */
194
- updateListWithSearchHits(e) {
195
- this.listWithSearchHits = [...e], this.displaySearchResult = !0, this.setPopupActive(!0);
196
- }
197
- /**
198
- * Søker etter alternativer som matcher søketeksten.
199
- * @param searchString Søketekst
200
- * @returns {Option[]} Liste med alternativer som matcher søket
201
- */
202
- searchForOptions(e) {
203
- const t = e.toLowerCase();
204
- return this.options.filter((i) => i.label.toLowerCase().includes(t)).sort((i, l) => {
205
- const a = i.label.toLowerCase().startsWith(t), n = l.label.toLowerCase().startsWith(t);
206
- return a && !n ? -1 : !a && n ? 1 : 0;
207
- });
208
- }
209
- /**
210
- * Velger et alternativ.
211
- * @param option Alternativet som skal velges
212
- * @returns {void}
213
- */
214
- selectOption(e) {
215
- if (this.disabled || this.isMaxNumberOfOptionsSelected()) return;
216
- const t = [...this.options], i = t.findIndex((l) => l.value === e.value);
217
- i !== -1 && (t[i].selected = !0, this.selectedOptions.push(e), this.options = t, this.inputValue = "", this.displaySearchResult = !1, this.setPopupActive(!1), this.focusPrefixInputField(), this.emitValueEvent(this.selectedOptions));
218
- }
219
- /**
220
- * Velger et alternativ med tastatur.
221
- * @param option Alternativet som skal velges
222
- * @param event KeyboardEvent
223
- * @returns {void}
224
- */
225
- selectOptionKeyDown(e, t) {
226
- t.key === "Enter" && this.selectOption(e);
227
- }
228
- /**
229
- * Fjerner et valgt alternativ.
230
- * @param option Alternativet som skal fjernes
231
- * @returns {void}
232
- */
233
- unSelectOption(e) {
234
- if (this.disabled) return;
235
- const t = [...this.options], i = [...this.selectedOptions], l = t.findIndex((n) => n.value === e.value), a = i.findIndex(
236
- (n) => n.value === e.value
237
- );
238
- l !== -1 && (t[l].selected = !1), a !== -1 && i.splice(a, 1), this.selectedOptions = i, this.options = t, this.emitValueEvent(i);
239
- }
240
- /**
241
- * Fjerner ett valgt alternativ med tastatur.
242
- * @param option Alternativet som skal fjernes
243
- * @param event KeyboardEvent
244
- * @returns {void}
245
- */
246
- unSelectOptionKeyDown(e, t) {
247
- if (t.key === "Enter") {
248
- this.unSelectOption(e);
249
- return;
250
- }
251
- }
252
- /**
253
- * Fjerner en tag med tastatur.
254
- * @param option Alternativet som skal fjernes
255
- * @param event KeyboardEvent
256
- * @returns {void}
257
- */
258
- unSelectOptionKeyDownTag(e, t) {
259
- if (!(t instanceof KeyboardEvent && t.key !== "Backspace") && (this.unSelectOption(e), this.selectedOptions.length === 0)) {
260
- this.focusPrefixInputField();
261
- return;
262
- }
263
- }
264
- /**
265
- * Setter popupens aktive tilstand.
266
- * @param active true for å åpne popup, false for å lukke
267
- */
268
- setPopupActive(e) {
269
- this.isPopupActive === e || this.disabled || (this.isPopupActive = e, this.shadowRoot?.querySelector(".open-icon")?.classList?.toggle("active"));
270
- }
271
- /**
272
- * Basert på om brukeren presser ArrowDown eller ArrowUp, fokuser på riktig element
273
- * @param option Event.key string ArrowDown || ArrowUp
274
- */
275
- focusNextOption(e) {
276
- const t = Array.from(this.shadowRoot?.querySelectorAll("nve-option") || []), i = t.findIndex((a) => a === this.shadowRoot?.activeElement);
277
- let l = i;
278
- e === "ArrowDown" ? i < t.length - 1 && (l = i + 1) : e === "ArrowUp" && i > 0 && (l = i - 1), t[l] && t[l].focus();
279
- }
280
- /**
281
- * Focuserer den siste sl-taggen i prefix slotten
282
- */
283
- focusLastTag() {
284
- const e = Array.from(this.shadowRoot?.querySelectorAll("sl-tag") || []), t = e[e.length - 1];
285
- t && t.focus();
286
- }
287
- /**
288
- * Toggle valg av alternativ i søkeresultatlisten.
289
- * @param option Alternativet som skal toggles
290
- * @param index Indeks i søkeresultatlisten
291
- * @returns {void}
292
- */
293
- toggleOptionInListWithSearchHits(e, t) {
294
- if (this.disabled || this.shouldDisplayOptionAsDisabled(e)) return;
295
- const i = [...this.listWithSearchHits], l = i[t].selected;
296
- i[t].selected = !i[t].selected, this.listWithSearchHits = i, l === !0 ? this.unSelectOption(e) : this.selectOption(e);
297
- }
298
- /**
299
- * Toggle valg av alternativ i søkeresultatlisten med tastatur (kun Enter).
300
- * @param option Alternativet som skal toggles
301
- * @param index i søkeresultatlisten
302
- * @param event KeyboardEvent
303
- * @returns {void}
304
- */
305
- toggleOptionInListWithSearchHitsKeyDown(e, t, i) {
306
- i instanceof KeyboardEvent && i.key !== "Enter" || this.toggleOptionInListWithSearchHits(e, t);
307
- }
308
- /**
309
- * Legger til utheving av søketreff i label.
310
- * @param label Label til alternativet
311
- * @returns {TemplateResult} HTML med uthevet søketreff
312
- *
313
- */
314
- addHighlightingToSearchResult(e) {
315
- const t = e.replace(new RegExp(this.inputValue, "i"), (i) => `<b>${i}</b>`);
316
- return h` ${v(t)} `;
317
- }
318
- /**
319
- * Sjekker om maksimalt antall alternativer er valgt.
320
- */
321
- isMaxNumberOfOptionsSelected() {
322
- return this.selectedOptions.length === this.max;
323
- }
324
- /**
325
- * Sjekker om et alternativ skal vises som deaktivert.
326
- * Hvis disabled er true, vises alle alternativer som deaktivert.
327
- * Hvis maksimalt antall alternativer er valgt, vises alle alternativer som ikke er valgt som deaktivert.
328
- */
329
- shouldDisplayOptionAsDisabled(e) {
330
- return this.disabled ? !0 : this.isMaxNumberOfOptionsSelected() ? !e?.selected : !1;
331
- }
332
- /**
333
- * Sjekker om en bokstav er trykket på tastaturet.
334
- * @param event KeyboardEvent
335
- * @returns {boolean} true hvis en bokstav er trykket
336
- */
337
- isAPrintableCharacterPressed(e) {
338
- return e.code.startsWith("Key");
339
- }
340
- /**
341
- * Setter fokus på prefix input ref
342
- * @returns {void}
343
- */
344
- focusPrefixInputField() {
345
- this.prefixInputRef.value?.focus();
346
- }
347
- render() {
348
- return h`
6
+ import l from "./nve-combobox.styles.js";
7
+ import "../../chunks/nve-popup.component.js";
8
+ import "../../chunks/nve-input.component.js";
9
+ import "../../chunks/nve-menu.component.js";
10
+ import "../../chunks/nve-option.component.js";
11
+ //#region src/components/nve-combobox/nve-combobox.component.ts
12
+ var u = class extends t {
13
+ static {
14
+ this.styles = [l];
15
+ }
16
+ constructor() {
17
+ super(), this.helpText = void 0, this.requiredLabel = "*Obligatorisk", this.errorMessage = "-!ERROR!-", this.options = [], this.max = Infinity, this.min = void 0, this.disabled = !1, this.filled = !1, this.required = !1, this.size = "medium", this.testId = void 0, this.listWithSearchHits = [], this.displaySearchResult = !1, this.selectedOptions = [], this.inputValue = "", this.isPopupActive = !1, this.error = !1, this.prefixInputRef = c(), this.boundHandleOutsideClick = this.handleOutsideClick.bind(this);
18
+ }
19
+ firstUpdated() {
20
+ this.selectedOptions = this.options.filter((e) => e?.selected);
21
+ }
22
+ connectedCallback() {
23
+ super.connectedCallback(), document.addEventListener("click", this.boundHandleOutsideClick, !0), this.closest("form")?.addEventListener("submit", this.handleSubmit.bind(this));
24
+ }
25
+ disconnectedCallback() {
26
+ document.removeEventListener("click", this.boundHandleOutsideClick, !0), this.closest("form")?.removeEventListener("submit", this.handleSubmit.bind(this)), super.disconnectedCallback();
27
+ }
28
+ handleOutsideClick(e) {
29
+ !this.shadowRoot?.contains(e.target) && !this.contains(e.target) && this.isPopupActive && (this.setPopupActive(!1), this.listWithSearchHits = [], this.inputValue = "", this.displaySearchResult = !1);
30
+ }
31
+ emitValueEvent(e) {
32
+ this.dispatchEvent(new CustomEvent("value", {
33
+ bubbles: !0,
34
+ cancelable: !1,
35
+ composed: !0,
36
+ detail: { value: e }
37
+ }));
38
+ }
39
+ emitInvalidEvent() {
40
+ this.dispatchEvent(new CustomEvent("invalid", {
41
+ bubbles: !0,
42
+ cancelable: !1,
43
+ composed: !0
44
+ }));
45
+ }
46
+ handleFocus() {
47
+ this.displaySearchResult = !1, this.focusPrefixInputField(), this.handleInput(), this.setPopupActive(!0);
48
+ }
49
+ handleClick() {
50
+ this.focusPrefixInputField(), this.setPopupActive(!0);
51
+ }
52
+ togglePopupActive(e) {
53
+ e.stopPropagation(), this.setPopupActive(!this.isPopupActive);
54
+ }
55
+ handleSubmit(e) {
56
+ e.preventDefault(), this.checkValidity();
57
+ }
58
+ checkValidity() {
59
+ let e = this.selectedOptions.length;
60
+ e >= (this.min === void 0 ? 0 : this.min) && e <= this.max ? this.resetValidation() : this.makeInvalid();
61
+ }
62
+ makeInvalid() {
63
+ this.errorMessage = this.errorMessage, this.error = !0, this.emitInvalidEvent(), this.toggleValidationAttributes(!1);
64
+ }
65
+ resetValidation() {
66
+ this.error = !1, this.toggleValidationAttributes(!0);
67
+ }
68
+ toggleValidationAttributes(e) {
69
+ this.toggleAttribute("data-valid", e), this.toggleAttribute("data-user-valid", e), this.toggleAttribute("data-invalid", !e), this.toggleAttribute("data-user-invalid", !e);
70
+ }
71
+ handleInput() {
72
+ let e = this.prefixInputRef.value;
73
+ if (e && e.value) {
74
+ this.inputValue = e.value;
75
+ let t = this.searchForOptions(e.value);
76
+ this.updateListWithSearchHits(t);
77
+ } else this.displaySearchResult = !1;
78
+ }
79
+ handleKeyboardNavigationInput(e) {
80
+ if (!this.disabled) switch (e.key) {
81
+ case "ArrowDown":
82
+ e.preventDefault(), this.setPopupActive(!0), this.shadowRoot?.querySelector("nve-option")?.focus();
83
+ return;
84
+ case "ArrowUp":
85
+ e.preventDefault(), this.setPopupActive(!0);
86
+ let t = this.shadowRoot?.querySelectorAll("nve-option");
87
+ t && setTimeout(() => {
88
+ t[t.length - 1].focus();
89
+ }, 0);
90
+ return;
91
+ case "Escape":
92
+ !this.isPopupActive && this.inputValue.length > 0 && (this.inputValue = ""), this.setPopupActive(!1);
93
+ return;
94
+ case "Enter":
95
+ case "Space":
96
+ this.setPopupActive(!this.isPopupActive);
97
+ return;
98
+ case "Backspace":
99
+ this.inputValue === "" && this.focusLastTag();
100
+ return;
101
+ default: this.isAPrintableCharacterPressed(e) && this.focusPrefixInputField();
102
+ }
103
+ }
104
+ handleKeyboardNavigationListBox(e) {
105
+ if (!this.disabled) switch (e.key) {
106
+ case "Escape":
107
+ this.setPopupActive(!1);
108
+ return;
109
+ case "ArrowUp":
110
+ case "ArrowDown":
111
+ this.focusNextOption(e.key), e.preventDefault();
112
+ return;
113
+ case "ArrowRight":
114
+ case "ArrowLeft":
115
+ case "BackSpace":
116
+ this.focusPrefixInputField();
117
+ return;
118
+ default: this.isAPrintableCharacterPressed(e) && this.focusPrefixInputField();
119
+ }
120
+ }
121
+ updateListWithSearchHits(e) {
122
+ this.listWithSearchHits = [...e], this.displaySearchResult = !0, this.setPopupActive(!0);
123
+ }
124
+ searchForOptions(e) {
125
+ let t = e.toLowerCase();
126
+ return this.options.filter((e) => e.label.toLowerCase().includes(t)).sort((e, n) => {
127
+ let r = e.label.toLowerCase().startsWith(t), i = n.label.toLowerCase().startsWith(t);
128
+ return r && !i ? -1 : !r && i ? 1 : 0;
129
+ });
130
+ }
131
+ selectOption(e) {
132
+ if (this.disabled || this.isMaxNumberOfOptionsSelected()) return;
133
+ let t = [...this.options], n = t.findIndex((t) => t.value === e.value);
134
+ n !== -1 && (t[n].selected = !0, this.selectedOptions.push(e), this.options = t, this.inputValue = "", this.displaySearchResult = !1, this.setPopupActive(!1), this.focusPrefixInputField(), this.emitValueEvent(this.selectedOptions));
135
+ }
136
+ selectOptionKeyDown(e, t) {
137
+ t.key === "Enter" && this.selectOption(e);
138
+ }
139
+ unSelectOption(e) {
140
+ if (this.disabled) return;
141
+ let t = [...this.options], n = [...this.selectedOptions], r = t.findIndex((t) => t.value === e.value), i = n.findIndex((t) => t.value === e.value);
142
+ r !== -1 && (t[r].selected = !1), i !== -1 && n.splice(i, 1), this.selectedOptions = n, this.options = t, this.emitValueEvent(n);
143
+ }
144
+ unSelectOptionKeyDown(e, t) {
145
+ if (t.key === "Enter") {
146
+ this.unSelectOption(e);
147
+ return;
148
+ }
149
+ }
150
+ unSelectOptionKeyDownTag(e, t) {
151
+ if (!(t instanceof KeyboardEvent && t.key !== "Backspace") && (this.unSelectOption(e), this.selectedOptions.length === 0)) {
152
+ this.focusPrefixInputField();
153
+ return;
154
+ }
155
+ }
156
+ setPopupActive(e) {
157
+ this.isPopupActive === e || this.disabled || (this.isPopupActive = e, this.shadowRoot?.querySelector(".open-icon")?.classList?.toggle("active"));
158
+ }
159
+ focusNextOption(e) {
160
+ let t = Array.from(this.shadowRoot?.querySelectorAll("nve-option") || []), n = t.findIndex((e) => e === this.shadowRoot?.activeElement), r = n;
161
+ e === "ArrowDown" ? n < t.length - 1 && (r = n + 1) : e === "ArrowUp" && n > 0 && (r = n - 1), t[r] && t[r].focus();
162
+ }
163
+ focusLastTag() {
164
+ let e = Array.from(this.shadowRoot?.querySelectorAll("sl-tag") || []), t = e[e.length - 1];
165
+ t && t.focus();
166
+ }
167
+ toggleOptionInListWithSearchHits(e, t) {
168
+ if (this.disabled || this.shouldDisplayOptionAsDisabled(e)) return;
169
+ let n = [...this.listWithSearchHits], r = n[t].selected;
170
+ n[t].selected = !n[t].selected, this.listWithSearchHits = n, r === !0 ? this.unSelectOption(e) : this.selectOption(e);
171
+ }
172
+ toggleOptionInListWithSearchHitsKeyDown(e, t, n) {
173
+ n instanceof KeyboardEvent && n.key !== "Enter" || this.toggleOptionInListWithSearchHits(e, t);
174
+ }
175
+ addHighlightingToSearchResult(t) {
176
+ return e` ${o(t.replace(new RegExp(this.inputValue, "i"), (e) => `<b>${e}</b>`))} `;
177
+ }
178
+ isMaxNumberOfOptionsSelected() {
179
+ return this.selectedOptions.length === this.max;
180
+ }
181
+ shouldDisplayOptionAsDisabled(e) {
182
+ return this.disabled ? !0 : this.isMaxNumberOfOptionsSelected() ? !e?.selected : !1;
183
+ }
184
+ isAPrintableCharacterPressed(e) {
185
+ return e.code.startsWith("Key");
186
+ }
187
+ focusPrefixInputField() {
188
+ this.prefixInputRef.value?.focus();
189
+ }
190
+ render() {
191
+ return e`
349
192
  <nve-popup placement="bottom" sync="width" .active="${this.isPopupActive}" distance="8">
350
193
  <nve-input
351
194
  tabindex="0"
@@ -365,7 +208,7 @@ let s = class extends d {
365
208
  ?filled=${this.filled}
366
209
  ?required=${this.required}
367
210
  >
368
- ${this.selectedOptions.map((e) => h`
211
+ ${this.selectedOptions.map((t) => e`
369
212
  <sl-tag
370
213
  size="${this.size}"
371
214
  variant="neutral"
@@ -373,11 +216,11 @@ let s = class extends d {
373
216
  slot="prefix"
374
217
  saturation="default"
375
218
  variant="neutral"
376
- @sl-remove="${() => this.unSelectOption(e)}"
377
- @keydown="${(t) => this.unSelectOptionKeyDownTag(e, t)}"
219
+ @sl-remove="${() => this.unSelectOption(t)}"
220
+ @keydown="${(e) => this.unSelectOptionKeyDownTag(t, e)}"
378
221
  .removable=${!this.disabled}
379
222
  >
380
- ${e.label}
223
+ ${t.label}
381
224
  </sl-tag>
382
225
  `)}
383
226
 
@@ -390,10 +233,10 @@ let s = class extends d {
390
233
  ?filled=${this.filled}
391
234
  ?disabled=${this.disabled}
392
235
  .value="${this.inputValue}"
393
- ${b(this.prefixInputRef)}
236
+ ${s(this.prefixInputRef)}
394
237
  />
395
238
 
396
- ${h`
239
+ ${e`
397
240
  <span class="open-icon-wrapper" slot="suffix">
398
241
  <nve-icon
399
242
  class="open-icon ${this.disabled && "disabled"}"
@@ -404,12 +247,12 @@ let s = class extends d {
404
247
  ></nve-icon>
405
248
  </span>
406
249
  `}
407
- ${this.error && h`
250
+ ${this.error && e`
408
251
  <nve-icon slot="suffix" size="small" name="error" style="font-size: 1.5rem; color: #cc0000"> </nve-icon>
409
252
  `}
410
253
  </nve-input>
411
254
 
412
- ${this.error && this.errorMessage ? h`<span slot="anchor" class="text--error">${this.errorMessage}</span>` : this.helpText && h`<span slot="anchor" class="text-help">${this.helpText}</span>`}
255
+ ${this.error && this.errorMessage ? e`<span slot="anchor" class="text--error">${this.errorMessage}</span>` : this.helpText && e`<span slot="anchor" class="text-help">${this.helpText}</span>`}
413
256
 
414
257
  <div
415
258
  id="listbox"
@@ -423,100 +266,39 @@ let s = class extends d {
423
266
  ?disabled=${this.disabled}
424
267
  ?filled=${this.filled}
425
268
  >
426
- ${this.displaySearchResult === !0 ? this.listWithSearchHits.length > 0 ? this.listWithSearchHits.map(
427
- (e, t) => h`
269
+ ${this.displaySearchResult === !0 ? this.listWithSearchHits.length > 0 ? this.listWithSearchHits.map((t, n) => e`
428
270
  <nve-option
429
271
  tabindex="-1"
430
- @keydown="${(i) => this.toggleOptionInListWithSearchHitsKeyDown(e, t, i)}"
431
- @click="${() => this.toggleOptionInListWithSearchHits(e, t)}"
432
- value="${e.value}"
433
- ?disabled=${this.shouldDisplayOptionAsDisabled(e)}
434
- .selected="${e.selected}"
272
+ @keydown="${(e) => this.toggleOptionInListWithSearchHitsKeyDown(t, n, e)}"
273
+ @click="${() => this.toggleOptionInListWithSearchHits(t, n)}"
274
+ value="${t.value}"
275
+ ?disabled=${this.shouldDisplayOptionAsDisabled(t)}
276
+ .selected="${t.selected}"
435
277
  >
436
- ${this.addHighlightingToSearchResult(e.label)}
278
+ ${this.addHighlightingToSearchResult(t.label)}
437
279
  </nve-option>
438
- `
439
- ) : h` <nve-option disabled>Ingen resultater</nve-option> ` : ""}
440
- ${this.displaySearchResult === !1 ? this.options.map(
441
- (e) => h`
280
+ `) : e` <nve-option disabled>Ingen resultater</nve-option> ` : ""}
281
+ ${this.displaySearchResult === !1 ? this.options.map((t) => e`
442
282
  <nve-option
443
283
  tabindex="-1"
444
- value="${e.value}"
445
- @keydown="${(t) => e.selected ? this.unSelectOptionKeyDown(e, t) : this.selectOptionKeyDown(e, t)}"
446
- @click="${() => e.selected ? this.unSelectOption(e) : this.selectOption(e)}"
447
- ?disabled=${this.shouldDisplayOptionAsDisabled(e)}
448
- .selected="${e.selected}"
284
+ value="${t.value}"
285
+ @keydown="${(e) => t.selected ? this.unSelectOptionKeyDown(t, e) : this.selectOptionKeyDown(t, e)}"
286
+ @click="${() => t.selected ? this.unSelectOption(t) : this.selectOption(t)}"
287
+ ?disabled=${this.shouldDisplayOptionAsDisabled(t)}
288
+ .selected="${t.selected}"
449
289
  >
450
- ${e.label}
290
+ ${t.label}
451
291
  </nve-option>
452
- `
453
- ) : ""}
292
+ `) : ""}
454
293
  </div>
455
294
  </nve-popup>
456
295
  `;
457
- }
458
- };
459
- s.styles = [u];
460
- o([
461
- r()
462
- ], s.prototype, "label", 2);
463
- o([
464
- r()
465
- ], s.prototype, "placeholder", 2);
466
- o([
467
- r()
468
- ], s.prototype, "helpText", 2);
469
- o([
470
- r()
471
- ], s.prototype, "requiredLabel", 2);
472
- o([
473
- r()
474
- ], s.prototype, "errorMessage", 2);
475
- o([
476
- r({ type: Array })
477
- ], s.prototype, "options", 2);
478
- o([
479
- r({ type: Number })
480
- ], s.prototype, "max", 2);
481
- o([
482
- r({ type: String })
483
- ], s.prototype, "min", 2);
484
- o([
485
- r({ type: Boolean })
486
- ], s.prototype, "disabled", 2);
487
- o([
488
- r({ type: Boolean })
489
- ], s.prototype, "filled", 2);
490
- o([
491
- r({ type: Boolean })
492
- ], s.prototype, "required", 2);
493
- o([
494
- r({ type: String, reflect: !0 })
495
- ], s.prototype, "size", 2);
496
- o([
497
- r({ type: String })
498
- ], s.prototype, "testId", 2);
499
- o([
500
- p()
501
- ], s.prototype, "listWithSearchHits", 2);
502
- o([
503
- p()
504
- ], s.prototype, "displaySearchResult", 2);
505
- o([
506
- p()
507
- ], s.prototype, "selectedOptions", 2);
508
- o([
509
- p()
510
- ], s.prototype, "inputValue", 2);
511
- o([
512
- p()
513
- ], s.prototype, "isPopupActive", 2);
514
- o([
515
- p()
516
- ], s.prototype, "error", 2);
517
- s = o([
518
- y("nve-combobox")
519
- ], s);
520
- export {
521
- s as default
296
+ }
522
297
  };
298
+ a([r()], u.prototype, "label", void 0), a([r()], u.prototype, "placeholder", void 0), a([r()], u.prototype, "helpText", void 0), a([r()], u.prototype, "requiredLabel", void 0), a([r()], u.prototype, "errorMessage", void 0), a([r({ type: Array })], u.prototype, "options", void 0), a([r({ type: Number })], u.prototype, "max", void 0), a([r({ type: String })], u.prototype, "min", void 0), a([r({ type: Boolean })], u.prototype, "disabled", void 0), a([r({ type: Boolean })], u.prototype, "filled", void 0), a([r({ type: Boolean })], u.prototype, "required", void 0), a([r({
299
+ type: String,
300
+ reflect: !0
301
+ })], u.prototype, "size", void 0), a([r({ type: String })], u.prototype, "testId", void 0), a([n()], u.prototype, "listWithSearchHits", void 0), a([n()], u.prototype, "displaySearchResult", void 0), a([n()], u.prototype, "selectedOptions", void 0), a([n()], u.prototype, "inputValue", void 0), a([n()], u.prototype, "isPopupActive", void 0), a([n()], u.prototype, "error", void 0), u = a([i("nve-combobox")], u);
302
+ var d = u;
303
+ //#endregion
304
+ export { d as default };