@mattilsynet/design 2.2.21 → 2.2.23

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,16 +1,17 @@
1
- import { jsx as r, jsxs as l } from "react/jsx-runtime";
2
- import { forwardRef as d } from "react";
1
+ import { jsx as r, jsxs as d } from "react/jsx-runtime";
2
+ import { forwardRef as $ } from "react";
3
3
  import { toCustomElementProps as p } from "../utils.js";
4
4
  import "./chart-element.js";
5
- const x = d(function({ data: h, children: i, ...m }, n) {
6
- return /* @__PURE__ */ r("mtds-chart", { ref: n, ...p(m), children: h ? /* @__PURE__ */ l("table", { children: [
7
- /* @__PURE__ */ r("thead", { children: h.slice(0, 1).map((o, c) => /* @__PURE__ */ r("tr", { children: o.map((e, t) => /* @__PURE__ */ r("th", { children: e }, `${t + 1}`)) }, `${c + 1}`)) }),
8
- /* @__PURE__ */ r("tbody", { children: h.slice(1).map((o, c) => /* @__PURE__ */ r("tr", { children: o.map(
9
- (e, t) => t ? /* @__PURE__ */ r("td", { children: e }, `${t + 1}`) : /* @__PURE__ */ r("th", { children: e }, `${t + 1}`)
10
- ) }, `${c + 1}`)) })
11
- ] }) : i });
5
+ let t = 0;
6
+ const u = $(function({ data: l, children: i, ...m }, n) {
7
+ return /* @__PURE__ */ r("mtds-chart", { ref: n, ...p(m), children: l ? /* @__PURE__ */ d("table", { children: [
8
+ /* @__PURE__ */ r("thead", { children: l.slice(0, 1).map((o, c) => /* @__PURE__ */ r("tr", { children: o.map((h, e) => /* @__PURE__ */ r("th", { children: h }, `${e}_${t}`)) }, `${c}_${t}`)) }),
9
+ /* @__PURE__ */ r("tbody", { children: l.slice(1).map((o, c) => /* @__PURE__ */ r("tr", { children: o.map(
10
+ (h, e) => e ? /* @__PURE__ */ r("td", { children: h }, `${e}_${t}`) : /* @__PURE__ */ r("th", { children: h }, `${e}_${t}`)
11
+ ) }, `${c}_${t}`)) })
12
+ ] }, `table_${++t}`) : i });
12
13
  });
13
14
  export {
14
- x as Chart
15
+ u as Chart
15
16
  };
16
17
  //# sourceMappingURL=chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart.js","sources":["../../designsystem/chart/chart.tsx"],"sourcesContent":["import type * as ReactTypes from \"react\";\nimport { forwardRef } from \"react\";\nimport { toCustomElementProps } from \"../utils\";\nimport \"./chart-element\";\nimport type { MTDSChartElement } from \"./chart-element\";\n\ndeclare global {\n\tnamespace React.JSX {\n\t\tinterface IntrinsicElements {\n\t\t\t\"mtds-chart\": ChartProps;\n\t\t}\n\t}\n}\n\nexport type ChartProps = ReactTypes.DetailedHTMLProps<\n\tReactTypes.HTMLAttributes<MTDSChartElement>,\n\tMTDSChartElement\n> & {\n\tclass?: string;\n\tdata?: (number | string)[][];\n\t\"data-legend\"?: \"none\" | \"hidden\" | \"false\" | \"true\" | boolean;\n\t\"data-axis\"?: \"none\" | \"hidden\" | \"false\" | \"true\" | boolean;\n\t\"data-variant\"?:\n\t\t| \"area\"\n\t\t| \"bar\"\n\t\t| \"bar-stacked\"\n\t\t| \"column\"\n\t\t| \"column-stacked\"\n\t\t| \"doughnut\"\n\t\t| \"line\"\n\t\t| \"pie\";\n};\n\nexport const Chart = forwardRef<MTDSChartElement, ChartProps>(function Chart(\n\t{ data, children, ...rest },\n\tref,\n) {\n\treturn (\n\t\t<mtds-chart ref={ref} {...toCustomElementProps(rest)}>\n\t\t\t{data ? (\n\t\t\t\t<table>\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t{data.slice(0, 1).map((tr, row) => (\n\t\t\t\t\t\t\t<tr key={`${row + 1}`}>\n\t\t\t\t\t\t\t\t{tr.map((td, i) => (\n\t\t\t\t\t\t\t\t\t<th key={`${i + 1}`}>{td}</th>\n\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t{data.slice(1).map((tr, row) => (\n\t\t\t\t\t\t\t<tr key={`${row + 1}`}>\n\t\t\t\t\t\t\t\t{tr.map((td, i) =>\n\t\t\t\t\t\t\t\t\ti ? (\n\t\t\t\t\t\t\t\t\t\t<td key={`${i + 1}`}>{td}</td>\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t<th key={`${i + 1}`}>{td}</th>\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t) : (\n\t\t\t\tchildren\n\t\t\t)}\n\t\t</mtds-chart>\n\t);\n});\n"],"names":["Chart","forwardRef","data","children","rest","ref","jsx","toCustomElementProps","jsxs","tr","row","td","i"],"mappings":";;;;AAiCO,MAAMA,IAAQC,EAAyC,SAC7D,EAAE,MAAAC,GAAM,UAAAC,GAAU,GAAGC,EAAA,GACrBC,GACC;AACD,SACC,gBAAAC,EAAC,gBAAW,KAAAD,GAAW,GAAGE,EAAqBH,CAAI,GACjD,UAAAF,IACA,gBAAAM,EAAC,SAAA,EACA,UAAA;AAAA,IAAA,gBAAAF,EAAC,SAAA,EACC,UAAAJ,EAAK,MAAM,GAAG,CAAC,EAAE,IAAI,CAACO,GAAIC,MAC1B,gBAAAJ,EAAC,MAAA,EACC,YAAG,IAAI,CAACK,GAAIC,MACZ,gBAAAN,EAAC,MAAA,EAAqB,UAAAK,EAAA,GAAb,GAAGC,IAAI,CAAC,EAAQ,CACzB,EAAA,GAHO,GAAGF,IAAM,CAAC,EAInB,CACA,GACF;AAAA,IACA,gBAAAJ,EAAC,SAAA,EACC,UAAAJ,EAAK,MAAM,CAAC,EAAE,IAAI,CAACO,GAAIC,MACvB,gBAAAJ,EAAC,MAAA,EACC,UAAAG,EAAG;AAAA,MAAI,CAACE,GAAIC,MACZA,IACC,gBAAAN,EAAC,MAAA,EAAqB,eAAb,GAAGM,IAAI,CAAC,EAAQ,IAEzB,gBAAAN,EAAC,MAAA,EAAqB,eAAb,GAAGM,IAAI,CAAC,EAAQ;AAAA,IAAA,KALnB,GAAGF,IAAM,CAAC,EAQnB,CACA,EAAA,CACF;AAAA,EAAA,EAAA,CACD,IAEAP,GAEF;AAEF,CAAC;"}
1
+ {"version":3,"file":"chart.js","sources":["../../designsystem/chart/chart.tsx"],"sourcesContent":["import type * as ReactTypes from \"react\";\nimport { forwardRef } from \"react\";\nimport { toCustomElementProps } from \"../utils\";\nimport \"./chart-element\";\nimport type { MTDSChartElement } from \"./chart-element\";\n\ndeclare global {\n\tnamespace React.JSX {\n\t\tinterface IntrinsicElements {\n\t\t\t\"mtds-chart\": ChartProps;\n\t\t}\n\t}\n}\n\nexport type ChartProps = ReactTypes.DetailedHTMLProps<\n\tReactTypes.HTMLAttributes<MTDSChartElement>,\n\tMTDSChartElement\n> & {\n\tclass?: string;\n\tdata?: (number | string)[][];\n\t\"data-legend\"?: \"none\" | \"hidden\" | \"false\" | \"true\" | boolean;\n\t\"data-axis\"?: \"none\" | \"hidden\" | \"false\" | \"true\" | boolean;\n\t\"data-variant\"?:\n\t\t| \"area\"\n\t\t| \"bar\"\n\t\t| \"bar-stacked\"\n\t\t| \"column\"\n\t\t| \"column-stacked\"\n\t\t| \"doughnut\"\n\t\t| \"line\"\n\t\t| \"pie\";\n};\n\nlet RENDER = 0; // Ensure re-render on data change\nexport const Chart = forwardRef<MTDSChartElement, ChartProps>(function Chart(\n\t{ data, children, ...rest },\n\tref,\n) {\n\treturn (\n\t\t<mtds-chart ref={ref} {...toCustomElementProps(rest)}>\n\t\t\t{data ? (\n\t\t\t\t<table key={`table_${++RENDER}`}>\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t{data.slice(0, 1).map((tr, row) => (\n\t\t\t\t\t\t\t<tr key={`${row}_${RENDER}`}>\n\t\t\t\t\t\t\t\t{tr.map((td, i) => (\n\t\t\t\t\t\t\t\t\t<th key={`${i}_${RENDER}`}>{td}</th>\n\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t{data.slice(1).map((tr, row) => (\n\t\t\t\t\t\t\t<tr key={`${row}_${RENDER}`}>\n\t\t\t\t\t\t\t\t{tr.map((td, i) =>\n\t\t\t\t\t\t\t\t\ti ? (\n\t\t\t\t\t\t\t\t\t\t<td key={`${i}_${RENDER}`}>{td}</td>\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t<th key={`${i}_${RENDER}`}>{td}</th>\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t) : (\n\t\t\t\tchildren\n\t\t\t)}\n\t\t</mtds-chart>\n\t);\n});\n"],"names":["RENDER","Chart","forwardRef","data","children","rest","ref","jsx","toCustomElementProps","jsxs","tr","row","td","i"],"mappings":";;;;AAiCA,IAAIA,IAAS;AACN,MAAMC,IAAQC,EAAyC,SAC7D,EAAE,MAAAC,GAAM,UAAAC,GAAU,GAAGC,EAAA,GACrBC,GACC;AACD,SACC,gBAAAC,EAAC,gBAAW,KAAAD,GAAW,GAAGE,EAAqBH,CAAI,GACjD,UAAAF,IACA,gBAAAM,EAAC,SAAA,EACA,UAAA;AAAA,IAAA,gBAAAF,EAAC,SAAA,EACC,UAAAJ,EAAK,MAAM,GAAG,CAAC,EAAE,IAAI,CAACO,GAAIC,MAC1B,gBAAAJ,EAAC,MAAA,EACC,UAAAG,EAAG,IAAI,CAACE,GAAIC,MACZ,gBAAAN,EAAC,MAAA,EAA2B,UAAAK,EAAA,GAAnB,GAAGC,CAAC,IAAIb,CAAM,EAAQ,CAC/B,EAAA,GAHO,GAAGW,CAAG,IAAIX,CAAM,EAIzB,CACA,GACF;AAAA,IACA,gBAAAO,EAAC,SAAA,EACC,UAAAJ,EAAK,MAAM,CAAC,EAAE,IAAI,CAACO,GAAIC,MACvB,gBAAAJ,EAAC,MAAA,EACC,UAAAG,EAAG;AAAA,MAAI,CAACE,GAAIC,MACZA,sBACE,MAAA,EAA2B,UAAAD,EAAA,GAAnB,GAAGC,CAAC,IAAIb,CAAM,EAAQ,sBAE9B,MAAA,EAA2B,UAAAY,EAAA,GAAnB,GAAGC,CAAC,IAAIb,CAAM,EAAQ;AAAA,IAAA,KALzB,GAAGW,CAAG,IAAIX,CAAM,EAQzB,CACA,EAAA,CACF;AAAA,EAAA,EAAA,GAtBW,SAAS,EAAEA,CAAM,EAuB7B,IAEAI,GAEF;AAEF,CAAC;"}
@@ -25,3 +25,5 @@ export declare const WithLegendDisabled: Story;
25
25
  export declare const WithCustomTooltips: Story;
26
26
  export declare const WithDotsDisabled: Story;
27
27
  export declare const WithCustomInteractions: Story;
28
+ export declare const WithHiddenSteps: Story;
29
+ export declare const WithHiddeLabels: Story;
@@ -1,79 +1,81 @@
1
- import { UHTMLComboboxElement as E } from "@u-elements/u-combobox";
1
+ import { UHTMLComboboxElement as C } from "@u-elements/u-combobox";
2
2
  import { UHTMLDataListElement as T } from "@u-elements/u-datalist";
3
- import g from "../styles.module.css.js";
4
- import { IS_BROWSER as C, onLoaded as M, onMutation as A, on as m, QUICK_EVENT as p, isInputLike as h, attr as i, useId as u, anchorPosition as b } from "../utils.js";
5
- const v = g.field.split(" ")[0], x = g.validation.split(" "), H = x[0], $ = C ? document.getElementsByClassName(v) : [], l = (t, e) => t.getPropertyValue(`--mtds-text-${e}`)?.slice(1, -1) || "";
6
- function y(t) {
3
+ import v from "../styles.module.css.js";
4
+ import { IS_BROWSER as M, onLoaded as A, onMutation as H, on as m, QUICK_EVENT as g, isInputLike as x, attr as n, useId as p, anchorPosition as h } from "../utils.js";
5
+ const y = v.field.split(" ")[0], I = v.validation.split(" "), V = I[0], $ = M ? document.getElementsByClassName(y) : [];
6
+ function L(t) {
7
7
  let e = null;
8
8
  for (const a of $)
9
9
  if (a.isConnected) {
10
- const n = [], s = [], f = [];
10
+ const i = [], s = [], u = [];
11
11
  let c = null, r = null, d = !0;
12
12
  for (const o of a.getElementsByTagName("*"))
13
- o instanceof HTMLLabelElement ? n.push(o) : o instanceof E ? c = o : h(o) && !o.hidden ? r = o : o.hasAttribute("data-description") ? s.push(o) : o.classList.contains(H) ? (d = i(o, "data-color") === "success" || !o.clientHeight, f.push(o), s.unshift(o)) : o instanceof HTMLParagraphElement && (s.some((I) => I.contains(o)) || s.push(o));
13
+ o instanceof HTMLLabelElement ? i.push(o) : o instanceof C ? c = o : x(o) && !o.hidden ? r = o : o.hasAttribute("data-description") ? s.push(o) : o.classList.contains(V) ? (d = n(o, "data-color") === "success" || !o.clientHeight, u.push(o), s.unshift(o)) : o instanceof HTMLParagraphElement && (s.some((b) => b.contains(o)) || s.push(o));
14
14
  if (r) {
15
- for (const o of n) o.htmlFor = u(r);
16
- if (t && i(a, "data-validation") === "form") {
17
- d = r.matches(":valid"), !e && !d && (e = r);
18
- for (const o of f)
19
- i(o, "hidden", d ? "" : null);
15
+ const o = c?.control;
16
+ if ((t || o?.validity.customError) && n(a, "data-validation") === "form") {
17
+ d = o?.getAttribute("aria-required") === "true" ? !!c?.items.length : r.validity.valid, !e && !d && (e = r);
18
+ for (const f of u) n(f, "hidden", d ? "" : null);
19
+ o?.setCustomValidity(d ? "" : "Invalid");
20
20
  }
21
- F(c), S(r), L(r), i(r, "aria-describedby", s.map(u).join(" ")), i(r, "aria-invalid", `${!d}`);
21
+ for (const f of i) f.htmlFor = p(r);
22
+ D(c), E(r), S(r), n(r, "aria-describedby", s.map(p).join(" ")), n(r, "aria-invalid", `${!d}`);
22
23
  }
23
24
  }
24
- e?.focus();
25
+ return t && e?.focus(), e;
25
26
  }
26
- function L(t) {
27
+ function S(t) {
27
28
  t instanceof HTMLTextAreaElement && (t.style.setProperty("--mtds-textarea-height", "auto"), t.style.setProperty(
28
29
  "--mtds-textarea-height",
29
30
  `${t.scrollHeight}px`
30
31
  ));
31
32
  }
32
- function F(t) {
33
+ const l = (t, e) => t.getPropertyValue(`--mtds-text-${e}`)?.slice(1, -1) || "";
34
+ function D(t) {
33
35
  const { control: e, list: a } = t || {};
34
36
  if (t && a && !t.hasAttribute("data-sr-added")) {
35
- const n = window.getComputedStyle(t);
36
- i(t, "data-sr-added", l(n, "combobox-added")), i(t, "data-sr-empty", l(n, "combobox-empty")), i(t, "data-sr-found", l(n, "combobox-found")), i(t, "data-sr-invalid", l(n, "combobox-invalid")), i(t, "data-sr-of", l(n, "combobox-of")), i(t, "data-sr-remove", l(n, "combobox-remove")), i(t, "data-sr-removed", l(n, "combobox-removed")), i(a, "data-sr-plural", l(n, "datalist-plural")), i(a, "data-sr-singular", l(n, "datalist-singular"));
37
+ const i = window.getComputedStyle(t);
38
+ n(t, "data-sr-added", l(i, "combobox-added")), n(t, "data-sr-empty", l(i, "combobox-empty")), n(t, "data-sr-found", l(i, "combobox-found")), n(t, "data-sr-invalid", l(i, "combobox-invalid")), n(t, "data-sr-of", l(i, "combobox-of")), n(t, "data-sr-remove", l(i, "combobox-remove")), n(t, "data-sr-removed", l(i, "combobox-removed")), n(a, "data-sr-plural", l(i, "datalist-plural")), n(a, "data-sr-singular", l(i, "datalist-singular"));
37
39
  }
38
- a && e && !a.hasAttribute("popover") && (i(a, "popover", "manual"), i(e, "popovertarget", u(a)));
40
+ a && e && !a.hasAttribute("popover") && (n(a, "popover", "manual"), n(e, "popovertarget", p(a)));
39
41
  }
40
- function S(t) {
41
- const e = t?.nextElementSibling, a = e && i(e, "data-count");
42
+ function E(t) {
43
+ const e = t?.nextElementSibling, a = e && n(e, "data-count");
42
44
  if (e && a) {
43
- const n = Number(a) - t.value.length, s = n < 0, f = i(e, "aria-live") === "polite", c = window.getComputedStyle(e || t), r = l(c, "count-over"), d = l(c, "count-under");
44
- if (f !== s) {
45
- i(e, "aria-live", s ? "polite" : "off");
46
- for (const o of x) e.classList.toggle(o, s);
45
+ const i = Number(a) - t.value.length, s = i < 0, u = n(e, "aria-live") === "polite", c = window.getComputedStyle(e || t), r = l(c, "count-over"), d = l(c, "count-under");
46
+ if (u !== s) {
47
+ n(e, "aria-live", s ? "polite" : "off");
48
+ for (const o of I) e.classList.toggle(o, s);
47
49
  }
48
50
  e.textContent = (s ? r : d).replace(
49
51
  "%d",
50
- `${Math.abs(n)}`
52
+ `${Math.abs(i)}`
51
53
  );
52
54
  }
53
55
  }
54
- function N({ target: t, newState: e }) {
56
+ function F({ target: t, newState: e }) {
55
57
  if (t instanceof T) {
56
- const n = t.getRootNode()?.querySelector(
58
+ const i = t.getRootNode()?.querySelector(
57
59
  `[popovertarget="${t.id}"]`
58
60
  );
59
- e === "closed" ? b(t, !1) : n && b(t, n, {
61
+ e === "closed" ? h(t, !1) : i && h(t, i, {
60
62
  contain({ availableHeight: s }) {
61
- t.style.width = `${n.clientWidth}px`, t.style.maxHeight = `${Math.max(50, s)}px`;
63
+ t.style.width = `${i.clientWidth}px`, t.style.maxHeight = `${Math.max(50, s)}px`;
62
64
  }
63
65
  });
64
66
  }
65
67
  }
66
- function D(t) {
67
- h(t.target) && (S(t.target), L(t.target));
68
+ function N(t) {
69
+ x(t.target) && (E(t.target), S(t.target));
68
70
  }
69
71
  function w(t) {
70
- const e = t.target?.closest?.(`.${v}`);
71
- t.type === "invalid" && e && t.preventDefault(), y(!0);
72
+ const e = t.target?.closest?.(`.${y}`);
73
+ t.type === "invalid" && e && t.preventDefault(), L(!0) && t.preventDefault();
72
74
  }
73
- M(() => [
74
- A(() => y()),
75
- m(document, "input", D, p),
76
- m(document, "toggle", N, p),
75
+ A(() => [
76
+ H(() => L(), "class"),
77
+ m(document, "input", N, g),
78
+ m(document, "toggle", F, g),
77
79
  // Use capture since toggle does not bubble
78
80
  m(document, "invalid,submit", w, !0)
79
81
  // Use capture as invalid and submit does not bubble
@@ -1 +1 @@
1
- {"version":3,"file":"field-observer.js","sources":["../../designsystem/field/field-observer.ts"],"sourcesContent":["import { UHTMLComboboxElement } from \"@u-elements/u-combobox\";\nimport { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\tanchorPosition,\n\tattr,\n\tIS_BROWSER,\n\tisInputLike,\n\ton,\n\tonLoaded,\n\tonMutation,\n\tQUICK_EVENT,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELD = styles.field.split(\" \")[0];\nconst CSS_VALIDATIONS = styles.validation.split(\" \");\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\nconst FIELDS = IS_BROWSER ? document.getElementsByClassName(CSS_FIELD) : [];\n\nconst getText = (style: CSSStyleDeclaration, key: string) =>\n\tstyle.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || \"\"; // slice to trim quotes\n\nfunction handleFieldMutation(validate?: boolean) {\n\tlet firstInvalid: HTMLInputElement | null = null;\n\tfor (const field of FIELDS)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descriptions: Element[] = [];\n\t\t\tconst validationMessages: Element[] = [];\n\t\t\tlet combobox: UHTMLComboboxElement | null = null;\n\t\t\tlet input: HTMLInputElement | null = null;\n\t\t\tlet valid = true;\n\n\t\t\tfor (const el of field.getElementsByTagName(\"*\")) {\n\t\t\t\tif (el instanceof HTMLLabelElement) labels.push(el);\n\t\t\t\telse if (el instanceof UHTMLComboboxElement) combobox = el;\n\t\t\t\telse if (isInputLike(el) && !el.hidden) input = el;\n\t\t\t\telse if (el.hasAttribute(\"data-description\")) descriptions.push(el);\n\t\t\t\telse if (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\tvalid = attr(el, \"data-color\") === \"success\" || !el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\tvalidationMessages.push(el);\n\t\t\t\t\tdescriptions.unshift(el);\n\t\t\t\t} else if (el instanceof HTMLParagraphElement)\n\t\t\t\t\tdescriptions.some((desc) => desc.contains(el)) ||\n\t\t\t\t\t\tdescriptions.push(el); // Only add if not already inside description\n\t\t\t}\n\n\t\t\tif (input) {\n\t\t\t\tfor (const label of labels) label.htmlFor = useId(input);\n\t\t\t\tif (validate && attr(field, \"data-validation\") === \"form\") {\n\t\t\t\t\tvalid = input.matches(\":valid\");\n\t\t\t\t\tif (!firstInvalid && !valid) firstInvalid = input;\n\t\t\t\t\tfor (const el of validationMessages)\n\t\t\t\t\t\tattr(el, \"hidden\", valid ? \"\" : null);\n\t\t\t\t}\n\t\t\t\trenderCombobox(combobox);\n\t\t\t\trenderCounter(input);\n\t\t\t\trenderTextareaSize(input);\n\t\t\t\tattr(input, \"aria-describedby\", descriptions.map(useId).join(\" \"));\n\t\t\t\tattr(input, \"aria-invalid\", `${!valid}`);\n\t\t\t}\n\t\t}\n\tfirstInvalid?.focus(); // Move focus to first invalid field if doing validation\n}\n\n// iOS does not support field-sizing: content, so we need to manually resize\nfunction renderTextareaSize(textarea: Element) {\n\tif (textarea instanceof HTMLTextAreaElement) {\n\t\ttextarea.style.setProperty(\"--mtds-textarea-height\", \"auto\");\n\t\ttextarea.style.setProperty(\n\t\t\t\"--mtds-textarea-height\",\n\t\t\t`${textarea.scrollHeight}px`,\n\t\t);\n\t}\n}\n\n// Setup translations from CSS custom properties\nfunction renderCombobox(el: UHTMLComboboxElement | null) {\n\tconst { control, list } = el || {};\n\n\tif (el && list && !el.hasAttribute(\"data-sr-added\")) {\n\t\tconst style = window.getComputedStyle(el);\n\t\tattr(el, \"data-sr-added\", getText(style, \"combobox-added\"));\n\t\tattr(el, \"data-sr-empty\", getText(style, \"combobox-empty\"));\n\t\tattr(el, \"data-sr-found\", getText(style, \"combobox-found\"));\n\t\tattr(el, \"data-sr-invalid\", getText(style, \"combobox-invalid\"));\n\t\tattr(el, \"data-sr-of\", getText(style, \"combobox-of\"));\n\t\tattr(el, \"data-sr-remove\", getText(style, \"combobox-remove\"));\n\t\tattr(el, \"data-sr-removed\", getText(style, \"combobox-removed\"));\n\t\tattr(list, \"data-sr-plural\", getText(style, \"datalist-plural\"));\n\t\tattr(list, \"data-sr-singular\", getText(style, \"datalist-singular\"));\n\t}\n\tif (list && control && !list.hasAttribute(\"popover\")) {\n\t\tattr(list, \"popover\", \"manual\");\n\t\tattr(control, \"popovertarget\", useId(list));\n\t}\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n\tconst el = input?.nextElementSibling;\n\tconst limit = el && attr(el, \"data-count\");\n\n\tif (el && limit) {\n\t\tconst remainder = Number(limit) - input.value.length;\n\t\tconst nextInvalid = remainder < 0;\n\t\tconst prevInvalid = attr(el, \"aria-live\") === \"polite\";\n\t\tconst style = window.getComputedStyle(el || input);\n\t\tconst over = getText(style, \"count-over\");\n\t\tconst under = getText(style, \"count-under\");\n\n\t\tif (prevInvalid !== nextInvalid) {\n\t\t\tattr(el, \"aria-live\", nextInvalid ? \"polite\" : \"off\");\n\t\t\tfor (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n\t\t}\n\t\tel.textContent = (nextInvalid ? over : under).replace(\n\t\t\t\"%d\",\n\t\t\t`${Math.abs(remainder)}`,\n\t\t);\n\t}\n}\n\nfunction handleFieldToggle({ target: el, newState }: Partial<ToggleEvent>) {\n\tif (el instanceof UHTMLDataListElement) {\n\t\tconst root = el.getRootNode() as ShadowRoot | null;\n\t\tconst anchor = root?.querySelector<HTMLElement>(\n\t\t\t`[popovertarget=\"${el.id}\"]`,\n\t\t);\n\n\t\tif (newState === \"closed\") anchorPosition(el, false);\n\t\telse if (anchor)\n\t\t\tanchorPosition(el, anchor, {\n\t\t\t\tcontain({ availableHeight }) {\n\t\t\t\t\tel.style.width = `${anchor.clientWidth}px`;\n\t\t\t\t\tel.style.maxHeight = `${Math.max(50, availableHeight)}px`;\n\t\t\t\t},\n\t\t\t});\n\t}\n}\n// Update when typing\nfunction handleFieldInput(event: Event) {\n\tif (isInputLike(event.target)) {\n\t\trenderCounter(event.target);\n\t\trenderTextareaSize(event.target);\n\t}\n}\n\nfunction handleFieldValdiation(event: Event) {\n\tconst field = (event.target as Element)?.closest?.(`.${CSS_FIELD}`);\n\tif (event.type === \"invalid\" && field) event.preventDefault(); // Prevent browsers from showing default validation bubbles\n\thandleFieldMutation(true); // Update state\n}\n\nonLoaded(() => [\n\tonMutation(() => handleFieldMutation()),\n\ton(document, \"input\", handleFieldInput, QUICK_EVENT),\n\ton(document, \"toggle\", handleFieldToggle, QUICK_EVENT), // Use capture since toggle does not bubble\n\ton(document, \"invalid,submit\", handleFieldValdiation, true), // Use capture as invalid and submit does not bubble\n]);\n"],"names":["CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","FIELDS","IS_BROWSER","getText","style","key","handleFieldMutation","validate","firstInvalid","field","labels","descriptions","validationMessages","combobox","input","valid","el","UHTMLComboboxElement","isInputLike","attr","desc","label","useId","renderCombobox","renderCounter","renderTextareaSize","textarea","control","list","limit","remainder","nextInvalid","prevInvalid","over","under","css","handleFieldToggle","newState","UHTMLDataListElement","anchor","anchorPosition","availableHeight","handleFieldInput","event","handleFieldValdiation","onLoaded","onMutation","on","QUICK_EVENT"],"mappings":";;;;AAeA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAkBD,EAAO,WAAW,MAAM,GAAG,GAC7CE,IAAiBD,EAAgB,CAAC,GAClCE,IAASC,IAAa,SAAS,uBAAuBL,CAAS,IAAI,CAAA,GAEnEM,IAAU,CAACC,GAA4BC,MAC5CD,EAAM,iBAAiB,eAAeC,CAAG,EAAE,GAAG,MAAM,GAAG,EAAE,KAAK;AAE/D,SAASC,EAAoBC,GAAoB;AAChD,MAAIC,IAAwC;AAC5C,aAAWC,KAASR;AACnB,QAAIQ,EAAM,aAAa;AACtB,YAAMC,IAA6B,CAAA,GAC7BC,IAA0B,CAAA,GAC1BC,IAAgC,CAAA;AACtC,UAAIC,IAAwC,MACxCC,IAAiC,MACjCC,IAAQ;AAEZ,iBAAWC,KAAMP,EAAM,qBAAqB,GAAG;AAC9C,QAAIO,aAAc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er.ts"],"sourcesContent":["import { UHTMLComboboxElement } from \"@u-elements/u-combobox\";\nimport { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\tanchorPosition,\n\tattr,\n\tIS_BROWSER,\n\tisInputLike,\n\ton,\n\tonLoaded,\n\tonMutation,\n\tQUICK_EVENT,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELD = styles.field.split(\" \")[0];\nconst CSS_VALIDATIONS = styles.validation.split(\" \");\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\nconst FIELDS = IS_BROWSER ? document.getElementsByClassName(CSS_FIELD) : [];\n\nfunction handleFieldMutation(validate?: boolean) {\n\tlet firstInvalid: HTMLInputElement | null = null;\n\tfor (const field of FIELDS)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descriptions: Element[] = [];\n\t\t\tconst validationMsg: Element[] = [];\n\t\t\tlet combobox: UHTMLComboboxElement | null = null;\n\t\t\tlet input: HTMLInputElement | null = null;\n\t\t\tlet valid = true;\n\n\t\t\tfor (const el of field.getElementsByTagName(\"*\")) {\n\t\t\t\tif (el instanceof HTMLLabelElement) labels.push(el);\n\t\t\t\telse if (el instanceof UHTMLComboboxElement) combobox = el;\n\t\t\t\telse if (isInputLike(el) && !el.hidden) input = el;\n\t\t\t\telse if (el.hasAttribute(\"data-description\")) descriptions.push(el);\n\t\t\t\telse if (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\tvalid = attr(el, \"data-color\") === \"success\" || !el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\tvalidationMsg.push(el);\n\t\t\t\t\tdescriptions.unshift(el);\n\t\t\t\t} else if (el instanceof HTMLParagraphElement)\n\t\t\t\t\tdescriptions.some((desc) => desc.contains(el)) ||\n\t\t\t\t\t\tdescriptions.push(el); // Only add if not already inside description\n\t\t\t}\n\n\t\t\tif (input) {\n\t\t\t\tconst comboboxInput = combobox?.control;\n\t\t\t\tconst shouldValidate = validate || comboboxInput?.validity.customError; // Live re-evaluate combobox if invalid to correct validity before form sumbit\n\n\t\t\t\tif (shouldValidate && attr(field, \"data-validation\") === \"form\") {\n\t\t\t\t\tvalid =\n\t\t\t\t\t\tcomboboxInput?.getAttribute(\"aria-required\") === \"true\"\n\t\t\t\t\t\t\t? !!combobox?.items.length\n\t\t\t\t\t\t\t: input.validity.valid;\n\n\t\t\t\t\tif (!firstInvalid && !valid) firstInvalid = input;\n\t\t\t\t\tfor (const el of validationMsg) attr(el, \"hidden\", valid ? \"\" : null);\n\t\t\t\t\tcomboboxInput?.setCustomValidity(valid ? \"\" : \"Invalid\"); // Combobox does not have native validation\n\t\t\t\t}\n\t\t\t\tfor (const label of labels) label.htmlFor = useId(input);\n\t\t\t\trenderCombobox(combobox);\n\t\t\t\trenderCounter(input);\n\t\t\t\trenderTextareaSize(input);\n\t\t\t\tattr(input, \"aria-describedby\", descriptions.map(useId).join(\" \"));\n\t\t\t\tattr(input, \"aria-invalid\", `${!valid}`);\n\t\t\t}\n\t\t}\n\tif (validate) firstInvalid?.focus(); // Only move focus to first invalid field if validate was true\n\treturn firstInvalid;\n}\n\n// iOS does not support field-sizing: content, so we need to manually resize\nfunction renderTextareaSize(textarea: Element) {\n\tif (textarea instanceof HTMLTextAreaElement) {\n\t\ttextarea.style.setProperty(\"--mtds-textarea-height\", \"auto\");\n\t\ttextarea.style.setProperty(\n\t\t\t\"--mtds-textarea-height\",\n\t\t\t`${textarea.scrollHeight}px`,\n\t\t);\n\t}\n}\n\nconst getText = (style: CSSStyleDeclaration, key: string) =>\n\tstyle.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || \"\"; // slice to trim quotes\n\n// Setup translations from CSS custom properties\nfunction renderCombobox(el: UHTMLComboboxElement | null) {\n\tconst { control, list } = el || {};\n\n\tif (el && list && !el.hasAttribute(\"data-sr-added\")) {\n\t\tconst style = window.getComputedStyle(el);\n\t\tattr(el, \"data-sr-added\", getText(style, \"combobox-added\"));\n\t\tattr(el, \"data-sr-empty\", getText(style, \"combobox-empty\"));\n\t\tattr(el, \"data-sr-found\", getText(style, \"combobox-found\"));\n\t\tattr(el, \"data-sr-invalid\", getText(style, \"combobox-invalid\"));\n\t\tattr(el, \"data-sr-of\", getText(style, \"combobox-of\"));\n\t\tattr(el, \"data-sr-remove\", getText(style, \"combobox-remove\"));\n\t\tattr(el, \"data-sr-removed\", getText(style, \"combobox-removed\"));\n\t\tattr(list, \"data-sr-plural\", getText(style, \"datalist-plural\"));\n\t\tattr(list, \"data-sr-singular\", getText(style, \"datalist-singular\"));\n\t}\n\tif (list && control && !list.hasAttribute(\"popover\")) {\n\t\tattr(list, \"popover\", \"manual\");\n\t\tattr(control, \"popovertarget\", useId(list));\n\t}\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n\tconst el = input?.nextElementSibling;\n\tconst limit = el && attr(el, \"data-count\");\n\n\tif (el && limit) {\n\t\tconst remainder = Number(limit) - input.value.length;\n\t\tconst nextInvalid = remainder < 0;\n\t\tconst prevInvalid = attr(el, \"aria-live\") === \"polite\";\n\t\tconst style = window.getComputedStyle(el || input);\n\t\tconst over = getText(style, \"count-over\");\n\t\tconst under = getText(style, \"count-under\");\n\n\t\tif (prevInvalid !== nextInvalid) {\n\t\t\tattr(el, \"aria-live\", nextInvalid ? \"polite\" : \"off\");\n\t\t\tfor (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n\t\t}\n\t\tel.textContent = (nextInvalid ? over : under).replace(\n\t\t\t\"%d\",\n\t\t\t`${Math.abs(remainder)}`,\n\t\t);\n\t}\n}\n\nfunction handleFieldToggle({ target: el, newState }: Partial<ToggleEvent>) {\n\tif (el instanceof UHTMLDataListElement) {\n\t\tconst root = el.getRootNode() as ShadowRoot | null;\n\t\tconst anchor = root?.querySelector<HTMLElement>(\n\t\t\t`[popovertarget=\"${el.id}\"]`,\n\t\t);\n\n\t\tif (newState === \"closed\") anchorPosition(el, false);\n\t\telse if (anchor)\n\t\t\tanchorPosition(el, anchor, {\n\t\t\t\tcontain({ availableHeight }) {\n\t\t\t\t\tel.style.width = `${anchor.clientWidth}px`;\n\t\t\t\t\tel.style.maxHeight = `${Math.max(50, availableHeight)}px`;\n\t\t\t\t},\n\t\t\t});\n\t}\n}\n// Update when typing\nfunction handleFieldInput(event: Event) {\n\tif (isInputLike(event.target)) {\n\t\trenderCounter(event.target);\n\t\trenderTextareaSize(event.target);\n\t}\n}\n\nfunction handleFieldValdiation(event: Event) {\n\tconst field = (event.target as Element)?.closest?.(`.${CSS_FIELD}`);\n\tif (event.type === \"invalid\" && field) event.preventDefault(); // Prevent browsers from showing default validation bubbles\n\tif (handleFieldMutation(true)) event.preventDefault(); // Prevent submit if invalid fields found\n}\n\nonLoaded(() => [\n\tonMutation(() => handleFieldMutation(), \"class\"),\n\ton(document, \"input\", handleFieldInput, QUICK_EVENT),\n\ton(document, \"toggle\", handleFieldToggle, QUICK_EVENT), // Use capture since toggle does not bubble\n\ton(document, \"invalid,submit\", handleFieldValdiation, true), // Use capture as invalid and submit does not bubble\n]);\n"],"names":["CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","FIELDS","IS_BROWSER","handleFieldMutation","validate","firstInvalid","field","labels","descriptions","validationMsg","combobox","input","valid","el","UHTMLComboboxElement","isInputLike","attr","desc","comboboxInput","label","useId","renderCombobox","renderCounter","renderTextareaSize","textarea","getText","style","key","control","list","limit","remainder","nextInvalid","prevInvalid","over","under","css","handleFieldToggle","newState","UHTMLDataListElement","anchor","anchorPosition","availableHeight","handleFieldInput","event","handleFieldValdiation","onLoaded","onMutation","on","QUICK_EVENT"],"mappings":";;;;AAeA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAkBD,EAAO,WAAW,MAAM,GAAG,GAC7CE,IAAiBD,EAAgB,CAAC,GAClCE,IAASC,IAAa,SAAS,uBAAuBL,CAAS,IAAI,CAAA;AAEzE,SAASM,EAAoBC,G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7B,EAAY6B,EAAM,MAAM,MAC3BtB,EAAcsB,EAAM,MAAM,GAC1BrB,EAAmBqB,EAAM,MAAM;AAEjC;AAEA,SAASC,EAAsBD,GAAc;AAC5C,QAAMtC,IAASsC,EAAM,QAAoB,UAAU,IAAI/C,CAAS,EAAE;AAClE,EAAI+C,EAAM,SAAS,aAAatC,OAAa,eAAA,GACzCH,EAAoB,EAAI,KAAGyC,EAAM,eAAA;AACtC;AAEAE,EAAS,MAAM;AAAA,EACdC,EAAW,MAAM5C,EAAA,GAAuB,OAAO;AAAA,EAC/C6C,EAAG,UAAU,SAASL,GAAkBM,CAAW;AAAA,EACnDD,EAAG,UAAU,UAAUX,GAAmBY,CAAW;AAAA;AAAA,EACrDD,EAAG,UAAU,kBAAkBH,GAAuB,EAAI;AAAA;AAC3D,CAAC;"}
@@ -4,6 +4,7 @@ import { JSX } from 'react';
4
4
  import { InputProps } from '../input/input';
5
5
  import { PolymorphicComponentPropWithRef } from '../react-types';
6
6
  type FieldBaseProps = {
7
+ "data-validation"?: "form" | "false" | false;
7
8
  count?: number;
8
9
  description?: React.ReactNode;
9
10
  error?: React.ReactNode;
@@ -1,154 +1,159 @@
1
1
  'use client';
2
- import { jsx as e, Fragment as I, jsxs as j } from "react/jsx-runtime";
2
+ import { jsx as e, Fragment as I, jsxs as D } from "react/jsx-runtime";
3
3
  import k from "clsx";
4
- import { forwardRef as p, useRef as z, useImperativeHandle as K, useEffect as M } from "react";
5
- import { HelpText as Q } from "../helptext/helptext.js";
4
+ import { forwardRef as p, useRef as z, useImperativeHandle as M, useEffect as Q } from "react";
5
+ import { HelpText as T } from "../helptext/helptext.js";
6
6
  import { Input as U } from "../input/input.js";
7
- import g from "../styles.module.css.js";
8
- import { toCustomElementProps as N } from "../utils.js";
9
- const P = (o) => typeof o == "string" ? { label: o, value: o } : o, V = p(function({
7
+ import j from "../styles.module.css.js";
8
+ import { toCustomElementProps as E } from "../utils.js";
9
+ import { Validation as X } from "../validation/validation.js";
10
+ const P = (o) => typeof o == "string" ? { label: o, value: o } : o, Y = p(function({
10
11
  "data-size": t,
11
- as: n,
12
- className: a,
12
+ "data-validation": n,
13
+ as: i,
14
+ className: m,
13
15
  count: u,
14
- description: m,
15
- error: F,
16
+ description: f,
17
+ error: g,
16
18
  helpText: y,
17
- helpTextLabel: H,
18
- label: f,
19
- prefix: b,
20
- style: D,
21
- suffix: h,
22
- validation: C,
23
- ...i
24
- }, v) {
25
- const l = n || "div", E = !!h || !!b, W = C || F, O = {
19
+ helpTextLabel: C,
20
+ label: b,
21
+ prefix: h,
22
+ style: L,
23
+ suffix: v,
24
+ validation: H,
25
+ ...r
26
+ }, x) {
27
+ const d = i || "div", N = !!v || !!h, W = H || g, O = {
26
28
  "data-size": t,
27
- className: k(g.field, a),
28
- style: D
29
+ "data-validation": n,
30
+ className: k(j.field, m),
31
+ style: L
29
32
  };
30
- return n === "select" && !i.children && Object.assign(i, {
33
+ return i === "select" && !r.children && Object.assign(r, {
31
34
  options: void 0,
32
35
  // Ensure options is not passed to DOM
33
- children: /* @__PURE__ */ e(I, { children: i.options?.map(P).map(({ label: x, value: d }) => /* @__PURE__ */ e("option", { value: d, children: x }, d)) })
34
- }), n ? /* @__PURE__ */ j("div", { ...O, children: [
35
- !!f && /* @__PURE__ */ e("label", { suppressHydrationWarning: !0, children: f }),
36
- !!y && /* @__PURE__ */ e(Q, { "aria-label": H, children: y }),
37
- !!m && /* @__PURE__ */ e("p", { suppressHydrationWarning: !0, children: m }),
38
- E ? /* @__PURE__ */ j(S, { children: [
39
- !!b && /* @__PURE__ */ e("span", { children: b }),
36
+ children: /* @__PURE__ */ e(I, { children: r.options?.map(P).map(({ label: F, value: l }) => /* @__PURE__ */ e("option", { value: l, children: F }, l)) })
37
+ }), i ? /* @__PURE__ */ D("div", { ...O, children: [
38
+ !!b && /* @__PURE__ */ e("label", { suppressHydrationWarning: !0, children: b }),
39
+ !!y && /* @__PURE__ */ e(T, { "aria-label": C, children: y }),
40
+ !!f && /* @__PURE__ */ e("p", { suppressHydrationWarning: !0, children: f }),
41
+ N ? /* @__PURE__ */ D(S, { children: [
42
+ !!h && /* @__PURE__ */ e("span", { children: h }),
40
43
  /* @__PURE__ */ e(
41
- l,
44
+ d,
42
45
  {
43
- className: g.input,
46
+ className: j.input,
44
47
  suppressHydrationWarning: !0,
45
- ref: v,
46
- ...i
48
+ ref: x,
49
+ ...r
47
50
  }
48
51
  ),
49
- !!h && /* @__PURE__ */ e("span", { children: h })
52
+ !!v && /* @__PURE__ */ e("span", { children: v })
50
53
  ] }) : /* @__PURE__ */ e(
51
- l,
54
+ d,
52
55
  {
53
- className: typeof n == "string" ? g.input : void 0,
56
+ className: typeof i == "string" ? j.input : void 0,
54
57
  suppressHydrationWarning: !0,
55
- ref: v,
56
- ...i
58
+ ref: x,
59
+ ...r
57
60
  }
58
61
  ),
59
- !!W && /* @__PURE__ */ e("div", { suppressHydrationWarning: !0, className: g.validation, children: W }),
62
+ !!W && /* @__PURE__ */ e(X, { hidden: n === "form", children: W }),
60
63
  !!u && /* @__PURE__ */ e("p", { suppressHydrationWarning: !0, "data-count": u })
61
- ] }) : /* @__PURE__ */ e("div", { ref: v, ...O, ...i });
64
+ ] }) : /* @__PURE__ */ e("div", { ref: x, ...O, ...r });
62
65
  }), S = p(
63
- function({ className: t, ...n }, a) {
64
- return /* @__PURE__ */ e("div", { className: k(g.affixes, t), ref: a, ...n });
66
+ function({ className: t, ...n }, i) {
67
+ return /* @__PURE__ */ e("div", { className: k(j.affixes, t), ref: i, ...n });
65
68
  }
66
- ), T = p(
67
- function({ "data-nofilter": t, ...n }, a) {
69
+ ), V = p(
70
+ function({ "data-nofilter": t, ...n }, i) {
68
71
  return /* @__PURE__ */ e(
69
72
  "u-datalist",
70
73
  {
71
74
  "data-nofilter": !!t || void 0,
72
- ref: a,
73
- ...N(n)
75
+ ref: i,
76
+ ...E(n)
74
77
  }
75
78
  );
76
79
  }
77
- ), q = p(
80
+ ), B = p(
78
81
  function(t, n) {
79
- return /* @__PURE__ */ e("u-option", { ref: n, ...N(t) });
82
+ return /* @__PURE__ */ e("u-option", { ref: n, ...E(t) });
80
83
  }
81
- ), X = p(
84
+ ), Z = p(
82
85
  function({
83
- "data-multiple": t,
84
- "data-nofilter": n,
85
- "data-position": a,
86
+ "aria-required": t,
87
+ "data-position": n,
88
+ "data-nofilter": i,
89
+ "data-multiple": m,
86
90
  onAfterChange: u,
87
- onAfterSelect: m,
88
- onBeforeChange: F,
91
+ onAfterSelect: f,
92
+ onBeforeChange: g,
89
93
  onBeforeMatch: y,
90
- onBeforeSelect: H,
91
- onSelectedChange: f,
92
- children: b,
93
- disabled: D,
94
- name: h,
95
- options: C,
96
- placeholder: i,
97
- readOnly: v,
98
- selected: l,
99
- type: E,
94
+ onBeforeSelect: C,
95
+ onSelectedChange: b,
96
+ children: h,
97
+ disabled: L,
98
+ name: v,
99
+ options: H,
100
+ placeholder: r,
101
+ readOnly: x,
102
+ selected: d,
103
+ type: N,
100
104
  ...W
101
105
  }, O) {
102
- const x = z(null), d = z(f);
103
- return d.current = f, u && (m = u, console.warn(
106
+ const F = z(null), l = z(b);
107
+ return l.current = b, u && (f = u, console.warn(
104
108
  "Combobox onAfterChange is deprecated, use onAfterSelect instead."
105
- )), F && (H = F, console.warn(
109
+ )), g && (C = g, console.warn(
106
110
  "Combobox onBeforeChange is deprecated, use onBeforeSelect instead."
107
- )), K(O, () => x.current), M(() => {
108
- const c = x.current, s = (r) => {
109
- const L = d.current;
110
- if (!d) return;
111
- r.preventDefault();
112
- const { isConnected: B, textContent: G, value: w } = r.detail, A = G?.trim() || "", R = l || [];
113
- L?.(B ? R.filter((J) => J.value !== w) : t ? [...R, { value: w, label: A }] : [{ value: w, label: A }]);
111
+ )), M(O, () => F.current), Q(() => {
112
+ const c = F.current, s = (a) => {
113
+ const w = l.current;
114
+ if (!l) return;
115
+ a.preventDefault();
116
+ const { isConnected: G, textContent: J, value: A } = a.detail, R = J?.trim() || "", q = d || [];
117
+ w?.(G ? q.filter((K) => K.value !== A) : m ? [...q, { value: A, label: R }] : [{ value: A, label: R }]);
114
118
  };
115
119
  return c?.addEventListener("comboboxbeforeselect", s), () => c?.removeEventListener("comboboxbeforeselect", s);
116
- }, [t, l]), /* @__PURE__ */ j(
120
+ }, [m, d]), /* @__PURE__ */ D(
117
121
  "u-combobox",
118
122
  {
119
- "data-multiple": t || void 0,
120
- ...N({
121
- oncomboboxbeforeselect: H,
123
+ "data-multiple": m || void 0,
124
+ ...E({
125
+ oncomboboxbeforeselect: C,
122
126
  oncomboboxbeforematch: y,
123
- oncomboboxafterselect: m,
124
- ref: x,
127
+ oncomboboxafterselect: f,
128
+ ref: F,
125
129
  ...W
126
130
  }),
127
131
  children: [
128
- l?.map(({ children: c, label: s, value: r }) => /* @__PURE__ */ e("data", { value: r, suppressHydrationWarning: !0, children: c ?? s }, r)),
129
- b || /* @__PURE__ */ j(I, { children: [
132
+ d?.map(({ children: c, label: s, value: a }) => /* @__PURE__ */ e("data", { value: a, suppressHydrationWarning: !0, children: c ?? s }, a)),
133
+ h || /* @__PURE__ */ D(I, { children: [
130
134
  /* @__PURE__ */ e(
131
135
  U,
132
136
  {
133
- name: h,
134
- type: E,
135
- disabled: D,
136
- readOnly: v,
137
- placeholder: i
137
+ "aria-required": t,
138
+ disabled: L,
139
+ name: v,
140
+ placeholder: r,
141
+ readOnly: x,
142
+ type: N
138
143
  }
139
144
  ),
140
- /* @__PURE__ */ e("del", { ...N({ "aria-label": "Fjern tekst" }) })
145
+ /* @__PURE__ */ e("del", { ...E({ "aria-label": "Fjern tekst" }) })
141
146
  ] }),
142
- !!C && /* @__PURE__ */ e(T, { "data-nofilter": n, "data-position": a, children: C.map(P).map(({ children: c, label: s, value: r }) => /* @__PURE__ */ e(q, { value: r, label: s, children: c ?? s }, r)) })
147
+ !!H && /* @__PURE__ */ e(V, { "data-nofilter": i, "data-position": n, children: H.map(P).map(({ children: c, label: s, value: a }) => /* @__PURE__ */ e(B, { value: a, label: s, children: c ?? s }, a)) })
143
148
  ]
144
149
  }
145
150
  );
146
151
  }
147
- ), oe = Object.assign(V, {
152
+ ), ae = Object.assign(Y, {
148
153
  Affixes: S,
149
- Combobox: X,
150
- Datalist: T,
151
- Option: q,
154
+ Combobox: Z,
155
+ Datalist: V,
156
+ Option: B,
152
157
  Label: p(
153
158
  function(t, n) {
154
159
  return /* @__PURE__ */ e("label", { suppressHydrationWarning: !0, ref: n, ...t });
@@ -156,7 +161,7 @@ const P = (o) => typeof o == "string" ? { label: o, value: o } : o, V = p(functi
156
161
  )
157
162
  });
158
163
  export {
159
- oe as Field,
160
- V as FieldComp
164
+ ae as Field,
165
+ Y as FieldComp
161
166
  };
162
167
  //# sourceMappingURL=field.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["\"use client\";\nimport type { Placement } from \"@floating-ui/dom\";\nimport type {\n\tReactUcombobox,\n\tUHTMLComboboxElement,\n} from \"@u-elements/u-combobox\";\nimport clsx from \"clsx\";\nimport type { JSX } from \"react\";\nimport { forwardRef, useEffect, useImperativeHandle, useRef } from \"react\";\nimport { HelpText } from \"../helptext/helptext\";\nimport { Input, type InputProps } from \"../input/input\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport { toCustomElementProps } from \"../utils\";\n\ntype FieldBaseProps = {\n\tcount?: number;\n\tdescription?: React.ReactNode;\n\terror?: React.ReactNode; // Kept for backwards compatibility\n\thelpText?: React.ReactNode;\n\thelpTextLabel?: string;\n\tlabel?: React.ReactNode;\n\toptions?: string[] | FieldComboboxSelected;\n\tprefix?: string;\n\treadOnly?: boolean; // Allow readoOnly also on <select>\n\tsuffix?: string;\n\tvalidation?: React.ReactNode;\n};\n\nexport type FieldProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As, FieldBaseProps>;\n\ntype FieldComponent = <As extends React.ElementType = \"div\">(\n\tprops: FieldProps<As>,\n) => JSX.Element;\n\nconst toOption = (\n\to: FieldComboboxSelected[number] | string,\n): FieldComboboxSelected[number] =>\n\ttypeof o === \"string\" ? { label: o, value: o } : o;\n\nexport const FieldComp: FieldComponent = forwardRef<null>(function Field<\n\tAs extends React.ElementType = \"div\",\n>(\n\t{\n\t\t\"data-size\": size,\n\t\tas,\n\t\tclassName,\n\t\tcount,\n\t\tdescription,\n\t\terror,\n\t\thelpText,\n\t\thelpTextLabel,\n\t\tlabel,\n\t\tprefix,\n\t\tstyle,\n\t\tsuffix,\n\t\tvalidation,\n\t\t...rest\n\t}: FieldProps<As>,\n\tref?: PolymorphicRef<As>,\n) {\n\tconst Tag = as || \"div\";\n\tconst affixes = !!suffix || !!prefix;\n\tconst valid = validation || error; // error kept for backwards compatibility\n\tconst shared = {\n\t\t\"data-size\": size,\n\t\tclassName: clsx(styles.field, className),\n\t\tstyle,\n\t};\n\n\t// Render options if select\n\tif (as === \"select\" && !rest.children)\n\t\tObject.assign(rest, {\n\t\t\toptions: undefined, // Ensure options is not passed to DOM\n\t\t\tchildren: (\n\t\t\t\t<>\n\t\t\t\t\t{(rest.options as FieldBaseProps[\"options\"])\n\t\t\t\t\t\t?.map(toOption)\n\t\t\t\t\t\t.map(({ label, value }) => (\n\t\t\t\t\t\t\t<option key={value} value={value}>\n\t\t\t\t\t\t\t\t{label}\n\t\t\t\t\t\t\t</option>\n\t\t\t\t\t\t))}\n\t\t\t\t</>\n\t\t\t),\n\t\t});\n\n\t// Using suppressHydrationWarning to avoid Next.js vs field-observer.ts hydration conflict\n\treturn as ? (\n\t\t<div {...shared}>\n\t\t\t{!!label && <label suppressHydrationWarning>{label}</label>}\n\t\t\t{!!helpText && <HelpText aria-label={helpTextLabel}>{helpText}</HelpText>}\n\t\t\t{!!description && <p suppressHydrationWarning>{description}</p>}\n\t\t\t{affixes ? (\n\t\t\t\t<FieldAffixes>\n\t\t\t\t\t{!!prefix && <span>{prefix}</span>}\n\t\t\t\t\t<Tag\n\t\t\t\t\t\tclassName={styles.input}\n\t\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\t{...rest}\n\t\t\t\t\t/>\n\t\t\t\t\t{!!suffix && <span>{suffix}</span>}\n\t\t\t\t</FieldAffixes>\n\t\t\t) : (\n\t\t\t\t<Tag\n\t\t\t\t\tclassName={typeof as === \"string\" ? styles.input : undefined}\n\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\tref={ref}\n\t\t\t\t\t{...rest}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t{!!valid && (\n\t\t\t\t<div suppressHydrationWarning className={styles.validation}>\n\t\t\t\t\t{valid}\n\t\t\t\t</div>\n\t\t\t)}\n\t\t\t{!!count && <p suppressHydrationWarning data-count={count} />}\n\t\t</div>\n\t) : (\n\t\t<div ref={ref} {...shared} {...rest} />\n\t);\n}) as FieldComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport type FieldAffixProps = React.ComponentPropsWithoutRef<\"div\">;\nconst FieldAffixes = forwardRef<HTMLDivElement, FieldAffixProps>(\n\tfunction FieldAffixes({ className, ...rest }, ref) {\n\t\treturn (\n\t\t\t<div className={clsx(styles.affixes, className)} ref={ref} {...rest} />\n\t\t);\n\t},\n);\n\nexport type FieldDatalistProps = React.ComponentPropsWithoutRef<\"datalist\"> & {\n\t\"data-nofilter\"?: boolean;\n\t\"data-position\"?: Placement;\n};\n\nconst FieldDatalist = forwardRef<HTMLDataListElement, FieldDatalistProps>(\n\tfunction FieldDatalist({ \"data-nofilter\": filter, ...rest }, ref) {\n\t\treturn (\n\t\t\t<u-datalist\n\t\t\t\tdata-nofilter={!!filter || undefined} // Ensure data-nofilter is set correctly\n\t\t\t\tref={ref}\n\t\t\t\t{...toCustomElementProps(rest)}\n\t\t\t/>\n\t\t);\n\t},\n);\n\nexport type FieldOptionProps = React.ComponentPropsWithoutRef<\"option\">;\nconst FieldOption = forwardRef<HTMLOptionElement, FieldOptionProps>(\n\tfunction FieldOption(props, ref) {\n\t\treturn <u-option ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport type FieldComboboxSelected = {\n\tlabel: string;\n\tvalue: string;\n\tchildren?: React.ReactNode;\n}[];\nexport type FieldComboboxProps = Omit<\n\tReactUcombobox,\n\t\"onChange\" | \"onInput\"\n> & {\n\t\"data-creatable\"?: boolean;\n\t\"data-multiple\"?: boolean;\n\tonAfterChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonAfterSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonBeforeMatch?: (e: CustomEvent<HTMLOptionElement>) => void; // Custom event to handle before change\n\tonBeforeSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonSelectedChange?: (selected: FieldComboboxSelected) => void; // Allow onChange to be a function that returns void\n\toptions?: FieldComboboxSelected;\n\tselected?: FieldComboboxSelected; // Allow value to be a string or an array of strings for multiple select\n} & Pick<\n\t\tInputProps,\n\t\t| \"disabled\"\n\t\t| \"name\"\n\t\t| \"onChange\"\n\t\t| \"onInput\"\n\t\t| \"placeholder\"\n\t\t| \"readOnly\"\n\t\t| \"type\"\n\t\t| \"value\"\n\t> & // Allow input props to be passed down\n\tPick<FieldDatalistProps, \"data-position\" | \"data-nofilter\">; // Allow datalist props to be passed down\n\nconst FieldCombobox = forwardRef<UHTMLComboboxElement, FieldComboboxProps>(\n\tfunction FieldCombobox(\n\t\t{\n\t\t\t\"data-multiple\": multiple,\n\t\t\t\"data-nofilter\": nofilter,\n\t\t\t\"data-position\": position,\n\t\t\tonAfterChange,\n\t\t\tonAfterSelect,\n\t\t\tonBeforeChange,\n\t\t\tonBeforeMatch,\n\t\t\tonBeforeSelect,\n\t\t\tonSelectedChange,\n\t\t\tchildren,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\toptions,\n\t\t\tplaceholder,\n\t\t\treadOnly,\n\t\t\tselected,\n\t\t\ttype,\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) {\n\t\tconst innerRef = useRef<UHTMLComboboxElement>(null);\n\t\tconst onSelected = useRef(onSelectedChange);\n\t\tonSelected.current = onSelectedChange; // Sync the latest onSelectedChange function\n\n\t\t// Deprecated props\n\t\tif (onAfterChange) {\n\t\t\tonAfterSelect = onAfterChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onAfterChange is deprecated, use onAfterSelect instead.`,\n\t\t\t);\n\t\t}\n\t\tif (onBeforeChange) {\n\t\t\tonBeforeSelect = onBeforeChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onBeforeChange is deprecated, use onBeforeSelect instead.`,\n\t\t\t);\n\t\t}\n\n\t\t// Using useEffect for React 18 and lower compatibility\n\t\tuseImperativeHandle(ref, () => innerRef.current as UHTMLComboboxElement); // Forward innerRef\n\t\tuseEffect(() => {\n\t\t\tconst self = innerRef.current;\n\t\t\tconst handleChange = (event: CustomEvent<HTMLDataElement>) => {\n\t\t\t\tconst handleSelected = onSelected.current;\n\t\t\t\tif (!onSelected) return; // No onSelectedChange function provided, let u-combobox handle it\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst { isConnected: remove, textContent, value } = event.detail;\n\t\t\t\tconst label = textContent?.trim() || \"\";\n\t\t\t\tconst prev = selected || [];\n\n\t\t\t\tif (remove) handleSelected?.(prev.filter((i) => i.value !== value));\n\t\t\t\telse if (multiple) handleSelected?.([...prev, { value, label }]);\n\t\t\t\telse handleSelected?.([{ value, label }]);\n\t\t\t};\n\n\t\t\tself?.addEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t\treturn () =>\n\t\t\t\tself?.removeEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t}, [multiple, selected]);\n\n\t\treturn (\n\t\t\t<u-combobox\n\t\t\t\tdata-multiple={multiple || undefined}\n\t\t\t\t{...toCustomElementProps({\n\t\t\t\t\toncomboboxbeforeselect: onBeforeSelect,\n\t\t\t\t\toncomboboxbeforematch: onBeforeMatch,\n\t\t\t\t\toncomboboxafterselect: onAfterSelect,\n\t\t\t\t\tref: innerRef,\n\t\t\t\t\t...props,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{selected?.map(({ children, label, value }) => (\n\t\t\t\t\t<data key={value} value={value} suppressHydrationWarning>\n\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t</data>\n\t\t\t\t))}\n\t\t\t\t{children || (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\tname={name}\n\t\t\t\t\t\t\ttype={type}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<del {...toCustomElementProps({ \"aria-label\": \"Fjern tekst\" })} />\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t\t{!!options && (\n\t\t\t\t\t<FieldDatalist data-nofilter={nofilter} data-position={position}>\n\t\t\t\t\t\t{options.map(toOption).map(({ children, label, value }) => (\n\t\t\t\t\t\t\t<FieldOption key={value} value={value} label={label}>\n\t\t\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t\t\t</FieldOption>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</FieldDatalist>\n\t\t\t\t)}\n\t\t\t</u-combobox>\n\t\t);\n\t},\n);\n\nexport type FieldLabelProps = React.ComponentPropsWithoutRef<\"label\">;\nexport const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\tCombobox: FieldCombobox,\n\tDatalist: FieldDatalist,\n\tOption: FieldOption,\n\tLabel: forwardRef<HTMLLabelElement, FieldLabelProps>(\n\t\tfunction FieldLabel(rest, ref) {\n\t\t\treturn <label suppressHydrationWarning ref={ref} {...rest} />;\n\t\t},\n\t),\n});\n"],"names":["toOption","FieldComp","forwardRef","size","as","className","count","description","error","helpText","helpTextLabel","label","prefix","style","suffix","validation","rest","ref","Tag","affixes","valid","shared","clsx","styles","value","jsx","jsxs","HelpText","FieldAffixes","FieldDatalist","filter","toCustomElementProps","FieldOption","props","FieldCombobox","multiple","nofilter","position","onAfterChange","onAfterSelect","onBeforeChange","onBeforeMatch","onBeforeSelect","onSelectedChange","children","disabled","name","options","placeholder","readOnly","selected","type","innerRef","useRef","onSelected","useImperativeHandle","useEffect","self","handleChange","event","handleSelected","remove","textContent","prev","i","Fragment","Input","Field"],"mappings":";;;;;;;AAuCA,MAAMA,IAAW,CAChB,MAEA,OAAO,KAAM,WAAW,EAAE,OAAO,GAAG,OAAO,EAAA,IAAM,GAErCC,IAA4BC,EAAiB,SAGzD;AAAA,EACC,aAAaC;AAAA,EACb,IAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,eAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAAC;AAAA,EACA,GAAGC;AACJ,GACAC,GACC;AACD,QAAMC,IAAMd,KAAM,OACZe,IAAU,CAAC,CAACL,KAAU,CAAC,CAACF,GACxBQ,IAAQL,KAAcP,GACtBa,IAAS;AAAA,IACd,aAAalB;AAAA,IACb,WAAWmB,EAAKC,EAAO,OAAOlB,CAAS;AAAA,IACvC,OAAAQ;AAAA,EAAA;AAID,SAAIT,MAAO,YAAY,CAACY,EAAK,YAC5B,OAAO,OAAOA,GAAM;AAAA,IACnB,SAAS;AAAA;AAAA,IACT,iCAEI,UAAAA,EAAK,SACJ,IAAIhB,CAAQ,EACb,IAAI,CAAC,EAAE,OAAAW,GAAO,OAAAa,EAAA,MACd,gBAAAC,EAAC,UAAA,EAAmB,OAAAD,GAClB,UAAAb,EAAAA,GADWa,CAEb,CACA,EAAA,CACH;AAAA,EAAA,CAED,GAGKpB,IACN,gBAAAsB,EA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AAA,CAAG;AAAA,UAAA,GACjE;AAAA,UAEA,CAAC,CAACgB,KACF,gBAAAtB,EAACI,GAAA,EAAc,iBAAeO,GAAU,iBAAeC,GACrD,UAAAU,EAAQ,IAAI/C,CAAQ,EAAE,IAAI,CAAC,EAAE,UAAA4C,GAAU,OAAAjC,GAAO,OAAAa,EAAA,MAC9C,gBAAAC,EAACO,GAAA,EAAwB,OAAAR,GAAc,OAAAb,GACrC,UAAAiC,KAAYjC,EAAA,GADIa,CAElB,CACA,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIJ;AACD,GAGa2C,KAAQ,OAAO,OAAOlE,GAAW;AAAA,EAC7C,SAAS2B;AAAA,EACT,UAAUM;AAAA,EACV,UAAUL;AAAA,EACV,QAAQG;AAAA,EACR,OAAO9B;AAAA,IACN,SAAoBc,GAAMC,GAAK;AAC9B,+BAAQ,SAAA,EAAM,0BAAwB,IAAC,KAAAA,GAAW,GAAGD,GAAM;AAAA,IAC5D;AAAA,EAAA;AAEF,CAAC;"}
1
+ {"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["\"use client\";\nimport type { Placement } from \"@floating-ui/dom\";\nimport type {\n\tReactUcombobox,\n\tUHTMLComboboxElement,\n} from \"@u-elements/u-combobox\";\nimport clsx from \"clsx\";\nimport type { JSX } from \"react\";\nimport { forwardRef, useEffect, useImperativeHandle, useRef } from \"react\";\nimport { HelpText } from \"../helptext/helptext\";\nimport { Input, type InputProps } from \"../input/input\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport { toCustomElementProps } from \"../utils\";\nimport { Validation } from \"../validation/validation\";\n\ntype FieldBaseProps = {\n\t\"data-validation\"?: \"form\" | \"false\" | false;\n\tcount?: number;\n\tdescription?: React.ReactNode;\n\terror?: React.ReactNode; // Kept for backwards compatibility\n\thelpText?: React.ReactNode;\n\thelpTextLabel?: string;\n\tlabel?: React.ReactNode;\n\toptions?: string[] | FieldComboboxSelected;\n\tprefix?: string;\n\treadOnly?: boolean; // Allow readoOnly also on <select>\n\tsuffix?: string;\n\tvalidation?: React.ReactNode;\n};\n\nexport type FieldProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As, FieldBaseProps>;\n\ntype FieldComponent = <As extends React.ElementType = \"div\">(\n\tprops: FieldProps<As>,\n) => JSX.Element;\n\nconst toOption = (\n\to: FieldComboboxSelected[number] | string,\n): FieldComboboxSelected[number] =>\n\ttypeof o === \"string\" ? { label: o, value: o } : o;\n\nexport const FieldComp: FieldComponent = forwardRef<null>(function Field<\n\tAs extends React.ElementType = \"div\",\n>(\n\t{\n\t\t\"data-size\": size,\n\t\t\"data-validation\": validationType,\n\t\tas,\n\t\tclassName,\n\t\tcount,\n\t\tdescription,\n\t\terror,\n\t\thelpText,\n\t\thelpTextLabel,\n\t\tlabel,\n\t\tprefix,\n\t\tstyle,\n\t\tsuffix,\n\t\tvalidation: validationContent,\n\t\t...rest\n\t}: FieldProps<As>,\n\tref?: PolymorphicRef<As>,\n) {\n\tconst Tag = as || \"div\";\n\tconst affixes = !!suffix || !!prefix;\n\tconst validation = validationContent || error; // error kept for backwards compatibility\n\tconst shared = {\n\t\t\"data-size\": size,\n\t\t\"data-validation\": validationType,\n\t\tclassName: clsx(styles.field, className),\n\t\tstyle,\n\t};\n\n\t// Render options if select\n\tif (as === \"select\" && !rest.children)\n\t\tObject.assign(rest, {\n\t\t\toptions: undefined, // Ensure options is not passed to DOM\n\t\t\tchildren: (\n\t\t\t\t<>\n\t\t\t\t\t{(rest.options as FieldBaseProps[\"options\"])\n\t\t\t\t\t\t?.map(toOption)\n\t\t\t\t\t\t.map(({ label, value }) => (\n\t\t\t\t\t\t\t<option key={value} value={value}>\n\t\t\t\t\t\t\t\t{label}\n\t\t\t\t\t\t\t</option>\n\t\t\t\t\t\t))}\n\t\t\t\t</>\n\t\t\t),\n\t\t});\n\n\t// Using suppressHydrationWarning to avoid Next.js vs field-observer.ts hydration conflict\n\treturn as ? (\n\t\t<div {...shared}>\n\t\t\t{!!label && <label suppressHydrationWarning>{label}</label>}\n\t\t\t{!!helpText && <HelpText aria-label={helpTextLabel}>{helpText}</HelpText>}\n\t\t\t{!!description && <p suppressHydrationWarning>{description}</p>}\n\t\t\t{affixes ? (\n\t\t\t\t<FieldAffixes>\n\t\t\t\t\t{!!prefix && <span>{prefix}</span>}\n\t\t\t\t\t<Tag\n\t\t\t\t\t\tclassName={styles.input}\n\t\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\t\tref={ref}\n\t\t\t\t\t\t{...rest}\n\t\t\t\t\t/>\n\t\t\t\t\t{!!suffix && <span>{suffix}</span>}\n\t\t\t\t</FieldAffixes>\n\t\t\t) : (\n\t\t\t\t<Tag\n\t\t\t\t\tclassName={typeof as === \"string\" ? styles.input : undefined}\n\t\t\t\t\tsuppressHydrationWarning\n\t\t\t\t\tref={ref}\n\t\t\t\t\t{...rest}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t{!!validation && (\n\t\t\t\t<Validation hidden={validationType === \"form\"}>{validation}</Validation>\n\t\t\t)}\n\t\t\t{!!count && <p suppressHydrationWarning data-count={count} />}\n\t\t</div>\n\t) : (\n\t\t<div ref={ref} {...shared} {...rest} />\n\t);\n}) as FieldComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport type FieldAffixProps = React.ComponentPropsWithoutRef<\"div\">;\nconst FieldAffixes = forwardRef<HTMLDivElement, FieldAffixProps>(\n\tfunction FieldAffixes({ className, ...rest }, ref) {\n\t\treturn (\n\t\t\t<div className={clsx(styles.affixes, className)} ref={ref} {...rest} />\n\t\t);\n\t},\n);\n\nexport type FieldDatalistProps = React.ComponentPropsWithoutRef<\"datalist\"> & {\n\t\"data-nofilter\"?: boolean;\n\t\"data-position\"?: Placement;\n};\n\nconst FieldDatalist = forwardRef<HTMLDataListElement, FieldDatalistProps>(\n\tfunction FieldDatalist({ \"data-nofilter\": filter, ...rest }, ref) {\n\t\treturn (\n\t\t\t<u-datalist\n\t\t\t\tdata-nofilter={!!filter || undefined} // Ensure data-nofilter is set correctly\n\t\t\t\tref={ref}\n\t\t\t\t{...toCustomElementProps(rest)}\n\t\t\t/>\n\t\t);\n\t},\n);\n\nexport type FieldOptionProps = React.ComponentPropsWithoutRef<\"option\">;\nconst FieldOption = forwardRef<HTMLOptionElement, FieldOptionProps>(\n\tfunction FieldOption(props, ref) {\n\t\treturn <u-option ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport type FieldComboboxSelected = {\n\tlabel: string;\n\tvalue: string;\n\tchildren?: React.ReactNode;\n}[];\nexport type FieldComboboxProps = Omit<\n\tReactUcombobox,\n\t\"onChange\" | \"onInput\"\n> & {\n\t\"data-creatable\"?: boolean;\n\t\"data-multiple\"?: boolean;\n\tonAfterChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonAfterSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonBeforeMatch?: (e: CustomEvent<HTMLOptionElement>) => void; // Custom event to handle before change\n\tonBeforeSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonSelectedChange?: (selected: FieldComboboxSelected) => void; // Allow onChange to be a function that returns void\n\toptions?: FieldComboboxSelected;\n\tselected?: FieldComboboxSelected; // Allow value to be a string or an array of strings for multiple select\n} & Pick<\n\t\tInputProps,\n\t\t| \"disabled\"\n\t\t| \"name\"\n\t\t| \"onChange\"\n\t\t| \"onInput\"\n\t\t| \"placeholder\"\n\t\t| \"readOnly\"\n\t\t| \"type\"\n\t\t| \"value\"\n\t> & // Allow input props to be passed down\n\tPick<FieldDatalistProps, \"data-position\" | \"data-nofilter\">; // Allow datalist props to be passed down\n\nconst FieldCombobox = forwardRef<UHTMLComboboxElement, FieldComboboxProps>(\n\tfunction FieldCombobox(\n\t\t{\n\t\t\t\"aria-required\": required,\n\t\t\t\"data-position\": position,\n\t\t\t\"data-nofilter\": nofilter,\n\t\t\t\"data-multiple\": multiple,\n\t\t\tonAfterChange,\n\t\t\tonAfterSelect,\n\t\t\tonBeforeChange,\n\t\t\tonBeforeMatch,\n\t\t\tonBeforeSelect,\n\t\t\tonSelectedChange,\n\t\t\tchildren,\n\t\t\tdisabled,\n\t\t\tname,\n\t\t\toptions,\n\t\t\tplaceholder,\n\t\t\treadOnly,\n\t\t\tselected,\n\t\t\ttype,\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) {\n\t\tconst innerRef = useRef<UHTMLComboboxElement>(null);\n\t\tconst onSelected = useRef(onSelectedChange);\n\t\tonSelected.current = onSelectedChange; // Sync the latest onSelectedChange function\n\n\t\t// Deprecated props\n\t\tif (onAfterChange) {\n\t\t\tonAfterSelect = onAfterChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onAfterChange is deprecated, use onAfterSelect instead.`,\n\t\t\t);\n\t\t}\n\t\tif (onBeforeChange) {\n\t\t\tonBeforeSelect = onBeforeChange;\n\t\t\tconsole.warn(\n\t\t\t\t`Combobox onBeforeChange is deprecated, use onBeforeSelect instead.`,\n\t\t\t);\n\t\t}\n\n\t\t// Using useEffect for React 18 and lower compatibility\n\t\tuseImperativeHandle(ref, () => innerRef.current as UHTMLComboboxElement); // Forward innerRef\n\t\tuseEffect(() => {\n\t\t\tconst self = innerRef.current;\n\t\t\tconst handleChange = (event: CustomEvent<HTMLDataElement>) => {\n\t\t\t\tconst handleSelected = onSelected.current;\n\t\t\t\tif (!onSelected) return; // No onSelectedChange function provided, let u-combobox handle it\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst { isConnected: remove, textContent, value } = event.detail;\n\t\t\t\tconst label = textContent?.trim() || \"\";\n\t\t\t\tconst prev = selected || [];\n\n\t\t\t\tif (remove) handleSelected?.(prev.filter((i) => i.value !== value));\n\t\t\t\telse if (multiple) handleSelected?.([...prev, { value, label }]);\n\t\t\t\telse handleSelected?.([{ value, label }]);\n\t\t\t};\n\n\t\t\tself?.addEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t\treturn () =>\n\t\t\t\tself?.removeEventListener(\"comboboxbeforeselect\", handleChange);\n\t\t}, [multiple, selected]);\n\n\t\treturn (\n\t\t\t<u-combobox\n\t\t\t\tdata-multiple={multiple || undefined}\n\t\t\t\t{...toCustomElementProps({\n\t\t\t\t\toncomboboxbeforeselect: onBeforeSelect,\n\t\t\t\t\toncomboboxbeforematch: onBeforeMatch,\n\t\t\t\t\toncomboboxafterselect: onAfterSelect,\n\t\t\t\t\tref: innerRef,\n\t\t\t\t\t...props,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{selected?.map(({ children, label, value }) => (\n\t\t\t\t\t<data key={value} value={value} suppressHydrationWarning>\n\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t</data>\n\t\t\t\t))}\n\t\t\t\t{children || (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\taria-required={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\tname={name}\n\t\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\ttype={type}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<del {...toCustomElementProps({ \"aria-label\": \"Fjern tekst\" })} />\n\t\t\t\t\t</>\n\t\t\t\t)}\n\t\t\t\t{!!options && (\n\t\t\t\t\t<FieldDatalist data-nofilter={nofilter} data-position={position}>\n\t\t\t\t\t\t{options.map(toOption).map(({ children, label, value }) => (\n\t\t\t\t\t\t\t<FieldOption key={value} value={value} label={label}>\n\t\t\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t\t\t</FieldOption>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</FieldDatalist>\n\t\t\t\t)}\n\t\t\t</u-combobox>\n\t\t);\n\t},\n);\n\nexport type FieldLabelProps = React.ComponentPropsWithoutRef<\"label\">;\nexport const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\tCombobox: FieldCombobox,\n\tDatalist: FieldDatalist,\n\tOption: FieldOption,\n\tLabel: forwardRef<HTMLLabelElement, FieldLabelProps>(\n\t\tfunction FieldLabel(rest, ref) {\n\t\t\treturn <label suppressHydrationWarning ref={ref} {...rest} />;\n\t\t},\n\t),\n});\n"],"names":["toOption","FieldComp","forwardRef","size","validationType","as","className","count","description","error","helpText","helpTextLabel","label","prefix","style","suffix","validationContent","rest","ref","Tag","affixes","validation","shared","clsx","styles","value","jsx","jsxs","HelpText","FieldAffixes","Validation","FieldDatalist","filter","toCustomElementProps","FieldOption","props","FieldCombobox","required","position","nofilter","multiple","onAfterChange","onAfterSelect","onBeforeChange","onBeforeMatch","onBeforeSelect","onSelectedChange","children","disabled","name","options","placeholder","readOnly","selected","type","innerRef","useRef","onSelected","useImperativeHandle","useEffect","self","handleChange","event","handleSelected","remove","textContent","prev","i","Fragment","Input","Field"],"mappings":";;;;;;;;AAyCA,MAAMA,IAAW,CAChB,MAEA,OAAO,KAAM,WAAW,EAAE,OAAO,GAAG,OAAO,EAAA,IAAM,GAErCC,IAA4BC,EAAiB,SAGzD;AAAA,EACC,aAAaC;AAAA,EACb,mBAAmBC;AAAA,EACnB,IAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,eAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAYC;AAAA,EACZ,GAAGC;AACJ,GACAC,GACC;AACD,QAAMC,IAAMd,KAAM,OACZe,IAAU,CAAC,CAACL,KAAU,CAAC,CAACF,GACxBQ,IAAaL,KAAqBP,GAClCa,IAAS;AAAA,IACd,aAAanB;AAAA,IACb,mBAAmBC;AAAA,IACnB,WAAWm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