@altinn/altinn-components 0.56.4 → 0.56.5

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.
@@ -1,637 +0,0 @@
1
- "use client";
2
- import { jsx as r, jsxs as L } from "react/jsx-runtime";
3
- import { c as pe } from "./index-p1eeF8LQ.js";
4
- import { useRef as W, useState as X, useMemo as R, useEffect as j, Fragment as me, useLayoutEffect as oe, useId as ne } from "react";
5
- import { Icon as he } from "./components/Icon/Icon.js";
6
- import { Button as xe } from "./components/Button/Button.js";
7
- import "./components/RootProvider/RootProvider.js";
8
- import { useMenu as ie } from "./hooks/useMenu.js";
9
- import { Input as ye } from "./components/Forms/Input.js";
10
- import { FieldBase as ve } from "./components/Forms/FieldBase.js";
11
- import "./components/Snackbar/useSnackbar.js";
12
- import { S as ge } from "./MagnifyingGlass-bwVhw07z.js";
13
- import { S as Ie } from "./XMark-tKk6aExO.js";
14
- import { MenuItem as se } from "./components/Menu/MenuItem.js";
15
- import { MenuList as Z } from "./components/Menu/MenuList.js";
16
- import { MenuListItem as ae } from "./components/Menu/MenuListItem.js";
17
- import { MenuListGroup as ce } from "./components/Menu/MenuListGroup.js";
18
- import { MenuListDivider as le } from "./components/Menu/MenuListDivider.js";
19
- import { MenuListHeading as ue } from "./components/Menu/MenuListHeading.js";
20
- import { a as be } from "./useMenuVirtualization-Cs426RCN.js";
21
- import { useMenuSearch as ke } from "./components/Menu/useMenuSearch.js";
22
- import './assets/SearchField.css';const Ce = "_search_18jfe_1", _e = "_searchInput_18jfe_8", te = {
23
- search: Ce,
24
- searchInput: _e
25
- }, de = ({
26
- style: I,
27
- index: b,
28
- name: A,
29
- value: C,
30
- placeholder: f = "Search",
31
- clearButtonAltText: a = "Clear search",
32
- onChange: w,
33
- onClear: D,
34
- onNavigate: m,
35
- combobox: l = !1,
36
- listId: v,
37
- "aria-activedescendant": M,
38
- onKeyDown: h,
39
- onInput: i,
40
- onFocus: k,
41
- ..._
42
- }) => /* @__PURE__ */ r("li", { className: te.search, style: I, "data-index": b, "data-menu-search": "true", children: l ? (
43
- // biome-ignore lint/a11y/useFocusableInteractive: <explanation>
44
- // biome-ignore lint/a11y/useAriaPropsForRole: <explanation>
45
- // biome-ignore lint/a11y/useSemanticElements: <explanation>
46
- /* @__PURE__ */ r("div", { role: "combobox", "aria-expanded": !0, "aria-haspopup": "listbox", "aria-owns": v, children: /* @__PURE__ */ r(
47
- re,
48
- {
49
- size: "xs",
50
- className: te.searchInput,
51
- name: A,
52
- value: C,
53
- placeholder: f,
54
- onChange: w,
55
- onClear: D,
56
- clearButtonAltText: a,
57
- autoComplete: "off",
58
- autoCorrect: "off",
59
- autoCapitalize: "off",
60
- "aria-autocomplete": "list",
61
- "aria-controls": v,
62
- "aria-activedescendant": M,
63
- autoFocus: !0,
64
- onKeyDown: (c) => {
65
- (c.key === "ArrowUp" || c.key === "ArrowDown") && (c.preventDefault(), m?.()), h?.(c);
66
- },
67
- onInput: i,
68
- onFocus: k,
69
- ..._
70
- }
71
- ) })
72
- ) : /* @__PURE__ */ r(
73
- re,
74
- {
75
- size: "xs",
76
- className: te.searchInput,
77
- name: A,
78
- value: C,
79
- placeholder: f,
80
- onChange: w,
81
- onClear: D,
82
- clearButtonAltText: a,
83
- autoComplete: "off",
84
- autoCorrect: "off",
85
- autoCapitalize: "off",
86
- autoFocus: !0,
87
- onKeyDown: (c) => {
88
- (c.key === "ArrowUp" || c.key === "ArrowDown") && (c.preventDefault(), m?.()), h?.(c);
89
- },
90
- onInput: i,
91
- onFocus: k,
92
- ..._
93
- }
94
- ) }), fe = ({
95
- level: I = 0,
96
- maxLevels: b,
97
- expanded: A,
98
- a11yMode: C = "menu",
99
- open: f,
100
- scrollToTopOnOpen: a = !1,
101
- autoActivateFirstItem: w = !0,
102
- autoFocusList: D = !0,
103
- announceNoResults: m = !1,
104
- search: l,
105
- items: v,
106
- groups: M = {},
107
- size: h,
108
- id: i,
109
- color: k,
110
- variant: _,
111
- scrollRefStyles: c = {},
112
- keyboardEvents: x = !1,
113
- onSelect: N = () => {
114
- },
115
- onActiveItemIdChange: g
116
- }) => {
117
- if (b && I >= b)
118
- return null;
119
- const p = C === "combobox", u = p && i ? `${i}-listbox` : i, B = W(f), z = W(f), [Y, n] = X(!1), P = R(
120
- () => v.map((o, y) => ({
121
- ...o,
122
- id: o.id || `${i}-item-${y}`
123
- })),
124
- [v, i]
125
- ), G = W(null), { menu: $, setActiveIndex: H, activeItem: E } = ie({
126
- items: P,
127
- groups: M,
128
- groupByKey: "groupId",
129
- keyboardEvents: x,
130
- autoActivateFirstItem: w,
131
- onSelect: N,
132
- ref: G
133
- });
134
- return j(() => {
135
- g?.(E?.id);
136
- }, [E?.id, g]), j(() => {
137
- if (!a) {
138
- B.current = f;
139
- return;
140
- }
141
- const o = B.current;
142
- B.current = f, f && !o && G.current?.scrollTo({ top: 0 });
143
- }, [f, a]), j(() => {
144
- const o = z.current;
145
- z.current = f, !(!x || l || !D) && f && !o && requestAnimationFrame(() => G.current?.focus?.({ preventScroll: !0 }));
146
- }, [f, x, l]), j(() => {
147
- if (p && m) {
148
- H(0), n(!0);
149
- return;
150
- }
151
- }, [m, p, H]), /* @__PURE__ */ L(
152
- Z,
153
- {
154
- variant: _,
155
- expanded: A,
156
- ref: G,
157
- style: c,
158
- id: u,
159
- role: p ? "listbox" : void 0,
160
- tabIndex: x ? -1 : void 0,
161
- children: [
162
- l && /* @__PURE__ */ r(
163
- de,
164
- {
165
- ...l,
166
- combobox: p,
167
- listId: u,
168
- "aria-activedescendant": p && Y ? E?.id : void 0,
169
- onNavigate: p ? () => n(!0) : void 0,
170
- onChange: (o) => {
171
- n(!1), l.onChange?.(o);
172
- },
173
- onFocus: (o) => {
174
- n(!1), l.onFocus?.(o);
175
- },
176
- onInput: (o) => {
177
- n(!1), l.onInput?.(o);
178
- },
179
- onKeyDown: (o) => {
180
- const y = o.key === "ArrowUp" || o.key === "ArrowDown", O = o.key.length === 1 || o.key === "Backspace" || o.key === "Delete";
181
- p && !y && O && n(!1), l.onKeyDown?.(o);
182
- }
183
- }
184
- ),
185
- $.map((o, y) => {
186
- const O = o?.props || {}, { title: F, hidden: q = !1, divider: J = !0 } = O;
187
- return /* @__PURE__ */ L(me, { children: [
188
- (I > 0 || y) && J ? /* @__PURE__ */ r(le, {}) : "",
189
- /* @__PURE__ */ r(ce, { hidden: q, children: /* @__PURE__ */ L(Z, { role: "presentation", children: [
190
- F && /* @__PURE__ */ r(ue, { title: F, level: I }),
191
- o?.items.filter((U) => !U.props?.hidden).map((U, e) => {
192
- const { active: t, onMouseEnter: d } = U, { groupId: S, ...s } = U.props || {}, { expanded: K } = s, V = Array.isArray(s?.items) && s.items.length > 0, Q = s.role === "checkbox" || s.role === "radio", ee = p && !Q ? "option" : s.role;
193
- return /* @__PURE__ */ L(
194
- ae,
195
- {
196
- expanded: K,
197
- onMouseLeave: () => H(-1),
198
- role: p || Q ? "presentation" : void 0,
199
- children: [
200
- /* @__PURE__ */ r(
201
- se,
202
- {
203
- ...s,
204
- size: s?.size || O?.size || h,
205
- color: s?.color || O?.color || k,
206
- variant: s?.variant || O?.variant || _,
207
- active: t,
208
- role: ee,
209
- selected: p && !Q ? t : s.selected,
210
- tabIndex: s?.disabled || x ? -1 : s.tabIndex ?? 0,
211
- onMouseEnter: d,
212
- "aria-haspopup": V ? "menu" : void 0,
213
- "aria-expanded": V ? K : void 0,
214
- "aria-controls": V ? s.id + "-menu" : void 0
215
- }
216
- ),
217
- K && s?.items && /* @__PURE__ */ r(
218
- fe,
219
- {
220
- id: s.id + "-menu",
221
- expanded: K,
222
- level: I + 1,
223
- maxLevels: b,
224
- items: s?.items,
225
- groups: M,
226
- size: h,
227
- color: k,
228
- variant: _
229
- }
230
- )
231
- ]
232
- },
233
- e
234
- );
235
- })
236
- ] }) }, y)
237
- ] }, y);
238
- })
239
- ]
240
- }
241
- );
242
- }, we = (I) => {
243
- const b = W(null), A = W(null), [C, f] = X(0), {
244
- search: a,
245
- items: w,
246
- groups: D = {},
247
- size: m,
248
- color: l,
249
- variant: v,
250
- keyboardEvents: M,
251
- scrollRefStyles: h = {},
252
- id: i,
253
- expanded: k,
254
- a11yMode: _ = "menu",
255
- open: c,
256
- scrollToTopOnOpen: x = !1,
257
- autoActivateFirstItem: N = !0,
258
- announceNoResults: g = !1,
259
- onActiveItemIdChange: p
260
- } = I, u = _ === "combobox", B = u && i ? `${i}-listbox` : i, z = W(c), [Y, n] = X(!1), P = R(
261
- () => w.map((e, t) => ({
262
- ...e,
263
- id: e.id || `${i}-item-${t}`
264
- })),
265
- [w, i]
266
- ), { menu: G, activeItem: $, setActiveIndex: H, activeIndex: E } = ie({
267
- items: P,
268
- groups: D,
269
- groupByKey: "groupId",
270
- keyboardEvents: M,
271
- autoActivateFirstItem: N,
272
- ref: b
273
- }), { flatMenu: o, virtualizer: y, scrollMaxHeight: O } = be({
274
- menu: G,
275
- scrollRef: b
276
- });
277
- oe(() => {
278
- const e = A.current;
279
- if (!e) return;
280
- const t = Math.round(e.offsetTop);
281
- f((d) => d === t ? d : t);
282
- });
283
- const F = R(() => {
284
- const e = $?.id;
285
- if (e)
286
- return o.findIndex((d) => d.type === "item" && d.itemProps?.id === e);
287
- if (E < 0) return -1;
288
- let t = -1;
289
- for (let d = 0; d < o.length; d++)
290
- if (o[d]?.type === "item" && (t += 1, t === E))
291
- return d;
292
- return -1;
293
- }, [$?.id, E, o]), q = W(null);
294
- oe(() => {
295
- const e = q?.current, t = typeof e == "number" ? F <= e : !1;
296
- q.current = F;
297
- const d = t ? F : F + 2;
298
- if (!t) {
299
- const V = y.getOffsetForIndex(d, "auto");
300
- if (!V) return;
301
- const [Q, ee] = V;
302
- if (ee === "auto") return;
303
- y.scrollToOffset(Q + C + 10, { align: "start" });
304
- return;
305
- }
306
- if (F <= 3) {
307
- y.scrollToOffset(0);
308
- return;
309
- }
310
- const S = y.getOffsetForIndex(F - 1, "auto");
311
- if (!S) return;
312
- const [s, K] = S;
313
- K !== "auto" && y.scrollToOffset(s + C + 10, { align: "start" });
314
- }, [F, C, y, q]);
315
- const J = R(() => {
316
- const e = /* @__PURE__ */ new Map();
317
- let t = 0;
318
- return o.forEach((d, S) => {
319
- d.type === "item" && (t += 1, e.set(S, t));
320
- }), { positions: e, total: t };
321
- }, [o]);
322
- j(() => {
323
- p?.($?.id);
324
- }, [$?.id, p]), j(() => {
325
- if (u && g) {
326
- H(0), n(!0);
327
- return;
328
- }
329
- }, [g, u, H]), j(() => {
330
- if (!x) {
331
- z.current = c;
332
- return;
333
- }
334
- const e = z.current;
335
- z.current = c, c && !e && b.current?.scrollTo({ top: 0 });
336
- }, [c, x]);
337
- const U = {
338
- position: "relative",
339
- maxHeight: h?.maxHeight || O,
340
- margin: "-0.5rem",
341
- padding: "0.5rem",
342
- minWidth: h?.minWidth ?? "20rem",
343
- overflowY: "auto",
344
- ...h
345
- };
346
- return /* @__PURE__ */ L(
347
- Z,
348
- {
349
- ref: b,
350
- style: U,
351
- variant: v,
352
- color: l,
353
- expanded: k,
354
- id: B,
355
- role: u ? "listbox" : void 0,
356
- children: [
357
- a && /* @__PURE__ */ r(
358
- de,
359
- {
360
- ...a,
361
- combobox: u,
362
- listId: B,
363
- "aria-activedescendant": u && Y ? $?.id : void 0,
364
- onNavigate: u ? () => n(!0) : void 0,
365
- onChange: (e) => {
366
- n(!1), a.onChange?.(e);
367
- },
368
- onFocus: (e) => {
369
- n(!1), a.onFocus?.(e);
370
- },
371
- onInput: (e) => {
372
- n(!1), a.onInput?.(e);
373
- },
374
- onKeyDown: (e) => {
375
- const t = e.key === "ArrowUp" || e.key === "ArrowDown", d = e.key.length === 1 || e.key === "Backspace" || e.key === "Delete";
376
- u && !t && d && n(!1), a.onKeyDown?.(e);
377
- }
378
- }
379
- ),
380
- /* @__PURE__ */ r(
381
- ce,
382
- {
383
- ref: A,
384
- style: {
385
- position: "relative",
386
- height: `${y.getTotalSize()}px`,
387
- width: "100%"
388
- },
389
- children: /* @__PURE__ */ r(Z, { style: { width: "100%", minWidth: "100%" }, children: y.getVirtualItems().map((e) => {
390
- const t = o[e.index];
391
- if (!t) return null;
392
- const d = {
393
- position: "absolute",
394
- top: 0,
395
- left: 0,
396
- width: "100%",
397
- transform: `translateY(${e.start}px)`
398
- }, S = {
399
- style: d,
400
- index: e.index,
401
- "data-index": e.index,
402
- ref: y.measureElement
403
- };
404
- switch (t.type) {
405
- case "divider":
406
- return /* @__PURE__ */ r(
407
- le,
408
- {
409
- ...S,
410
- style: { ...d, padding: "0.25rem 0" }
411
- },
412
- e.key
413
- );
414
- case "header":
415
- return /* @__PURE__ */ r(ue, { ...S, title: t.title || "", level: 1 }, e.key);
416
- default: {
417
- const s = t.itemProps?.role === "checkbox" || t.itemProps?.role === "radio", K = u && !s ? "option" : t.itemProps?.role;
418
- return /* @__PURE__ */ r(
419
- ae,
420
- {
421
- ...S,
422
- role: u || s ? "presentation" : "menuitem",
423
- children: /* @__PURE__ */ r(
424
- se,
425
- {
426
- ...t.itemProps || {},
427
- size: t.itemProps?.size || m,
428
- color: t.itemProps?.color || l,
429
- variant: t.itemProps?.variant || v,
430
- active: t.active,
431
- role: K,
432
- selected: u && !s ? t.active : t.itemProps?.selected,
433
- "aria-posinset": u ? J.positions.get(e.index) : void 0,
434
- "aria-setsize": u ? J.total : void 0,
435
- tabIndex: t.itemProps?.disabled || M ? -1 : 0
436
- }
437
- )
438
- },
439
- e.key
440
- );
441
- }
442
- }
443
- }) })
444
- }
445
- )
446
- ]
447
- }
448
- );
449
- }, Ae = ({
450
- searchable: I,
451
- search: b,
452
- items: A = [],
453
- groups: C = {},
454
- variant: f = "default",
455
- size: a,
456
- level: w = 0,
457
- maxLevels: D = 3,
458
- virtualized: m = !1,
459
- keyboardEvents: l = !1,
460
- scrollRefStyles: v = {},
461
- onActiveItemIdChange: M,
462
- a11yMode: h = "menu",
463
- open: i,
464
- scrollToTopOnOpen: k,
465
- autoFocusList: _,
466
- id: c
467
- }) => {
468
- const x = ke({ ...b, items: A, groups: C }), N = I ? x.search : b, g = I && x.hasQuery && x.resultCount === 0, p = I ? x.items : A, u = I ? { ...C, ...x.groups } : C, B = h !== "combobox";
469
- return m ? /* @__PURE__ */ r(
470
- we,
471
- {
472
- id: c,
473
- search: N,
474
- announceNoResults: g,
475
- items: p,
476
- groups: u,
477
- variant: f,
478
- size: a,
479
- level: w,
480
- maxLevels: D,
481
- keyboardEvents: l,
482
- scrollRefStyles: v,
483
- onActiveItemIdChange: M,
484
- a11yMode: h,
485
- open: i,
486
- scrollToTopOnOpen: k,
487
- autoActivateFirstItem: B,
488
- autoFocusList: _
489
- }
490
- ) : /* @__PURE__ */ r(
491
- fe,
492
- {
493
- id: c,
494
- search: N,
495
- announceNoResults: g,
496
- items: p,
497
- groups: u,
498
- variant: f,
499
- size: a,
500
- level: w,
501
- maxLevels: D,
502
- keyboardEvents: l,
503
- scrollRefStyles: v,
504
- onActiveItemIdChange: M,
505
- a11yMode: h,
506
- open: i,
507
- scrollToTopOnOpen: k,
508
- autoActivateFirstItem: B,
509
- autoFocusList: _
510
- }
511
- );
512
- }, Me = "_fieldContainer_1ekv9_1", De = "_field_1ekv9_1", Be = "_inputContainer_1ekv9_9", Fe = "_icon_1ekv9_15", Ne = "_input_1ekv9_9", Se = "_clear_1ekv9_58", ze = "_clearButton_1ekv9_70", Pe = "_autocomplete_1ekv9_99", T = {
513
- fieldContainer: Me,
514
- field: De,
515
- inputContainer: Be,
516
- icon: Fe,
517
- input: Ne,
518
- clear: Se,
519
- clearButton: ze,
520
- autocomplete: Pe
521
- }, re = ({
522
- className: I,
523
- collapsible: b,
524
- size: A,
525
- color: C = "neutral",
526
- label: f,
527
- value: a,
528
- onClear: w,
529
- clearButtonAltText: D = "Clear search",
530
- menu: m,
531
- minLength: l,
532
- ...v
533
- }) => {
534
- const M = ne(), [h, i] = X(!1), k = v.id || `search-field-${M}`, _ = `${k}-listbox`, [c, x] = X(void 0), N = "searchfield-clear-button-" + ne(), g = R(() => !a || typeof l == "number" && typeof a == "string" && a.length < l ? !1 : h, [h, l, a]), p = R(() => (m?.items ?? []).map((n) => ({
535
- ...n,
536
- onClick: () => {
537
- n.onClick?.(), i(!1);
538
- }
539
- })), [m]), u = (n) => {
540
- if (n.key === "Enter" && g) {
541
- m?.items?.[0]?.onClick?.(), i(!1);
542
- return;
543
- }
544
- if (n.key === "Escape" && g) {
545
- n.preventDefault(), n.stopPropagation(), i(!1), m?.onClose(), document.getElementById(k)?.focus();
546
- return;
547
- }
548
- v.onKeyDown?.(n), i(!0);
549
- }, B = () => {
550
- i(!0);
551
- }, z = (n) => {
552
- if (!h) return;
553
- const P = n.relatedTarget;
554
- P && n.currentTarget.contains(P) || i(!1);
555
- }, Y = (n) => {
556
- n.relatedTarget?.id === N && x(void 0), v.onBlur?.(n);
557
- };
558
- return /* @__PURE__ */ L("div", { className: T.fieldContainer, children: [
559
- /* @__PURE__ */ r(
560
- ve,
561
- {
562
- size: A,
563
- color: C,
564
- label: f,
565
- className: pe(T.field, I),
566
- onBlurCapture: z,
567
- children: /* @__PURE__ */ L("div", { className: T.inputContainer, children: [
568
- /* @__PURE__ */ r(
569
- ye,
570
- {
571
- ...v,
572
- id: k,
573
- type: "search",
574
- value: a,
575
- className: T.input,
576
- "data-collapsible": b,
577
- autoCapitalize: "off",
578
- autoComplete: "off",
579
- minLength: l,
580
- onKeyDown: u,
581
- onBlur: Y,
582
- ...m && {
583
- role: "combobox",
584
- "aria-autocomplete": "list",
585
- "aria-expanded": !!g,
586
- "aria-haspopup": "listbox",
587
- "aria-controls": _,
588
- "aria-activedescendant": g ? c : void 0,
589
- onFocus: B
590
- }
591
- }
592
- ),
593
- /* @__PURE__ */ r(he, { svgElement: ge, className: T.icon }),
594
- w && !!a && /* @__PURE__ */ r("span", { className: T.clear, children: /* @__PURE__ */ r(
595
- xe,
596
- {
597
- id: N,
598
- "data-testid": "clear-button",
599
- size: "xs",
600
- rounded: !0,
601
- icon: !0,
602
- variant: "tinted",
603
- className: T.clearButton,
604
- onClick: () => {
605
- w?.(), document.getElementById(k)?.focus();
606
- },
607
- "aria-label": D,
608
- "data-action": "clear-input",
609
- children: /* @__PURE__ */ r(Ie, {})
610
- }
611
- ) })
612
- ] })
613
- }
614
- ),
615
- m && g && /* @__PURE__ */ r("div", { className: T.autocomplete, "aria-hidden": !g, children: /* @__PURE__ */ r(
616
- Ae,
617
- {
618
- ...m,
619
- id: _,
620
- items: p,
621
- groups: m?.groups,
622
- keyboardEvents: !0,
623
- a11yMode: "combobox",
624
- open: g,
625
- autoFocusList: !1,
626
- onActiveItemIdChange: x
627
- }
628
- ) })
629
- ] });
630
- };
631
- export {
632
- Ae as M,
633
- re as S,
634
- we as V,
635
- fe as a,
636
- de as b
637
- };