@altinn/altinn-components 0.25.4 → 0.25.6

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,1090 +0,0 @@
1
- "use client";
2
- import { jsxs as P, jsx as c, Fragment as ce } from "react/jsx-runtime";
3
- import { u as j, c as w, a as Ye, b as Tt, o as Pt, f as Lt, s as Rt, d as Dt, e as At, g as Ft, h as Bt, i as $t, j as zt, k as Mt, l as jt, F as Vt, m as Kt } from "./floating-ui.react-BQwG1HOM.js";
4
- import * as Ie from "react";
5
- import { forwardRef as p, useLayoutEffect as Ht, useEffect as L, useRef as A, useState as K, createContext as W, useContext as S, useId as ee, version as qt, useReducer as Ut, useMemo as J, isValidElement as Ge, memo as Xt, useCallback as Wt, Children as Xe } from "react";
6
- import { a as Je, S as N } from "./index-C8BS_2GY.js";
7
- import { u as Yt } from "./index-DyDqjche.js";
8
- import { S as Gt } from "./XMark-Bv1I87Ev.js";
9
- import { S as Jt } from "./ChevronUp-H8Nuww4h.js";
10
- import { S as Qt } from "./ChevronDown-CRAwzuD3.js";
11
- import { u as Zt } from "./useId-CsCRkvK3.js";
12
- import { S as en } from "./Checkmark-RgzvRNxP.js";
13
- import { flushSync as tn } from "react-dom";
14
- var nn = function(t, n) {
15
- var e = {};
16
- for (var o in t) Object.prototype.hasOwnProperty.call(t, o) && n.indexOf(o) < 0 && (e[o] = t[o]);
17
- if (t != null && typeof Object.getOwnPropertySymbols == "function")
18
- for (var r = 0, o = Object.getOwnPropertySymbols(t); r < o.length; r++)
19
- n.indexOf(o[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, o[r]) && (e[o[r]] = t[o[r]]);
20
- return e;
21
- };
22
- const on = p((t, n) => {
23
- var { title: e, titleId: o } = t, r = nn(t, ["title", "titleId"]);
24
- let i = Zt();
25
- return i = e ? o || "title-" + i : void 0, Ie.createElement(
26
- "svg",
27
- Object.assign({ xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", fill: "none", viewBox: "0 0 24 24", focusable: !1, role: "img", ref: n, "aria-labelledby": i }, r),
28
- e ? Ie.createElement("title", { id: i }, e) : null,
29
- Ie.createElement("path", { fill: "currentColor", fillRule: "evenodd", d: "M12 2.25A4.75 4.75 0 0 0 7.25 7v2.25H7A1.75 1.75 0 0 0 5.25 11v9c0 .414.336.75.75.75h12a.75.75 0 0 0 .75-.75v-9A1.75 1.75 0 0 0 17 9.25h-.25V7A4.75 4.75 0 0 0 12 2.25m3.25 7V7a3.25 3.25 0 0 0-6.5 0v2.25zM12 13a1.5 1.5 0 0 0-.75 2.8V17a.75.75 0 0 0 1.5 0v-1.2A1.5 1.5 0 0 0 12 13", clipRule: "evenodd" })
30
- );
31
- }), rn = typeof window < "u" ? Ht : L;
32
- function Se(t) {
33
- const n = A(null);
34
- return rn(() => {
35
- const e = document.getAnimations().filter((i) => "animationName" in i && i.animationName === t), o = e.find((i) => "animationName" in i && i.animationName === t), r = e.find((i) => {
36
- var s;
37
- return ((s = i.effect) == null ? void 0 : s.target) === n.current;
38
- });
39
- return r && r === o && (r.currentTime = 0), r && (o != null && o.currentTime) && r !== o && (r.currentTime = o.currentTime), () => {
40
- r && (o != null && o.currentTime) && (r.currentTime = o.currentTime);
41
- };
42
- }, [t]), n;
43
- }
44
- const Qe = p(function({ "aria-label": n, className: e, ...o }, r) {
45
- const i = Se("ds-spinner-rotate-animation"), s = Se("ds-spinner-stroke-animation"), a = j([i, r]);
46
- return P("svg", { "aria-label": n, className: w("ds-spinner", e), ref: a, role: "img", viewBox: "0 0 50 50", ...o, children: [c("circle", { className: w("ds-spinner__background"), cx: "25", cy: "25", r: "20", fill: "none", strokeWidth: "5" }), c("circle", { className: w("ds-spinner__circle"), cx: "25", cy: "25", r: "20", fill: "none", strokeWidth: "5", ref: s })] });
47
- }), te = p(function({ asChild: n, className: e, children: o, icon: r = !1, loading: i = !1, variant: s = "primary", ...a }, l) {
48
- return P(n ? N : "button", {
49
- "aria-busy": !!i || void 0,
50
- "aria-disabled": !!i || void 0,
51
- className: w("ds-button", e),
52
- "data-icon": r || void 0,
53
- "data-variant": s,
54
- ref: l,
55
- /* don't set type when we use `asChild` */
56
- type: n ? void 0 : "button",
57
- ...a,
58
- children: [i === !0 ? c(Qe, { "aria-hidden": "true" }) : i, c(Je, { children: o })]
59
- });
60
- }), sn = p(function({ className: n, count: e, maxCount: o, variant: r = "base", ...i }, s) {
61
- return c("span", { className: w("ds-badge", n), "data-count": e && o && e > o ? `${o}+` : e, "data-variant": r, ref: s, ...i });
62
- }), an = p(function({ className: n, overlap: e = "rectangle", placement: o = "top-right", ...r }, i) {
63
- return c("span", { className: w("ds-badge--position", n), "data-overlap": e, "data-placement": o, ref: i, ...r });
64
- }), cn = Object.assign(sn, { Position: an });
65
- cn.Position.displayName = "Badge.Position";
66
- const ln = p(({ asChild: t, className: n, ...e }, o) => c(t ? N : "a", { className: w("ds-link", n), ref: o, ...e }));
67
- ln.displayName = "Link";
68
- const fo = p(function({ asChild: n, className: e, height: o, style: r, variant: i = "rectangle", width: s, ...a }, l) {
69
- const f = n ? N : "span", b = i === "text", m = Se("ds-skeleton-opacity-fade"), d = j([m, l]);
70
- return c(f, { "aria-hidden": "true", className: w("ds-skeleton", e), "data-text": b ? "-".repeat(Number(s) || 1) : void 0, "data-variant": i, ref: d, style: b ? r : { width: s, height: o, ...r }, ...a });
71
- }), mo = p(function({ asChild: n, ...e }, o) {
72
- return c(n ? N : "li", { ...e, ref: o });
73
- }), Ze = (t, { asChild: n, className: e, ...o }, r) => c(n ? N : t, { className: w("ds-list", e), ref: r, ...o }), po = p(function(n, e) {
74
- return Ze("ul", n, e);
75
- });
76
- p(function(n, e) {
77
- return Ze("ol", n, e);
78
- });
79
- const Q = p(function({ className: n, weight: e = "medium", asChild: o, ...r }, i) {
80
- return c(o ? N : "label", { ref: i, className: w("ds-label", n), "data-weight": e, ...r });
81
- }), bo = p(function({ level: n = 2, className: e, asChild: o, ...r }, i) {
82
- const s = o ? N : `h${n}`;
83
- return c(s, { className: w("ds-heading", e), ref: i, ...r });
84
- }), me = p(function({ className: n, asChild: e, variant: o = "default", ...r }, i) {
85
- return c(e ? N : "p", { ref: i, className: w("ds-paragraph", n), "data-variant": o, ...r });
86
- }), Pe = p(function({ className: n, asChild: e, ...o }, r) {
87
- return c(e ? N : "p", { className: w("ds-validation-message", n), "data-field": "validation", ref: r, ...o });
88
- }), ho = p(function({ "data-color": n = "info", className: e, ...o }, r) {
89
- return c("div", { className: w("ds-alert", e), "data-color": n, ref: r, ...o });
90
- }), Le = p(function({ type: n = "text", className: e, onChange: o, onClick: r, ...i }, s) {
91
- return c("input", { className: w("ds-input", e), ref: s, type: n, onChange: (a) => i.readOnly || (o == null ? void 0 : o(a)), onClick: (a) => {
92
- i.readOnly && a.preventDefault(), r == null || r(a);
93
- }, ...i });
94
- }), et = p(function({ asChild: n, className: e, ...o }, r) {
95
- return c(n ? N : "button", { className: w("ds-chip", e), type: n ? void 0 : "button", ref: r, ...o });
96
- }), tt = p(function(n, e) {
97
- return c(et, { "data-removable": !0, ref: e, ...n });
98
- }), nt = p(function({ asChild: n, children: e, className: o, "data-size": r, "data-color": i, ...s }, a) {
99
- const l = s.type ?? "checkbox";
100
- return P(n ? N : "label", { className: w("ds-chip", o), "data-size": r, "data-color": i, ref: a, children: [c(Le, { ...s, type: l }), c(Je, { children: e })] });
101
- }), dn = p(function(n, e) {
102
- return c(nt, { ref: e, type: "radio", ...n });
103
- }), pe = {
104
- Button: et,
105
- Checkbox: nt,
106
- Radio: dn,
107
- Removable: tt
108
- };
109
- pe.Button.displayName = "Chip.Button";
110
- pe.Checkbox.displayName = "Chip.Checkbox";
111
- pe.Radio.displayName = "Chip.Radio";
112
- pe.Removable.displayName = "Chip.Removable";
113
- const un = p(function({ "aria-label": n = "Sidenavigering", asChild: e, className: o, ...r }, i) {
114
- return c(e ? N : "nav", { "aria-label": n, className: w("ds-pagination", o), ref: i, ...r });
115
- }), fn = p(function(n, e) {
116
- return c(te, { ref: e, ...n });
117
- }), mn = p(function({ asChild: n, className: e, ...o }, r) {
118
- return c(n ? N : "li", { ref: r, ...o });
119
- }), pn = p(function({ asChild: n, ...e }, o) {
120
- return c(n ? N : "ul", { ref: o, ...e });
121
- }), Re = Object.assign(un, {
122
- List: pn,
123
- Item: mn,
124
- Button: fn
125
- });
126
- Re.List.displayName = "Pagination.List";
127
- Re.Item.displayName = "Pagination.Item";
128
- Re.Button.displayName = "Pagination.Button";
129
- function bn(t) {
130
- if (!t)
131
- return;
132
- const n = /* @__PURE__ */ new Map(), e = `:${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;
133
- let o = null, r = "";
134
- const i = (a) => {
135
- const l = [], f = [];
136
- for (const d of a)
137
- d.attributeName && l.push(d.target ?? t), l.push(...d.addedNodes || []), f.push(...d.removedNodes || []);
138
- for (const d of l)
139
- We(d) && (ke(d) ? n.set(d, d.htmlFor) : d.hasAttribute("data-field") ? n.set(d, d.id) : _e(d) && (o = d, r = d.getAttribute("aria-describedby") || ""));
140
- for (const d of f)
141
- We(d) && (o === d && (o = null), n.has(d) && (fe(d, ke(d) ? "for" : "id", n.get(d)), n.delete(d)));
142
- const b = [r], m = (o == null ? void 0 : o.id) || e;
143
- for (const [d, h] of n) {
144
- const y = d.getAttribute("data-field"), v = y ? `${m}:${y}` : m;
145
- h || fe(d, ke(d) ? "for" : "id", v), y === "validation" ? b.unshift(d.id) : y && b.push(d.id);
146
- }
147
- fe(o, "id", m), fe(o, "aria-describedby", b.join(" ").trim());
148
- }, s = hn(i);
149
- return s.observe(t, {
150
- attributeFilter: ["id", "for", "aria-describedby"],
151
- attributes: !0,
152
- childList: !0,
153
- subtree: !0
154
- }), i([{ addedNodes: t.querySelectorAll("*") }]), s.takeRecords(), () => s.disconnect();
155
- }
156
- const We = (t) => t instanceof Element, ke = (t) => t instanceof HTMLLabelElement, _e = (t) => t instanceof HTMLElement && "validity" in t && !(t instanceof HTMLButtonElement), fe = (t, n, e) => e ? t == null ? void 0 : t.setAttribute(n, e) : t == null ? void 0 : t.removeAttribute(n);
157
- function hn(t) {
158
- const n = [], e = new MutationObserver((r) => {
159
- n.length || requestAnimationFrame(o), n.push(...r);
160
- }), o = () => {
161
- t(n, e), n.length = 0, e.takeRecords();
162
- };
163
- return e;
164
- }
165
- const gn = p(function({ className: n, position: e, ...o }, r) {
166
- const i = A(null), s = j([i, r]);
167
- return L(() => bn(i.current), []), c("div", { className: w("ds-field", n), "data-position": e, ref: s, ...o });
168
- }), yn = p(function({ className: n, ...e }, o) {
169
- return c("div", { className: w("ds-field-affixes", n), ref: o, ...e });
170
- }), xn = p(function({ className: n, ...e }, o) {
171
- return c("span", { className: w("ds-field-affix", n), "aria-hidden": "true", ref: o, ...e });
172
- }), Ne = (t, n) => t.replace("%d", Math.abs(n).toString()), vn = p(function({ limit: n, under: e = "%d tegn igjen", over: o = "%d tegn for mye", ...r }, i) {
173
- const [s, a] = K(0), l = A(null), f = s > n, b = n - s;
174
- return L(() => {
175
- var y;
176
- const m = (y = l.current) == null ? void 0 : y.closest(".ds-field"), d = Array.from((m == null ? void 0 : m.getElementsByTagName("*")) || []).find(_e), h = ({ target: v }) => {
177
- _e(v) && a(v.value.length);
178
- };
179
- return d && h({ target: d }), m == null || m.addEventListener("input", h), () => m == null ? void 0 : m.removeEventListener("input", h);
180
- }, [a]), P(ce, { children: [c("div", { "data-field": "description", className: "ds-sr-only", "aria-live": "polite", ref: l, children: f && Ne(o, b) }), f ? c(Pe, { ref: i, ...r, children: Ne(o, b) }) : c(me, { ref: i, ...r, "data-field": "validation", children: Ne(e, b) })] });
181
- }), Cn = p(function(n, e) {
182
- return c("div", { "data-field": "description", ref: e, ...n });
183
- }), le = Object.assign(gn, {
184
- Description: Cn,
185
- Affixes: yn,
186
- Affix: xn,
187
- Counter: vn
188
- });
189
- le.Description.displayName = "Field.Description";
190
- le.Affixes.displayName = "Field.Affixes";
191
- le.Affix.displayName = "Field.Affix";
192
- le.Counter.displayName = "Field.Counter";
193
- const go = p(function({ "data-size": n, className: e, style: o, children: r, label: i, description: s, error: a, ...l }, f) {
194
- return P(le, { "data-size": n, className: e, style: o, children: [c(Le, { type: "checkbox", ref: f, ...l }), !!i && c(Q, { weight: "regular", children: i }), !!s && c("div", { "data-field": "description", children: s }), !!a && c(Pe, { children: a })] });
195
- }), be = W({}), wn = p(function({ value: n, defaultValue: e, className: o, onChange: r, ...i }, s) {
196
- const a = n !== void 0, [l, f] = K(e);
197
- let b = r;
198
- return a || (b = (m) => {
199
- f(m), r == null || r(m);
200
- }, n = l), c(be.Provider, { value: {
201
- value: n,
202
- defaultValue: e,
203
- onChange: b
204
- }, children: c("div", { className: w("ds-tabs", o), ref: s, ...i }) });
205
- }), ot = W({
206
- elements: { current: /* @__PURE__ */ new Map() },
207
- getOrderedItems: () => [],
208
- setFocusableValue: () => {
209
- },
210
- onShiftTab: () => {
211
- },
212
- focusableValue: null,
213
- orientation: "horizontal"
214
- }), In = p(({ activeValue: t, asChild: n, orientation: e = "horizontal", onBlur: o, onFocus: r, ...i }, s) => {
215
- const a = n ? N : "div", [l, f] = K(null), [b, m] = K(!1), d = A(/* @__PURE__ */ new Map()), h = A(null), y = j([s, h]), v = () => {
216
- if (!h.current)
217
- return [];
218
- const u = Array.from(h.current.querySelectorAll("[data-roving-tabindex-item]"));
219
- return Array.from(d.current).sort((C, g) => u.indexOf(C[1]) - u.indexOf(g[1])).map(([C, g]) => ({ value: C, element: g }));
220
- };
221
- return L(() => {
222
- f(t ?? null);
223
- }, [t]), c(ot.Provider, { value: {
224
- elements: d,
225
- getOrderedItems: v,
226
- focusableValue: l,
227
- setFocusableValue: f,
228
- onShiftTab: () => {
229
- m(!0);
230
- },
231
- orientation: e
232
- }, children: c(a, { ...i, tabIndex: b ? -1 : 0, onBlur: (u) => {
233
- o == null || o(u), m(!1), f(t ?? null);
234
- }, onFocus: (u) => {
235
- var g, x, I;
236
- if (r == null || r(u), u.target !== u.currentTarget)
237
- return;
238
- const C = v();
239
- C.length !== 0 && (l != null ? (g = d.current.get(l)) == null || g.focus() : t != null ? (x = d.current.get(t)) == null || x.focus() : (I = C.at(0)) == null || I.element.focus());
240
- }, ref: y }) });
241
- }), kn = p(function({ children: n, ...e }, o) {
242
- const { value: r } = S(be);
243
- return c(In, { role: "tablist", activeValue: r, orientation: "ambiguous", ref: o, ...e, children: n });
244
- }), Nn = p(function({ children: n, value: e, ...o }, r) {
245
- const { value: i } = S(be), s = e === i, [a, l] = K(!1), f = A(null), b = j([r, f]);
246
- return L(() => {
247
- if (!f.current)
248
- return;
249
- const m = f.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
250
- l(m.length > 0);
251
- }, [n]), c(ce, { children: s && c("div", { ref: b, role: "tabpanel", tabIndex: a ? void 0 : 0, ...o, children: n }) });
252
- }), On = (t) => {
253
- const { elements: n, getOrderedItems: e, setFocusableValue: o, focusableValue: r, onShiftTab: i, orientation: s } = S(ot);
254
- return {
255
- getOrderedItems: e,
256
- isFocusable: r === t,
257
- orientation: s,
258
- getRovingProps: (a) => ({
259
- ...a,
260
- ref: (l) => {
261
- l ? n.current.set(t, l) : n.current.delete(t);
262
- },
263
- onKeyDown: (l) => {
264
- var f;
265
- if ((f = a == null ? void 0 : a.onKeyDown) == null || f.call(a, l), l.shiftKey && l.key === "Tab") {
266
- i();
267
- return;
268
- }
269
- },
270
- onFocus: (l) => {
271
- var f;
272
- (f = a == null ? void 0 : a.onFocus) == null || f.call(a, l), o(t);
273
- },
274
- "data-roving-tabindex-item": !0,
275
- tabIndex: r === t ? 0 : -1
276
- })
277
- };
278
- };
279
- function Oe(t, n) {
280
- const e = t.findIndex((o) => o.value === n);
281
- return t.at(e === t.length - 1 ? 0 : e + 1);
282
- }
283
- function Ee(t, n) {
284
- const e = t.findIndex((o) => o.value === n);
285
- return t.at(e === 0 ? -1 : e - 1);
286
- }
287
- const En = p(({ value: t, asChild: n, ...e }, o) => {
288
- const r = n ? N : "div", i = t ?? (typeof e.children == "string" ? e.children : ""), { getOrderedItems: s, getRovingProps: a, orientation: l } = On(i), f = a({
289
- onKeyDown: (m) => {
290
- var y;
291
- (y = e == null ? void 0 : e.onKeyDown) == null || y.call(e, m);
292
- const d = s();
293
- let h;
294
- switch (l) {
295
- case "horizontal":
296
- m.key === "ArrowRight" && (h = Oe(d, i)), m.key === "ArrowLeft" && (h = Ee(d, i));
297
- break;
298
- case "vertical":
299
- m.key === "ArrowDown" && (h = Oe(d, i)), m.key === "ArrowUp" && (h = Ee(d, i));
300
- break;
301
- case "ambiguous":
302
- ["ArrowRight", "ArrowDown"].includes(m.key) && (h = Oe(d, i)), ["ArrowLeft", "ArrowUp"].includes(m.key) && (h = Ee(d, i));
303
- }
304
- m.key === "Home" && (h = d[0]), m.key === "End" && (h = d[d.length - 1]), h && (m.preventDefault(), h.element.focus());
305
- }
306
- }), b = j([o, f.ref]);
307
- return c(r, { ...e, ...f, ref: b, children: e.children });
308
- }), Sn = p(function({ value: n, id: e, ...o }, r) {
309
- const i = S(be), s = e ?? `tab-${ee()}`;
310
- return c(En, { value: n, ...o, asChild: !0, children: c("button", { ...o, "aria-selected": i.value === n, id: s, onClick: () => {
311
- var a;
312
- return (a = i.onChange) == null ? void 0 : a.call(i, n);
313
- }, ref: r, role: "tab", type: "button" }) });
314
- }), De = Object.assign(wn, {
315
- List: kn,
316
- Tab: Sn,
317
- Panel: Nn
318
- });
319
- De.Tab.displayName = "Tabs.Tab";
320
- De.List.displayName = "Tabs.List";
321
- De.Panel.displayName = "Tabs.Panel";
322
- const rt = ({ children: t }) => {
323
- const n = ee(), [e, o] = K(n);
324
- return c(Ae.Provider, { value: { popoverId: e, setPopoverId: o }, children: t });
325
- };
326
- rt.displayName = "PopoverTriggerContext";
327
- const Ae = W({}), _n = p(function({ id: n, className: e, onClose: o, onOpen: r, open: i, variant: s = "default", placement: a = "top", autoPlacement: l = !0, asChild: f = !1, ...b }, m) {
328
- const d = f ? N : "div", h = A(null), y = j([h, m]), { popoverId: v, setPopoverId: u } = S(Ae), [C, g] = K(!1), x = i ?? C;
329
- return L(() => {
330
- var F;
331
- const I = h.current, O = (z) => {
332
- var G;
333
- const B = z.target, H = (G = B == null ? void 0 : B.closest) == null ? void 0 : G.call(B, `[popovertarget="${I == null ? void 0 : I.id}"]`), M = !H && !(I != null && I.contains(B));
334
- H && (z.preventDefault(), g((T) => !T), r == null || r()), M && (g(!1), o == null || o());
335
- }, _ = (z) => {
336
- z.key !== "Escape" || !x || (z.preventDefault(), g(!1), o == null || o());
337
- };
338
- return (F = I == null ? void 0 : I.togglePopover) == null || F.call(I, x), document.addEventListener("click", O, !0), document.addEventListener("keydown", _), () => {
339
- document.removeEventListener("click", O, !0), document.removeEventListener("keydown", _);
340
- };
341
- }, [x]), L(() => {
342
- const I = h.current, O = document.querySelector(`[popovertarget="${I == null ? void 0 : I.id}"]`);
343
- if (I && O && x)
344
- return Ye(O, I, () => {
345
- Tt(O, I, {
346
- placement: a,
347
- strategy: "fixed",
348
- middleware: [
349
- Pt((_) => {
350
- const F = getComputedStyle(_.elements.floating, "::before");
351
- return parseFloat(F.height);
352
- }),
353
- ...l ? [Lt({ fallbackAxisSideDirection: "start" }), Rt()] : [],
354
- Tn
355
- ]
356
- }).then(({ x: _, y: F }) => {
357
- I.style.translate = `${_}px ${F}px`;
358
- });
359
- });
360
- }, [x, a, n, l]), L(() => {
361
- n && (u == null || u(n));
362
- }, [n]), c(d, {
363
- className: w("ds-popover", e),
364
- id: n || v,
365
- // @ts-ignore @types/react-dom does not understand popover yet
366
- popover: "manual",
367
- "data-variant": s,
368
- ref: y,
369
- ...b
370
- });
371
- }), Tn = {
372
- name: "ArrowPseudoElement",
373
- fn(t) {
374
- const { elements: n, rects: e, placement: o } = t;
375
- let r = `${Math.round(e.reference.width / 2 + e.reference.x - t.x)}px`, i = `${Math.round(e.reference.height / 2 + e.reference.y - t.y)}px`;
376
- switch (e.reference.width > e.floating.width && (r = `${Math.round(e.floating.width / 2)}px`), e.reference.height > e.floating.height && (i = `${Math.round(e.floating.height / 2)}px`), o.split("-")[0]) {
377
- case "top":
378
- i = "100%";
379
- break;
380
- case "right":
381
- r = "0";
382
- break;
383
- case "bottom":
384
- i = "0";
385
- break;
386
- case "left":
387
- r = "100%";
388
- break;
389
- }
390
- return n.floating.setAttribute("data-placement", o.split("-")[0]), n.floating.style.setProperty("--ds-popover-arrow-x", r), n.floating.style.setProperty("--ds-popover-arrow-y", i), t;
391
- }
392
- }, Pn = p(function({ id: n, inline: e, asChild: o, ...r }, i) {
393
- const { popoverId: s } = S(Ae), a = o ? N : e ? "button" : te, l = Object.assign({
394
- [qt.startsWith("19") ? "popoverTarget" : "popovertarget"]: s,
395
- ...e ? {
396
- "data-popover": "inline"
397
- } : {}
398
- }, r);
399
- return c(a, { ref: i, ...l });
400
- }), it = Object.assign(_n, {
401
- TriggerContext: rt,
402
- Trigger: Pn
403
- });
404
- it.TriggerContext.displayName = "Popover.TriggerContext";
405
- it.Trigger.displayName = "Popover.Trigger";
406
- const Fe = W({
407
- current: null
408
- }), st = ({ children: t }) => {
409
- const n = A(null);
410
- return c(Fe.Provider, { value: n, children: t });
411
- };
412
- st.displayName = "DialogTriggerContext";
413
- const Ln = p(function({ asChild: n, children: e, className: o, closeButton: r = "Lukk dialogvindu", closedby: i = "closerequest", modal: s = !0, onClose: a, open: l, ...f }, b) {
414
- const m = S(Fe), d = A(null), h = n ? N : "dialog", y = j([m, b, d]), v = s ? "showModal" : "show";
415
- return L(() => {
416
- var u;
417
- return (u = d.current) == null ? void 0 : u[l ? v : "close"]();
418
- }, [l]), L(() => {
419
- const u = d.current, C = (x) => {
420
- var F;
421
- const { clientY: I, clientX: O, target: _ } = x;
422
- if (x instanceof KeyboardEvent)
423
- return i === "none" && x.key === "Escape" && x.preventDefault();
424
- if (!((F = window.getSelection()) != null && F.toString()) && u && _ === u && i === "any") {
425
- const { top: z, left: B, right: H, bottom: M } = u.getBoundingClientRect();
426
- z <= I && I <= M && B <= O && O <= H || u == null || u.close();
427
- }
428
- }, g = () => {
429
- const x = u == null ? void 0 : u.querySelector("[autofocus]");
430
- document.activeElement !== x && (x == null || x.focus());
431
- };
432
- return u == null || u.addEventListener("animationend", g), u == null || u.addEventListener("click", C), u == null || u.addEventListener("keydown", C), () => {
433
- u == null || u.removeEventListener("animationend", g), u == null || u.removeEventListener("click", C), u == null || u.removeEventListener("keydown", C);
434
- };
435
- }, [i]), L(() => {
436
- var C;
437
- const u = (g) => a == null ? void 0 : a(g);
438
- return (C = d.current) == null || C.addEventListener("close", u), () => {
439
- var g;
440
- return (g = d.current) == null ? void 0 : g.removeEventListener("close", u);
441
- };
442
- }, [a]), P(h, { className: w("ds-dialog", o), ref: y, "data-modal": s, ...f, children: [r !== !1 && c("form", { method: "dialog", children: c(te, { "aria-label": r, autoFocus: !0, "data-color": "neutral", icon: !0, name: "close", type: "submit", variant: "tertiary" }) }), e] });
443
- }), Rn = p(function({ asChild: n, className: e, ...o }, r) {
444
- return c(n ? N : "div", { className: w("ds-dialog__block", e), ref: r, ...o });
445
- }), Dn = p(function({ asChild: n, ...e }, o) {
446
- const r = S(Fe);
447
- return c(n ? N : te, { "aria-haspopup": "dialog", onClick: () => {
448
- var a, l, f;
449
- ((a = r.current) == null ? void 0 : a.getAttribute("data-modal")) === "true" ? (l = r.current) == null || l.showModal() : (f = r.current) == null || f.show();
450
- }, ref: o, ...e });
451
- }), Be = Object.assign(Ln, {
452
- Block: Rn,
453
- TriggerContext: st,
454
- Trigger: Dn
455
- });
456
- Be.Block.displayName = "Dialog.Block";
457
- Be.TriggerContext.displayName = "Dialog.TriggerContext";
458
- Be.Trigger.displayName = "Dialog.Trigger";
459
- const Y = W(void 0), at = W({
460
- activeIndex: 0
461
- }), An = (t, n) => {
462
- switch (n.type) {
463
- case "SET_ACTIVE_INDEX":
464
- return {
465
- ...t,
466
- activeIndex: n.payload
467
- };
468
- default:
469
- return t;
470
- }
471
- }, ct = W(() => {
472
- throw new Error("ComboboxIdDispatch must be used within a provider");
473
- }), Fn = ({ children: t }) => {
474
- const [n, e] = Ut(An, {
475
- activeIndex: 0
476
- });
477
- return c(at.Provider, { value: n, children: c(ct.Provider, { value: e, children: t }) });
478
- };
479
- function $e() {
480
- return S(ct);
481
- }
482
- function he() {
483
- return S(at);
484
- }
485
- const Z = (t, n) => {
486
- const e = {}, o = {};
487
- let r = 0;
488
- const i = t.length;
489
- for (; r < i; )
490
- o[t[r]] = 1, r += 1;
491
- for (const s in n)
492
- Object.prototype.hasOwnProperty.call(o, s) || (e[s] = n[s]);
493
- return e;
494
- }, lt = p(({ asChild: t, interactive: n, id: e, className: o, ...r }, i) => {
495
- if (n && !e)
496
- throw new Error("If ComboboxCustom is interactive, it must have an id");
497
- const s = t ? N : "div", a = ee(), { activeIndex: l } = he(), f = S(Y);
498
- if (!f)
499
- throw new Error("ComboboxCustom must be used within a Combobox");
500
- const { customIds: b, setListRef: m, getItemProps: d, size: h } = f, y = J(() => e && b.indexOf(e) || 0, [e, b]), v = j([
501
- (u) => {
502
- m(y, u);
503
- },
504
- i
505
- ]);
506
- return c(Q, { "data-size": h, asChild: !0, children: c(s, { ref: v, tabIndex: -1, className: w("ds-combobox__custom", o), id: e || a, role: "option", "aria-selected": l === y, "data-active": l === y, ...Z(["interactive"], r), ...Z(["onClick", "onPointerLeave"], d()) }) });
507
- });
508
- function Bn(t) {
509
- return Ge(t) && t.type === lt;
510
- }
511
- function $n(t) {
512
- return Bn(t) && t.props.interactive === !0;
513
- }
514
- const dt = "internal-option-", D = (t) => dt + t, Te = (t) => t.slice(dt.length), ae = (t, n) => {
515
- const e = t.value;
516
- t.value = n;
517
- const o = t._valueTracker;
518
- typeof o < "u" && o.setValue(e), t.dispatchEvent(new Event("change", { bubbles: !0 }));
519
- }, zn = p(function({ "aria-label": n = "Tøm", onClick: e, ...o }, r) {
520
- return c(te, { ref: r, variant: "tertiary", type: "reset", "aria-label": n, onClick: (s) => {
521
- var f;
522
- const a = s.target;
523
- let l = null;
524
- if (a instanceof HTMLElement && (l = (f = a.closest(".ds-search")) == null ? void 0 : f.querySelector("input")), !l)
525
- throw new Error("Input is missing");
526
- if (!(l instanceof HTMLInputElement))
527
- throw new Error("Input is not an input element");
528
- s.preventDefault(), ae(l, ""), l.focus(), e == null || e(s);
529
- }, icon: !0, ...o });
530
- }), Mn = p(function({ children: n = "Søk", ...e }, o) {
531
- return c(te, { ref: o, type: "submit", ...e, children: n });
532
- }), jn = p(function({ ...n }, e) {
533
- return c(Le, {
534
- ref: e,
535
- type: "search",
536
- /* We need an empty placeholder for the clear button to be able to show/hide */
537
- placeholder: "",
538
- ...n
539
- });
540
- }), Vn = p(function({ className: n, ...e }, o) {
541
- return c("div", { ref: o, className: w("ds-search", n), ...e });
542
- }), ze = Object.assign(Vn, {
543
- Clear: zn,
544
- Button: Mn,
545
- Input: jn
546
- });
547
- ze.Clear.displayName = "Search.Clear";
548
- ze.Button.displayName = "Search.Button";
549
- ze.Input.displayName = "Search.Input";
550
- const Kn = W(null), Hn = (t, n) => {
551
- const e = S(Kn), o = ee(), r = t.id ?? `${n}-${o}`, i = t.errorId ?? `${n}-error-${o}`, s = `${n}-description-${o}`, a = t.size ?? (e == null ? void 0 : e.size) ?? "md", l = (e == null ? void 0 : e.disabled) || (t == null ? void 0 : t.disabled), f = !l && !!(t.error || e != null && e.error);
552
- return {
553
- hasError: f,
554
- errorId: i,
555
- descriptionId: s,
556
- size: a,
557
- inputProps: {
558
- id: r,
559
- disabled: l,
560
- "aria-invalid": f ? !0 : void 0,
561
- "aria-describedby": w(t["aria-describedby"], !!(t != null && t.description) && typeof (t == null ? void 0 : t.description) == "string" && s, f && !(e != null && e.error) && i, f && !!(e != null && e.error) && (e == null ? void 0 : e.errorId)) || void 0
562
- }
563
- };
564
- }, ut = ({ size: t, error: n, formFieldProps: e }) => c("div", { className: "ds-combobox__error-message", id: e.errorId, "aria-live": "polite", "aria-relevant": "additions removals", children: n && c(Pe, { "data-size": t, children: n }) });
565
- ut.displayName = "ComboboxError";
566
- const ft = () => {
567
- const t = S(Y);
568
- if (!t)
569
- throw new Error("ComboboxContext is missing");
570
- const { size: n, readOnly: e, disabled: o, selectedOptions: r, chipSrLabel: i, handleSelectOption: s, inputRef: a } = t;
571
- return c(ce, { children: Object.keys(r).map((l) => c(tt, { "data-size": n, disabled: o, onKeyDown: (f) => {
572
- var b;
573
- e || o || f.key === "Enter" && (f.stopPropagation(), s({
574
- option: r[l],
575
- remove: !0
576
- }), (b = a == null ? void 0 : a.current) == null || b.focus());
577
- }, onClick: () => {
578
- e || o || s({
579
- option: r[l],
580
- remove: !0
581
- });
582
- }, "aria-label": i(r[l]), children: r[l].label }, l)) });
583
- };
584
- ft.displayName = "ComboboxChips";
585
- const mt = p((t, n) => {
586
- const e = S(Y);
587
- if (!e)
588
- throw new Error("ComboboxContext is missing");
589
- const { readOnly: o, disabled: r, clearButtonLabel: i, handleSelectOption: s } = e;
590
- return c("button", { ...t, ref: n, disabled: r, className: w("ds-combobox__clear-button", "ds-focus"), onClick: () => {
591
- o || r || s({ option: null, clear: !0 });
592
- }, onKeyDown: (a) => {
593
- o || r || a.key === "Enter" && (a.stopPropagation(), s({ option: null, clear: !0 }));
594
- }, type: "button", "aria-label": i, children: c(Gt, { fontSize: "1.5em", title: "Clear selection" }) });
595
- });
596
- mt.displayName = "ComboboxClearButton";
597
- const pt = ({ hideClearButton: t, listId: n, error: e, hideChips: o, handleKeyDown: r, ...i }) => {
598
- const s = S(Y), a = $e(), l = A(null);
599
- if (!s)
600
- throw new Error("ComboboxContext is missing");
601
- const f = (R) => {
602
- a == null || a({ type: "SET_ACTIVE_INDEX", payload: R });
603
- }, { forwareddRef: b, readOnly: m, disabled: d, open: h, inputRef: y, refs: v, inputValue: u, multiple: C, selectedOptions: g, formFieldProps: x, htmlSize: I, options: O, setOpen: _, getReferenceProps: F, setInputValue: z, handleSelectOption: B, size: H } = s, M = j([b, y]), G = (R) => {
604
- const $ = R.target.value;
605
- z($), f(0);
606
- for (const q of Object.values(O))
607
- if (q.label.toLowerCase() === $.toLowerCase()) {
608
- if (g[D(q.value)])
609
- continue;
610
- B({ option: q });
611
- }
612
- }, T = !t && Object.keys(g).length > 0, ne = F({
613
- ref: v == null ? void 0 : v.setReference,
614
- role: null,
615
- "aria-controls": null,
616
- "aria-expanded": null,
617
- "aria-haspopup": null,
618
- /* If we click the wrapper, toggle open, set index to first option, and focus the input */
619
- onClick(R) {
620
- var $, q;
621
- d || m || ($ = l.current) != null && $.contains(R.target) || (_(!h), f(0), (q = y.current) == null || q.focus());
622
- },
623
- /* Handles list navigation */
624
- onKeyDown: r,
625
- // preventDefault on keydown to avoid sending in form
626
- onKeyPress(R) {
627
- R.key === "Enter" && R.preventDefault();
628
- }
629
- });
630
- return c(me, { "data-size": H, asChild: !0, children: P("div", { ...ne, "aria-disabled": d ? "true" : void 0, className: w("ds-textfield__input", "ds-combobox__input__wrapper", m && "ds-combobox--readonly", e && "ds-combobox--error"), children: [P("div", { className: "ds-combobox__chip-and-input", children: [C && !o && c(ft, {}), c(me, { "data-size": H, asChild: !0, children: c("input", { ref: M, "aria-activedescendant": ne["aria-activedescendant"], readOnly: m, "aria-autocomplete": "list", role: "combobox", "aria-expanded": h, "aria-controls": h ? n : void 0, autoComplete: "off", size: I, value: u, ...Z(["style", "className"], i), ...x.inputProps, className: "ds-combobox__input", onChange: (R) => {
631
- var $;
632
- G(R), !h && _(!0), ($ = i.onChange) == null || $.call(i, R);
633
- } }) })] }), T && c(mt, { ref: l }), c("div", { className: "ds-combobox__arrow", children: h ? c(Jt, { title: "arrow up", fontSize: "1.5em" }) : c(Qt, { title: "arrow down", fontSize: "1.5em" }) })] }) });
634
- };
635
- pt.displayName = "ComboboxInput";
636
- const bt = ({ label: t, description: n, hideLabel: e, size: o, readOnly: r, formFieldProps: i }) => P(ce, { children: [t && P(Q, { "data-size": o, htmlFor: i.inputProps.id, className: w("ds-combobox__label", e && "ds-sr-only"), children: [r && c(on, { "aria-hidden": !0, className: "ds-combobox__readonly__icon" }), t] }), n && c(me, { asChild: !0, "data-size": o, children: c("div", { id: i.descriptionId, className: w("ds-combobox__description", e && "ds-sr-only"), children: n }) })] });
637
- bt.displayName = "ComboboxLabel";
638
- const ht = ({ selectedOptions: t, multiple: n, name: e }) => {
639
- const o = Object.keys(t).map((r) => Te(r));
640
- return c("select", { name: e, multiple: n, style: { display: "none" }, value: n ? o : o[0], onChange: () => {
641
- }, children: o.map((r) => c("option", { value: r }, r)) });
642
- };
643
- ht.displayName = "ComboboxNative";
644
- const gt = p(({ children: t, className: n, ...e }, o) => c("span", { className: w("ds-combobox__option__description", n), ref: o, ...e, children: t }));
645
- gt.displayName = "ComboboxOptionDescription";
646
- const yt = ({ multiple: t, selected: n }) => c("div", { className: w(t && "ds-combobox__option__icon-wrapper", n && "ds-combobox__option__icon-wrapper--selected"), children: n && c(en, { className: "ds-combobox__option__icon-wrapper__icon", "aria-hidden": !0 }) });
647
- yt.displayName = "SelectedIcon";
648
- function Me(t, n = 50) {
649
- const e = A(null);
650
- return L(() => () => {
651
- e.current && clearTimeout(e.current);
652
- }, []), (...r) => {
653
- e.current && clearTimeout(e.current), e.current = window.setTimeout(() => {
654
- t(...r);
655
- }, n);
656
- };
657
- }
658
- const qn = ({ id: t, ref: n, value: e }) => {
659
- const o = ee(), r = t || o, i = S(Y), { activeIndex: s } = he(), a = $e();
660
- if (!i)
661
- throw new Error("ComboboxOption must be used within a Combobox");
662
- const { selectedOptions: l, onOptionClick: f, setListRef: b, customIds: m, filteredOptions: d } = i, h = J(() => d.indexOf(D(String(e))) + m.length, [m.length, d, e]), y = j([
663
- (g) => {
664
- b(h, g);
665
- },
666
- n
667
- ]);
668
- if (h === -1)
669
- throw new Error("Internal error: ComboboxOption did not find index");
670
- const v = l[D(e)], u = s === h;
671
- L(() => {
672
- u && (a == null || a({ type: "SET_ACTIVE_INDEX", payload: h }));
673
- }, [o, t, a, u, h]);
674
- const C = Me(() => f(e), 50);
675
- return {
676
- id: r,
677
- ref: y,
678
- selected: v,
679
- active: u,
680
- onOptionClick: C
681
- };
682
- }, je = Xt(p(({ value: t, description: n, children: e, className: o, ...r }, i) => {
683
- const s = ee(), { id: a, ref: l, selected: f, active: b, onOptionClick: m } = qn({
684
- id: r.id,
685
- ref: i,
686
- value: t
687
- }), d = S(Y);
688
- if (!d)
689
- throw new Error("ComboboxOption must be used within a Combobox");
690
- const { size: h, multiple: y, getItemProps: v } = d, u = v();
691
- return c(Q, { "data-size": "md", asChild: !0, children: P("button", {
692
- ref: l,
693
- id: a,
694
- // biome-ignore lint/a11y/useSemanticElements: biome wants me to use the <option> element
695
- role: "option",
696
- type: "button",
697
- "aria-selected": !!f,
698
- "aria-labelledby": s,
699
- tabIndex: -1,
700
- onClick: (C) => {
701
- var g;
702
- m(), (g = r.onClick) == null || g.call(r, C);
703
- },
704
- className: w("ds-combobox__option", b && "ds-combobox__option--active", y && "ds-combobox__option--multiple", o),
705
- ...Z(["displayValue"], r),
706
- ...Z(["onClick", "onPointerLeave"], u),
707
- children: [c(Q, { asChild: !0, "data-size": h, children: c("span", { children: c(yt, { multiple: y, selected: !!f }) }) }), P(Q, { className: "ds-combobox__option__label", "data-size": h, id: s, children: [e, n && c(gt, { children: n })] })]
708
- }) });
709
- }));
710
- je.displayName = "ComboboxOption";
711
- function Un(t) {
712
- return Ge(t) && t.type === je;
713
- }
714
- const Xn = (t) => !!t;
715
- function Wn({ children: t, inputValue: n, multiple: e, filter: o = (i, s) => s.label.toLowerCase().startsWith(i.toLowerCase()), initialValue: r }) {
716
- const i = Wt(o, [o]), { optionsChildren: s, customIds: a, restChildren: l, interactiveChildren: f } = J(() => Xe.toArray(t).reduce((g, x) => {
717
- if (Un(x))
718
- g.optionsChildren.push(x);
719
- else if (g.restChildren.push(x), $n(x)) {
720
- const I = x;
721
- if (g.interactiveChildren.push(I), !I.props.id)
722
- throw new Error("If ComboboxCustom is interactive, it must have an id");
723
- g.customIds.push(I.props.id);
724
- }
725
- return g;
726
- }, {
727
- optionsChildren: [],
728
- customIds: [],
729
- restChildren: [],
730
- interactiveChildren: []
731
- }), [t]), b = J(() => {
732
- const u = [], C = {};
733
- return s.map((g) => {
734
- const x = g.props;
735
- let I = x.displayValue || "";
736
- if (!x.displayValue) {
737
- let O = "";
738
- Xe.forEach(x.children, (_) => {
739
- if (typeof _ == "string")
740
- O += _;
741
- else
742
- throw new Error("If ComboboxOption is not a string, it must have a displayValue prop");
743
- }), I = O;
744
- }
745
- u.includes(x.value) && console.warn(`Combobox has multiple options with the same value: ${x.value}`), u.push(x.value), C[D(String(x.value))] = {
746
- value: String(x.value),
747
- label: I,
748
- displayValue: x.displayValue,
749
- description: x.description
750
- };
751
- }), C;
752
- }, [s]), m = J(() => ((r == null ? void 0 : r.map((u) => D(u))) || []).reduce((u, C) => {
753
- const g = b[C];
754
- return Xn(g) && (u[C] = g), u;
755
- }, {}), [r, b]), [d, h] = K(m), { filteredOptions: y, filteredOptionsChildren: v } = J(() => {
756
- const u = [], C = Object.keys(b).map((g, x) => {
757
- if (!e && Object.keys(d).length === 1 || e && d[g] || i(n, b[g]))
758
- return u.push(g), s[x];
759
- }).filter((g) => g);
760
- return { filteredOptions: u, filteredOptionsChildren: C };
761
- }, [
762
- i,
763
- n,
764
- e,
765
- b,
766
- s,
767
- d
768
- ]);
769
- return {
770
- filteredOptionsChildren: v,
771
- filteredOptions: y,
772
- restChildren: l,
773
- options: b,
774
- customIds: a,
775
- selectedOptions: d,
776
- interactiveChildren: f,
777
- setSelectedOptions: h
778
- };
779
- }
780
- const Yn = ({ readOnly: t, disabled: n, interactiveChildren: e, filteredOptions: o, inputValue: r, selectedOptions: i, multiple: s, open: a, options: l, setOpen: f, handleSelectOption: b }) => {
781
- const { activeIndex: m } = he();
782
- return Me((y) => {
783
- if (!(t || n) && y)
784
- switch (y.key) {
785
- case "ArrowDown":
786
- if (y.preventDefault(), a)
787
- break;
788
- f(!0);
789
- break;
790
- case "ArrowUp":
791
- if (y.preventDefault(), m !== 0)
792
- break;
793
- f(!1);
794
- break;
795
- case "Enter": {
796
- if (y.preventDefault(), !a)
797
- break;
798
- if (m <= e.length - 1) {
799
- const C = e[m];
800
- if (C.props.onSelect) {
801
- C == null || C.props.onSelect();
802
- return;
803
- }
804
- }
805
- const v = m - e.length, u = o[v];
806
- b({ option: l[u] });
807
- break;
808
- }
809
- case "Backspace":
810
- if (!s) {
811
- const v = Object.keys(i).pop();
812
- v && b({
813
- option: i[v],
814
- remove: !0
815
- });
816
- break;
817
- }
818
- if (r === "" && s) {
819
- const v = Object.keys(i).pop();
820
- v && b({
821
- option: i[v],
822
- remove: !0
823
- });
824
- }
825
- break;
826
- }
827
- }, 20);
828
- }, Gn = ({ listRef: t }) => {
829
- const [n, e] = K(!1), { activeIndex: o } = he(), r = $e(), { refs: i, floatingStyles: s, context: a } = Dt({
830
- open: n,
831
- onOpenChange: (y) => {
832
- y || r == null || r({ type: "SET_ACTIVE_INDEX", payload: 0 }), tn(() => {
833
- i.floating.current && !y && (i.floating.current.scrollTop = 0), setTimeout(() => {
834
- e(y);
835
- }, 1);
836
- });
837
- },
838
- whileElementsMounted: (y, v, u) => (Ye(y, v, u), () => {
839
- v.scrollTop = 0;
840
- }),
841
- middleware: [
842
- At({ padding: 10 }),
843
- Ft({
844
- apply({ rects: y, elements: v }) {
845
- requestAnimationFrame(() => {
846
- Object.assign(v.floating.style, {
847
- width: `${y.reference.width}px`,
848
- maxHeight: "200px"
849
- });
850
- });
851
- }
852
- }),
853
- Bt(10)
854
- ]
855
- }), l = $t(a, { role: "listbox" }), f = zt(a), b = Mt(a, {
856
- listRef: t,
857
- activeIndex: o,
858
- virtual: !0,
859
- scrollItemIntoView: !0,
860
- enabled: n,
861
- focusItemOnHover: !0,
862
- onNavigate: (y) => {
863
- r == null || r({ type: "SET_ACTIVE_INDEX", payload: y || 0 });
864
- }
865
- }), { getReferenceProps: m, getFloatingProps: d, getItemProps: h } = jt([l, f, b]);
866
- return {
867
- open: n,
868
- setOpen: e,
869
- activeIndex: o,
870
- refs: i,
871
- floatingStyles: s,
872
- context: a,
873
- getReferenceProps: m,
874
- getFloatingProps: d,
875
- getItemProps: h
876
- };
877
- }, Jn = p(({ value: t, initialValue: n = [], onValueChange: e, label: o, hideLabel: r = !1, description: i, multiple: s = !1, disabled: a = !1, readOnly: l = !1, hideChips: f = !1, clearButtonLabel: b = "Fjern alt", hideClearButton: m = !1, error: d, errorId: h, id: y, name: v, portal: u = !0, htmlSize: C = 0, virtual: g = !1, children: x, style: I, size: O = "md", loading: _, loadingLabel: F = "Laster...", filter: z, chipSrLabel: B = (T) => "Slett " + T.label, className: H, ...M }, G) => {
878
- const T = A(null), ne = A(null), R = A([]), [$, q] = K(M.inputValue || "");
879
- L(() => {
880
- typeof M.inputValue == "string" && q(M.inputValue);
881
- }, [M.inputValue]);
882
- const { selectedOptions: oe, options: U, restChildren: Ct, interactiveChildren: wt, customIds: It, filteredOptionsChildren: ye, filteredOptions: Ve, setSelectedOptions: re } = Wn({
883
- children: x,
884
- inputValue: $,
885
- filter: z,
886
- multiple: s,
887
- initialValue: n
888
- }), { open: xe, setOpen: ve, refs: de, floatingStyles: kt, context: Ke, getReferenceProps: Nt, getFloatingProps: Ot, getItemProps: Et } = Gn({
889
- listRef: R
890
- }), ie = Hn({
891
- disabled: a,
892
- error: d,
893
- errorId: h,
894
- size: O,
895
- description: i,
896
- id: y
897
- }, "combobox");
898
- L(() => {
899
- if (t && t.length > 0 && !s) {
900
- const E = U[D(t[0])];
901
- T.current && ae(T.current, (E == null ? void 0 : E.label) || "");
902
- }
903
- }, [s, t, U]), L(() => {
904
- if (t && Object.keys(U).length >= 0) {
905
- const E = t.map((k) => U[D(k)]);
906
- re(E.reduce((k, se) => (k[D(se.value)] = se, k), {}));
907
- }
908
- }, [s, t, U, re]);
909
- const Ce = Me((E) => {
910
- var He, qe;
911
- const { option: k, clear: se, remove: _t } = E;
912
- if (se) {
913
- re({}), T.current && ae(T.current, ""), e == null || e([]);
914
- return;
915
- }
916
- if (!k)
917
- return;
918
- if (_t) {
919
- const V = { ...oe };
920
- delete V[D(k.value)], re(V), e == null || e(Object.keys(V).map((ue) => Te(ue)));
921
- return;
922
- }
923
- const X = { ...oe };
924
- if (s)
925
- X[D(k.value)] ? delete X[D(k.value)] : X[D(k.value)] = k, T.current && ae(T.current, ""), (He = T.current) == null || He.focus();
926
- else {
927
- for (const V of Object.keys(X))
928
- delete X[V];
929
- X[D(k.value)] = k, T.current && ae(T.current, (k == null ? void 0 : k.label) || ""), setTimeout(() => {
930
- var V, ue, Ue;
931
- (Ue = T.current) == null || Ue.setSelectionRange(((V = k == null ? void 0 : k.label) == null ? void 0 : V.length) || 0, ((ue = k == null ? void 0 : k.label) == null ? void 0 : ue.length) || 0);
932
- }, 0);
933
- }
934
- re(X), e == null || e(Object.keys(X).map((V) => Te(V))), !s && ve(!1), (qe = de.domReference.current) == null || qe.focus();
935
- }, 50), St = Yn({
936
- filteredOptions: Ve,
937
- selectedOptions: oe,
938
- readOnly: ie.readOnly || !1,
939
- disabled: a,
940
- multiple: s,
941
- inputValue: $,
942
- options: U,
943
- open: xe,
944
- interactiveChildren: wt,
945
- setOpen: ve,
946
- handleSelectOption: Ce
947
- }), we = Yt({
948
- count: Object.keys(ye).length,
949
- getScrollElement: () => g ? de.floating.current : null,
950
- estimateSize: () => 70,
951
- measureElement: (E) => E.getBoundingClientRect().height,
952
- overscan: 7
953
- });
954
- return P(Y.Provider, { value: {
955
- size: O,
956
- options: U,
957
- selectedOptions: oe,
958
- multiple: s,
959
- disabled: a,
960
- readOnly: l,
961
- open: xe,
962
- inputRef: T,
963
- refs: de,
964
- inputValue: $,
965
- formFieldProps: ie,
966
- htmlSize: C,
967
- clearButtonLabel: b,
968
- customIds: It,
969
- filteredOptions: Ve,
970
- setInputValue: q,
971
- setOpen: ve,
972
- getReferenceProps: Nt,
973
- getItemProps: Et,
974
- /* Recieves the value of the option, and searches for it in our values lookup */
975
- onOptionClick: (E) => {
976
- if (l || a)
977
- return;
978
- const k = U[D(E)];
979
- Ce({ option: k });
980
- },
981
- handleSelectOption: Ce,
982
- chipSrLabel: B,
983
- listRef: R,
984
- forwareddRef: G,
985
- setListRef: (E, k) => {
986
- R.current[E] = k;
987
- }
988
- }, children: [P("div", { className: w("ds-combobox", `ds-combobox--${O}`, a && "ds-combobox__disabled", H), style: I, ref: ne, children: [v && c(ht, { name: v, selectedOptions: oe, multiple: s }), c(bt, { label: o, description: i, size: O, readOnly: l, hideLabel: r, formFieldProps: ie }), c(pt, { ...Z(["inputValue"], M), hideClearButton: m, listId: Ke.floatingId || "", error: d, hideChips: f, handleKeyDown: St, "aria-busy": _ }), c(ut, { size: O, error: d, formFieldProps: ie })] }), xe && c(Vt, { root: u ? null : ne, children: c(Kt, { context: Ke, initialFocus: -1, visuallyHiddenDismiss: !0, children: P("div", { "aria-labelledby": ie.inputProps.id, "aria-autocomplete": "list", tabIndex: -1, ...Ot({
989
- ref: de.setFloating,
990
- style: {
991
- ...kt
992
- }
993
- }), className: w("ds-combobox__options-wrapper", `ds-combobox--${O}`), children: [g && c("div", { style: {
994
- height: `${we.getTotalSize()}px`,
995
- width: "100%",
996
- position: "relative"
997
- }, children: we.getVirtualItems().map((E) => c("div", { ref: we.measureElement, "data-index": E.index, style: {
998
- position: "absolute",
999
- top: 0,
1000
- left: 0,
1001
- width: "100%",
1002
- transform: `translateY(${E.start}px)`
1003
- }, children: ye[E.index] }, E.index)) }), _ ? P(lt, { className: "ds-combobox__loading", children: [c(Qe, { "aria-label": "Laster", "data-size": "sm" }), F] }) : P(ce, { children: [Ct, !g && ye] })] }) }) })] });
1004
- }), xt = p((t, n) => c(Fn, { children: c(Jn, { ...t, ref: n }) }));
1005
- xt.displayName = "Combobox";
1006
- const vt = p(({ children: t, className: n, ...e }, o) => {
1007
- const r = S(Y);
1008
- if (!r)
1009
- throw new Error("ComboboxEmpty must be used within a Combobox");
1010
- const { filteredOptions: i, size: s } = r;
1011
- return i.length === 0 && c(Q, { "data-size": s, asChild: !0, children: c("div", { ref: o, className: w("ds-combobox__empty", n), ...e, children: t }) });
1012
- });
1013
- vt.displayName = "ComboboxEmpty";
1014
- const ge = xt;
1015
- ge.Option = je;
1016
- ge.Empty = vt;
1017
- ge.Option.displayName = "Combobox.Option";
1018
- ge.Empty.displayName = "Combobox.Empty";
1019
- const Qn = (t, n, e) => {
1020
- const o = (e - 1) / 2, r = Math.min(Math.max(t - Math.floor(o), 1), n - e + 1), i = Math.min(Math.max(t + Math.ceil(o), e), n), s = Array.from({ length: i + 1 - r }, (a, l) => l + r);
1021
- return e > 4 && r > 1 && s.splice(0, 2, 1, 0), e > 3 && i < n && s.splice(-2, 2, 0, n), s;
1022
- }, yo = ({ currentPage: t = 1, setCurrentPage: n, onChange: e, totalPages: o = 1, showPages: r = 7 }) => J(() => {
1023
- const i = t < o, s = t !== 1, a = (l) => (f) => {
1024
- if (l < 1 || l > o)
1025
- return f.preventDefault();
1026
- e == null || e(f, l), f.defaultPrevented || n == null || n(l);
1027
- };
1028
- return {
1029
- /** Number of steps */
1030
- pages: Qn(t, o, r).map((l, f) => ({
1031
- /**
1032
- * Page number or "ellipsis" for the ellipsis item
1033
- */
1034
- page: l || "ellipsis",
1035
- /**
1036
- * Unique key for the item
1037
- */
1038
- itemKey: l ? `page-${l}` : `ellipsis-${f}`,
1039
- // React key utility
1040
- /**
1041
- * Properties to spread on Pagination.Button
1042
- */
1043
- buttonProps: l ? {
1044
- "aria-current": l === t ? "page" : void 0,
1045
- onClick: a(l),
1046
- variant: l === t ? "primary" : "tertiary"
1047
- } : null
1048
- })),
1049
- /** Properties to spread on Pagination.Button used for previous naviagation */
1050
- prevButtonProps: {
1051
- "aria-disabled": !s,
1052
- // Using aria-disabled to support all HTML elements because of potential asChild
1053
- onClick: a(t - 1),
1054
- variant: "tertiary"
1055
- },
1056
- /** Properties to spread on Pagination.Button used for next naviagation */
1057
- nextButtonProps: {
1058
- "aria-disabled": !i,
1059
- // Using aria-disabled to support all HTML elements because of potential asChild
1060
- onClick: a(t + 1),
1061
- variant: "tertiary"
1062
- },
1063
- /** Indication if previous page action should be shown or not */
1064
- hasPrev: s,
1065
- /** Indication if next page action should be shown or not */
1066
- hasNext: i
1067
- };
1068
- }, [t, o, r]);
1069
- export {
1070
- ho as A,
1071
- cn as B,
1072
- go as C,
1073
- Be as D,
1074
- bo as H,
1075
- ln as L,
1076
- Re as P,
1077
- ze as S,
1078
- De as T,
1079
- Pe as V,
1080
- te as a,
1081
- pe as b,
1082
- ge as c,
1083
- mo as d,
1084
- po as e,
1085
- me as f,
1086
- it as g,
1087
- fo as h,
1088
- Qe as i,
1089
- yo as u
1090
- };