@mattilsynet/design 2.0.0 → 2.0.2

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,43 +1,44 @@
1
- import { UHTMLComboboxElement as g } from "../external/@u-elements/u-combobox/dist/u-combobox.js";
2
- import { UHTMLDataListElement as E } from "../external/@u-elements/u-datalist/dist/u-datalist.js";
1
+ import { UHTMLComboboxElement as h } from "../external/@u-elements/u-combobox/dist/u-combobox.js";
2
+ import { UHTMLDataListElement as S } from "../external/@u-elements/u-datalist/dist/u-datalist.js";
3
3
  import v from "../styles.module.css.js";
4
- import { onLoaded as I, onMutation as A, on as f, QUICK_EVENT as p, isInputLike as x, attr as n, useId as b, anchorPosition as m } from "../utils.js";
5
- const h = v.field.split(" ")[0], y = v.validation.split(" "), M = y[0], a = (t, o) => t.getPropertyValue(`--mtds-text-${o}`)?.slice(1, -1) || "";
6
- function T(t, o) {
7
- for (const s of t)
8
- if (s.isConnected) {
9
- const i = [], r = [], u = [];
4
+ import { onLoaded as M, onMutation as A, on as m, QUICK_EVENT as u, isInputLike as x, attr as n, useId as p, anchorPosition as b } from "../utils.js";
5
+ const g = v.field.split(" ")[0], y = v.validation.split(" "), H = y[0], s = (t, o) => t.getPropertyValue(`--mtds-text-${o}`)?.slice(1, -1) || "";
6
+ function L(t, o) {
7
+ for (const a of t)
8
+ if (a.isConnected) {
9
+ const i = [], r = [], f = [];
10
10
  let c = null, d = null, l = !0;
11
- for (const e of s.getElementsByTagName("*"))
12
- e instanceof HTMLLabelElement ? i.push(e) : e instanceof g ? c = e : x(e) && !e.hidden ? d = e : e.hasAttribute("data-description") ? r.push(e) : e.classList.contains(M) ? (l = n(e, "data-color") === "success" || !e.clientHeight, u.push(e), r.unshift(e)) : e instanceof HTMLParagraphElement && (r.some((C) => C.contains(e)) || r.push(e));
11
+ for (const e of a.getElementsByTagName("*"))
12
+ e instanceof HTMLLabelElement ? i.push(e) : e instanceof h ? c = e : x(e) && !e.hidden ? d = e : e.hasAttribute("data-description") ? r.push(e) : e.classList.contains(H) ? (l = n(e, "data-color") === "success" || !e.clientHeight, f.push(e), r.unshift(e)) : e instanceof HTMLParagraphElement && (r.some((I) => I.contains(e)) || r.push(e));
13
13
  if (d) {
14
- for (const e of i) e.htmlFor = b(d);
15
- if (o && n(s, "data-validation") === "form") {
14
+ for (const e of i) e.htmlFor = p(d);
15
+ if (o && n(a, "data-validation") === "form") {
16
16
  l = d.matches(":valid");
17
- for (const e of u) n(e, "hidden", l ? "" : null);
17
+ for (const e of f) n(e, "hidden", l ? "" : null);
18
18
  }
19
- H(c), S(d), L(d), n(d, "aria-describedby", r.map(b).join(" ") || null), n(d, "aria-invalid", `${!l}`);
19
+ N(c), E(d), T(d), n(d, "aria-describedby", r.map(p).join(" ") || null), n(d, "aria-invalid", `${!l}`);
20
20
  }
21
21
  }
22
22
  }
23
- function L(t) {
23
+ function T(t) {
24
24
  t instanceof HTMLTextAreaElement && (t.style.setProperty("--mtds-textarea-height", "auto"), t.style.setProperty(
25
25
  "--mtds-textarea-height",
26
26
  `${t.scrollHeight}px`
27
27
  ));
28
28
  }
29
- function H(t) {
30
- const { control: o, list: s } = t || {};
31
- if (t && s && o && !t.hasAttribute("data-sr-added")) {
29
+ function N(t) {
30
+ const { control: o, list: a } = t || {};
31
+ if (t && a && !t.hasAttribute("data-sr-added")) {
32
32
  const i = window.getComputedStyle(t);
33
- n(t, "data-sr-added", a(i, "combobox-added")), n(t, "data-sr-empty", a(i, "combobox-empty")), n(t, "data-sr-found", a(i, "combobox-found")), n(t, "data-sr-invalid", a(i, "combobox-invalid")), n(t, "data-sr-of", a(i, "combobox-of")), n(t, "data-sr-remove", a(i, "combobox-remove")), n(t, "data-sr-removed", a(i, "combobox-removed")), n(s, "data-sr-plural", a(i, "datalist-plural")), n(s, "data-sr-singular", a(i, "datalist-singular")), n(s, "popover", "manual"), n(o, "popovertarget", b(s));
33
+ n(t, "data-sr-added", s(i, "combobox-added")), n(t, "data-sr-empty", s(i, "combobox-empty")), n(t, "data-sr-found", s(i, "combobox-found")), n(t, "data-sr-invalid", s(i, "combobox-invalid")), n(t, "data-sr-of", s(i, "combobox-of")), n(t, "data-sr-remove", s(i, "combobox-remove")), n(t, "data-sr-removed", s(i, "combobox-removed")), n(a, "data-sr-plural", s(i, "datalist-plural")), n(a, "data-sr-singular", s(i, "datalist-singular"));
34
34
  }
35
+ a && o && !a.hasAttribute("popover") && (n(a, "popover", "manual"), n(o, "popovertarget", p(a)));
35
36
  }
36
- function S(t) {
37
- const o = t?.nextElementSibling, s = o && n(o, "data-count");
38
- if (o && s) {
39
- const i = Number(s) - t.value.length, r = i < 0, u = n(o, "aria-live") === "polite", c = window.getComputedStyle(o || t), d = a(c, "count-over"), l = a(c, "count-under");
40
- if (u !== r) {
37
+ function E(t) {
38
+ const o = t?.nextElementSibling, a = o && n(o, "data-count");
39
+ if (o && a) {
40
+ const i = Number(a) - t.value.length, r = i < 0, f = n(o, "aria-live") === "polite", c = window.getComputedStyle(o || t), d = s(c, "count-over"), l = s(c, "count-under");
41
+ if (f !== r) {
41
42
  n(o, "aria-live", r ? "polite" : "off");
42
43
  for (const e of y) o.classList.toggle(e, r);
43
44
  }
@@ -47,32 +48,29 @@ function S(t) {
47
48
  );
48
49
  }
49
50
  }
50
- function N({ target: t, newState: o }) {
51
- if (t instanceof E) {
51
+ function $({ target: t, newState: o }) {
52
+ if (t instanceof S) {
52
53
  const i = t.getRootNode()?.querySelector(
53
54
  `[popovertarget="${t.id}"]`
54
55
  );
55
- o === "closed" ? m(t, !1) : i && (t.style.width = `${i.clientWidth}px`, m(t, i, n(t, "data-position") ?? "bottom", !0));
56
+ o === "closed" ? b(t, !1) : i && (t.style.width = `${i.clientWidth}px`, b(t, i, n(t, "data-position") ?? "bottom", !0));
56
57
  }
57
58
  }
58
- function $({ target: t }) {
59
- if (x(t)) {
60
- S(t), L(t);
61
- const o = t.hasAttribute("list") && t.list;
62
- o && setTimeout(() => {
63
- m(o, t, n(o, "data-position") ?? "bottom", !0);
64
- }, 10);
65
- }
59
+ function D(t) {
60
+ x(t.target) && (E(t.target), T(t.target), C(t));
66
61
  }
67
- function w(t) {
68
- const o = t.target?.closest?.(`.${h}`);
69
- t.type === "invalid" && o && t.preventDefault(), T(document.getElementsByClassName(h), !0);
62
+ function P(t) {
63
+ const o = t.target?.closest?.(`.${g}`);
64
+ t.type === "invalid" && o && t.preventDefault(), L(document.getElementsByClassName(g), !0);
70
65
  }
71
- function D({ target: t }) {
72
- const o = t instanceof g && t.list;
73
- o && !o?.hidden && setTimeout(() => m(o, t, 2, !0), 10);
66
+ function C({ target: t }) {
67
+ const o = (t instanceof h || t instanceof HTMLInputElement) && t.list;
68
+ if (o && !o?.hidden) {
69
+ const a = n(o, "data-position") ?? "bottom";
70
+ setTimeout(() => b(o, t, a, !0), 10);
71
+ }
74
72
  }
75
- I(() => {
76
- A(document.documentElement, h, T), f(document, "comboboxbeforeselect", D, p), f(document, "input", $, p), f(document, "invalid,submit", w, !0), f(document, "toggle", N, p);
73
+ M(() => {
74
+ A(document.documentElement, g, L), m(document, "comboboxbeforeselect", C, u), m(document, "input", D, u), m(document, "invalid,submit", P, !0), m(document, "toggle", $, u);
77
75
  });
78
76
  //# sourceMappingURL=field-observer.js.map
@@ -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\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];\n\nconst getText = (style: CSSStyleDeclaration, key: string) =>\n\tstyle.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || \"\"; // slice to trim quotes\n\nfunction handleMutation(fields: HTMLCollectionOf<Element>, validate?: boolean) {\n\tfor (const field of fields)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descs: Element[] = [];\n\t\t\tconst valids: 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\")) descs.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\tvalids.push(el);\n\t\t\t\t\tdescs.unshift(el);\n\t\t\t\t} else if (el instanceof HTMLParagraphElement)\n\t\t\t\t\tdescs.some((desc) => desc.contains(el)) || descs.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\tfor (const el of valids) attr(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\", descs.map(useId).join(\" \") || null); // Remove if empty\n\t\t\t\tattr(input, \"aria-invalid\", `${!valid}`);\n\t\t\t}\n\t\t}\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 && control && !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\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 handleToggle({ target: el, newState }: Event & { newState?: string }) {\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\tel.style.width = `${anchor.clientWidth}px`;\n\t\t\tanchorPosition(el, anchor, attr(el, \"data-position\") ?? \"bottom\", true);\n\t\t}\n\t}\n}\n// Update when typing\nfunction handleInput({ target: el }: Event) {\n\tif (isInputLike(el)) {\n\t\trenderCounter(el);\n\t\trenderTextareaSize(el);\n\n\t\t// Reposition list datalist // TODO Enhance by using style.bottom?\n\t\tconst list = el.hasAttribute(\"list\") && el.list;\n\t\tif (list)\n\t\t\tsetTimeout(() => {\n\t\t\t\tanchorPosition(list, el, attr(list, \"data-position\") ?? \"bottom\", true);\n\t\t\t}, 10);\n\t}\n}\n\nfunction handleValdiation(event: Event) {\n\tconst field = (event.target as Element)?.closest?.(`.${CSS_FIELD}`);\n\n\tif (event.type === \"invalid\" && field) event.preventDefault(); // Prevent browsers from showing default validation bubbles\n\thandleMutation(document.getElementsByClassName(CSS_FIELD), true); // Update state\n}\n\n// Position combobox when changing content\nfunction handleSelect({ target: el }: Event) {\n\tconst list = el instanceof UHTMLComboboxElement && el.list;\n\tif (list && !list?.hidden)\n\t\tsetTimeout(() => anchorPosition(list, el, 2, true), 10); // Reposition list if not hidden\n}\n\nonLoaded(() => {\n\tonMutation(document.documentElement, CSS_FIELD, handleMutation);\n\ton(document, \"comboboxbeforeselect\", handleSelect, QUICK_EVENT);\n\ton(document, \"input\", handleInput, QUICK_EVENT);\n\ton(document, \"invalid,submit\", handleValdiation, true); // Use capture as invalid and submit does not bubble\n\ton(document, \"toggle\", handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n});\n"],"names":["CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","getText","style","key","handleMutation","fields","validate","field","labels","descs","valids","combobox","input","valid","el","UHTMLComboboxElement","isInputLike","attr","desc","label","useId","renderCombobox","renderCounter","renderTextareaSize","textarea","control","list","limit","remainder","nextInvalid","prevInvalid","over","under","css","handleToggle","newState","UHTMLDataListElement","anchor","anchorPosition","handleInput","handleValdiation","event","handleSelect","onLoaded","onMutation","on","QUICK_EVENT"],"mappings":";;;;AAcA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAkBD,EAAO,WAAW,MAAM,GAAG,GAC7CE,IAAiBD,EAAgB,CAAC,GAElCE,IAAU,CAACC,GAA4BC,MAC5CD,EAAM,iBAAiB,eAAeC,CAAG,EAAE,GAAG,MAAM,GAAG,EAAE,KAAK;AAE/D,SAASC,EAAeC,GAAmCC,GAAoB;AAC9E,aAAWC,KAASF;AACnB,QAAIE,EAAM,aAAa;AACtB,YAAMC,IAA6B,CAAC,GAC9BC,IAAmB,CAAC,GACpBC,IAAoB,CAAC;AAC3B,UAAIC,IAAwC,MACxCC,IAAiC,MACjCC,IAAQ;AAEZ,iBAAWC,KAAMP,EAAM,qBAAqB,GAAG;AAC9C,QAAIO,aAAc,mBAAyBN,EAAA,KAAKM,CAAE,IACzCA,aAAcC,IAAiCJ,IAAAG,IAC/CE,EAAYF,CAAE,KAAK,CAACA,EAAG,SAAgBF,IAAAE,IACvCA,EAAG,aAAa,kBAAkB,IAAGL,EAAM,KAAKK,CAAE,IAClDA,EAAG,UAAU,SAASd,CAAc,KAC5Ca,IAAQI,EAAKH,GAAI,YAAY,MAAM,aAAa,CAACA,EAAG,cACpDJ,EAAO,KAAKI,CAAE,GACdL,EAAM,QAAQK,CAAE,KACNA,aAAc,yBAClBL,EAAA,KAAK,CAACS,MAASA,EAAK,SAASJ,CAAE,CAAC,KAAKL,EAAM,KAAKK,CAA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KH,GAAI,eAAe,KAAK,UAAU,EAAI;AAAA,EACvE;AAEF;AAEA,SAASyB,EAAY,EAAE,QAAQzB,KAAa;AACvC,MAAAE,EAAYF,CAAE,GAAG;AACpB,IAAAQ,EAAcR,CAAE,GAChBS,EAAmBT,CAAE;AAGrB,UAAMY,IAAOZ,EAAG,aAAa,MAAM,KAAKA,EAAG;AACvC,IAAAY,KACH,WAAW,MAAM;AAChB,MAAAY,EAAeZ,GAAMZ,GAAIG,EAAKS,GAAM,eAAe,KAAK,UAAU,EAAI;AAAA,OACpE,EAAE;AAAA,EAAA;AAER;AAEA,SAASc,EAAiBC,GAAc;AACvC,QAAMlC,IAASkC,EAAM,QAAoB,UAAU,IAAI5C,CAAS,EAAE;AAElE,EAAI4C,EAAM,SAAS,aAAalC,OAAa,eAAe,GAC5DH,EAAe,SAAS,uBAAuBP,CAAS,GAAG,EAAI;AAChE;AAGA,SAAS6C,EAAa,EAAE,QAAQ5B,KAAa;AACtC,QAAAY,IAAOZ,aAAcC,KAAwBD,EAAG;AAClD,EAAAY,KAAQ,CAACA,GAAM,UAClB,WAAW,MAAMY,EAAeZ,GAAMZ,GAAI,GAAG,EAAI,GAAG,EAAE;AACxD;AAEA6B,EAAS,MAAM;AACH,EAAAC,EAAA,SAAS,iBAAiB/C,GAAWO,CAAc,GAC3DyC,EAAA,UAAU,wBAAwBH,GAAcI,CAAW,GAC3DD,EAAA,UAAU,SAASN,GAAaO,CAAW,GAC3CD,EAAA,UAAU,kBAAkBL,GAAkB,EAAI,GAClDK,EAAA,UAAU,UAAUX,GAAcY,CAAW;AACjD,CAAC;"}
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\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];\n\nconst getText = (style: CSSStyleDeclaration, key: string) =>\n\tstyle.getPropertyValue(`--mtds-text-${key}`)?.slice(1, -1) || \"\"; // slice to trim quotes\n\nfunction handleMutation(fields: HTMLCollectionOf<Element>, validate?: boolean) {\n\tfor (const field of fields)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descs: Element[] = [];\n\t\t\tconst valids: 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\")) descs.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\tvalids.push(el);\n\t\t\t\t\tdescs.unshift(el);\n\t\t\t\t} else if (el instanceof HTMLParagraphElement)\n\t\t\t\t\tdescs.some((desc) => desc.contains(el)) || descs.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\tfor (const el of valids) attr(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\", descs.map(useId).join(\" \") || null); // Remove if empty\n\t\t\t\tattr(input, \"aria-invalid\", `${!valid}`);\n\t\t\t}\n\t\t}\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 handleToggle({ target: el, newState }: Event & { newState?: string }) {\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\tel.style.width = `${anchor.clientWidth}px`;\n\t\t\tanchorPosition(el, anchor, attr(el, \"data-position\") ?? \"bottom\", true);\n\t\t}\n\t}\n}\n// Update when typing\nfunction handleInput(event: Event) {\n\tif (isInputLike(event.target)) {\n\t\trenderCounter(event.target);\n\t\trenderTextareaSize(event.target);\n\t\thandleDatalistPosition(event); // Reposition list datalist // TODO Enhance by using style.bottom?\n\t}\n}\n\nfunction handleValdiation(event: Event) {\n\tconst field = (event.target as Element)?.closest?.(`.${CSS_FIELD}`);\n\n\tif (event.type === \"invalid\" && field) event.preventDefault(); // Prevent browsers from showing default validation bubbles\n\thandleMutation(document.getElementsByClassName(CSS_FIELD), true); // Update state\n}\n\n// Position combobox when changing content\nfunction handleDatalistPosition({ target: el }: Event) {\n\tconst list =\n\t\t(el instanceof UHTMLComboboxElement || el instanceof HTMLInputElement) &&\n\t\tel.list;\n\tif (list && !list?.hidden) {\n\t\tconst position = attr(list, \"data-position\") ?? \"bottom\";\n\t\tsetTimeout(() => anchorPosition(list, el, position, true), 10); // Reposition list if not hidden\n\t}\n}\n\nonLoaded(() => {\n\tonMutation(document.documentElement, CSS_FIELD, handleMutation);\n\ton(document, \"comboboxbeforeselect\", handleDatalistPosition, QUICK_EVENT);\n\ton(document, \"input\", handleInput, QUICK_EVENT);\n\ton(document, \"invalid,submit\", handleValdiation, true); // Use capture as invalid and submit does not bubble\n\ton(document, \"toggle\", handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n});\n"],"names":["CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","getText","style","key","handleMutation","fields","validate","field","labels","descs","valids","combobox","input","valid","el","UHTMLComboboxElement","isInputLike","attr","desc","label","useId","renderCombobox","renderCounter","renderTextareaSize","textarea","control","list","limit","remainder","nextInvalid","prevInvalid","over","under","css","handleToggle","newState","UHTMLDataListElement","anchor","anchorPosition","handleInput","event","handleDatalistPosition","handleValdiation","position","onLoaded","onMutation","on","QUICK_EVENT"],"mappings":";;;;AAcA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAkBD,EAAO,WAAW,MAAM,GAAG,GAC7CE,IAAiBD,EAAgB,CAAC,GAElCE,IAAU,CAACC,GAA4BC,MAC5CD,EAAM,iBAAiB,eAAeC,CAAG,EAAE,GAAG,MAAM,GAAG,EAAE,KAAK;AAE/D,SAASC,EAAeC,GAAmCC,GAAoB;AAC9E,aAAWC,KAASF;AACnB,QAAIE,EAAM,aAAa;AACtB,YAAMC,IAA6B,CAAC,GAC9BC,IAAmB,CAAC,GACpBC,IAAoB,CAAC;AAC3B,UAAIC,IAAwC,MACxCC,IAAiC,MACjCC,IAAQ;AAEZ,iBAAWC,KAAMP,EAAM,qBAAqB,GAAG;AAC9C,QAAIO,aAAc,mBAAyBN,EAAA,KAAKM,CAAE,IACzCA,aAAcC,IAAiCJ,IAAAG,IAC/CE,EAAYF,CAAE,KAAK,CAACA,EAAG,SAAgBF,IAAAE,IACvCA,EAAG,aAAa,kBAAkB,IAAGL,EAAM,KAAKK,CAAE,IAClDA,EAAG,UAAU,SAASd,CAAc,KAC5Ca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-combobox';
2
2
  import { JSX } from 'react';
3
+ import { InputProps } from '../react';
3
4
  import { PolymorphicComponentPropWithRef } from '../react-types';
4
5
  import { AnchorPosition } from '../utils';
5
6
  type FieldBaseProps = {
@@ -34,18 +35,16 @@ export type FieldComboboxSelected = {
34
35
  export type FieldComboboxProps = ReactUcombobox & {
35
36
  "data-creatable"?: boolean;
36
37
  "data-multiple"?: boolean;
37
- "data-nofilter"?: boolean;
38
38
  onAfterChange?: (e: CustomEvent<HTMLDataElement>) => void;
39
- onBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void;
40
39
  onAfterSelect?: (e: CustomEvent<HTMLDataElement>) => void;
41
- onBeforeSelect?: (e: CustomEvent<HTMLDataElement>) => void;
40
+ onBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void;
42
41
  onBeforeMatch?: (e: CustomEvent<HTMLOptionElement>) => void;
42
+ onBeforeSelect?: (e: CustomEvent<HTMLDataElement>) => void;
43
43
  onSelectedChange?: (selected: FieldComboboxSelected) => void;
44
- disabled?: boolean;
45
44
  options?: FieldComboboxSelected;
46
- readOnly?: boolean;
47
45
  selected?: FieldComboboxSelected;
48
- };
46
+ } & Pick<InputProps, "disabled" | "readOnly" | "placeholder" | "type" | "name"> & // Allow input props to be passed down
47
+ Pick<FieldDatalistProps, "data-position" | "data-nofilter">;
49
48
  export declare const Field: FieldComponent & {
50
49
  Affixes: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
51
50
  Combobox: React.ForwardRefExoticComponent<Omit<FieldComboboxProps, "ref"> & React.RefAttributes<UHTMLComboboxElement>>;
@@ -1,6 +1,6 @@
1
- import { jsx as t, Fragment as R, jsxs as H } from "react/jsx-runtime";
2
- import { clsx as W } from "../external/clsx/dist/clsx.js";
3
- import { forwardRef as F, useRef as A, useImperativeHandle as q, useEffect as B } from "react";
1
+ import { jsx as t, Fragment as L, jsxs as j } from "react/jsx-runtime";
2
+ import { clsx as k } from "../external/clsx/dist/clsx.js";
3
+ import { forwardRef as g, useRef as I, useImperativeHandle as K, useEffect as M } from "react";
4
4
  import "../alert/alert.js";
5
5
  import "../app/app.js";
6
6
  import "../avatar/avatar.js";
@@ -14,8 +14,8 @@ import "../dialog/dialog.js";
14
14
  import "../divider/divider.js";
15
15
  import "../errorsummary/errorsummary.js";
16
16
  import "../fieldset/fieldset.js";
17
- import { HelpText as G } from "../helptext/helptext.js";
18
- import { Input as J } from "../input/input.js";
17
+ import { HelpText as Q } from "../helptext/helptext.js";
18
+ import { Input as U } from "../input/input.js";
19
19
  import "../layout/layout.js";
20
20
  import "../link/link.js";
21
21
  import "../logo/logo.js";
@@ -33,122 +33,150 @@ import "../typography/typography.js";
33
33
  import "../validation/validation.js";
34
34
  import v from "../styles.module.css.js";
35
35
  import { toCustomElementProps as N } from "../utils.js";
36
- const z = (n) => typeof n == "string" ? { label: n, value: n } : n, K = F(function({
36
+ const P = (i) => typeof i == "string" ? { label: i, value: i } : i, V = g(function({
37
37
  "data-size": e,
38
38
  as: o,
39
- className: l,
40
- count: d,
41
- description: p,
42
- error: g,
43
- helpText: C,
44
- helpTextLabel: y,
45
- label: O,
46
- prefix: f,
47
- style: j,
48
- suffix: u,
49
- validation: b,
50
- ...s
39
+ className: a,
40
+ count: m,
41
+ description: c,
42
+ error: F,
43
+ helpText: y,
44
+ helpTextLabel: C,
45
+ label: f,
46
+ prefix: u,
47
+ style: D,
48
+ suffix: b,
49
+ validation: H,
50
+ ...r
51
51
  }, h) {
52
- const m = o || "div", x = !!u || !!f, a = b || g, i = {
52
+ const p = o || "div", E = !!b || !!u, W = H || F, O = {
53
53
  "data-size": e,
54
- className: W(v.field, l),
55
- style: j
54
+ className: k(v.field, a),
55
+ style: D
56
56
  };
57
- return o === "select" && !s.children && Object.assign(s, {
58
- children: /* @__PURE__ */ t(R, { children: s.options?.map(z).map(({ label: r, value: c }) => /* @__PURE__ */ t("option", { value: c, children: r }, c)) })
59
- }), o ? /* @__PURE__ */ H("div", { ...i, children: [
60
- !!O && /* @__PURE__ */ t("label", { suppressHydrationWarning: !0, children: O }),
61
- !!C && /* @__PURE__ */ t(G, { "aria-label": y, children: C }),
62
- !!p && /* @__PURE__ */ t("p", { children: p }),
63
- x ? /* @__PURE__ */ H(I, { children: [
64
- !!f && /* @__PURE__ */ t("span", { children: f }),
65
- /* @__PURE__ */ t(m, { className: v.input, ref: h, ...s }),
66
- !!u && /* @__PURE__ */ t("span", { children: u })
57
+ return o === "select" && !r.children && Object.assign(r, {
58
+ children: /* @__PURE__ */ t(L, { children: r.options?.map(P).map(({ label: x, value: d }) => /* @__PURE__ */ t("option", { value: d, children: x }, d)) })
59
+ }), o ? /* @__PURE__ */ j("div", { ...O, children: [
60
+ !!f && /* @__PURE__ */ t("label", { suppressHydrationWarning: !0, children: f }),
61
+ !!y && /* @__PURE__ */ t(Q, { "aria-label": C, children: y }),
62
+ !!c && /* @__PURE__ */ t("p", { suppressHydrationWarning: !0, children: c }),
63
+ E ? /* @__PURE__ */ j(S, { children: [
64
+ !!u && /* @__PURE__ */ t("span", { children: u }),
65
+ /* @__PURE__ */ t(
66
+ p,
67
+ {
68
+ className: v.input,
69
+ suppressHydrationWarning: !0,
70
+ ref: h,
71
+ ...r
72
+ }
73
+ ),
74
+ !!b && /* @__PURE__ */ t("span", { children: b })
67
75
  ] }) : /* @__PURE__ */ t(
68
- m,
76
+ p,
69
77
  {
70
78
  className: typeof o == "string" ? v.input : void 0,
71
79
  suppressHydrationWarning: !0,
72
80
  ref: h,
73
- ...s
81
+ ...r
74
82
  }
75
83
  ),
76
- !!a && /* @__PURE__ */ t("div", { className: v.validation, children: a }),
77
- !!d && /* @__PURE__ */ t("p", { "data-count": d })
78
- ] }) : /* @__PURE__ */ t("div", { ref: h, ...i, ...s });
79
- }), I = F(
80
- function({ className: e, ...o }, l) {
81
- return /* @__PURE__ */ t("div", { className: W(v.affixes, e), ref: l, ...o });
84
+ !!W && /* @__PURE__ */ t("div", { suppressHydrationWarning: !0, className: v.validation, children: W }),
85
+ !!m && /* @__PURE__ */ t("p", { suppressHydrationWarning: !0, "data-count": m })
86
+ ] }) : /* @__PURE__ */ t("div", { ref: h, ...O, ...r });
87
+ }), S = g(
88
+ function({ className: e, ...o }, a) {
89
+ return /* @__PURE__ */ t("div", { className: k(v.affixes, e), ref: a, ...o });
82
90
  }
83
- ), L = F(
84
- function(e, o) {
85
- return /* @__PURE__ */ t("u-datalist", { ref: o, ...N(e) });
91
+ ), T = g(
92
+ function({ "data-nofilter": e, ...o }, a) {
93
+ return /* @__PURE__ */ t(
94
+ "u-datalist",
95
+ {
96
+ "data-nofilter": !!e || void 0,
97
+ ref: a,
98
+ ...N(o)
99
+ }
100
+ );
86
101
  }
87
- ), k = F(
102
+ ), q = g(
88
103
  function(e, o) {
89
104
  return /* @__PURE__ */ t("u-option", { ref: o, ...N(e) });
90
105
  }
91
- ), M = F(
106
+ ), X = g(
92
107
  function({
93
108
  "data-multiple": e,
94
109
  "data-nofilter": o,
95
- onAfterChange: l,
96
- onBeforeChange: d,
97
- onAfterSelect: p,
98
- onBeforeSelect: g,
99
- onBeforeMatch: C,
100
- onSelectedChange: y,
101
- children: O,
102
- disabled: f,
103
- options: j,
104
- readOnly: u,
105
- selected: b,
106
- ...s
107
- }, h) {
108
- const m = A(null), x = A(y);
109
- return x.current = y, l && (p = l, console.warn(
110
+ "data-position": a,
111
+ onAfterChange: m,
112
+ onAfterSelect: c,
113
+ onBeforeChange: F,
114
+ onBeforeMatch: y,
115
+ onBeforeSelect: C,
116
+ onSelectedChange: f,
117
+ children: u,
118
+ disabled: D,
119
+ name: b,
120
+ options: H,
121
+ placeholder: r,
122
+ readOnly: h,
123
+ selected: p,
124
+ type: E,
125
+ ...W
126
+ }, O) {
127
+ const x = I(null), d = I(f);
128
+ return d.current = f, m && (c = m, console.warn(
110
129
  "Combobox onAfterChange is deprecated, use onAfterSelect instead."
111
- )), d && (g = d, console.warn(
130
+ )), F && (C = F, console.warn(
112
131
  "Combobox onBeforeChange is deprecated, use onBeforeSelect instead."
113
- )), q(h, () => m.current), B(() => {
114
- const a = m.current, i = (r) => {
115
- const c = x.current;
116
- if (!x) return;
117
- r.preventDefault();
118
- const { isConnected: P, textContent: S, value: D } = r.detail, E = S?.trim() || "", w = b || [];
119
- c?.(P ? w.filter((T) => T.value !== D) : e ? [...w, { value: D, label: E }] : [{ value: D, label: E }]);
132
+ )), K(O, () => x.current), M(() => {
133
+ const l = x.current, s = (n) => {
134
+ const w = d.current;
135
+ if (!d) return;
136
+ n.preventDefault();
137
+ const { isConnected: B, textContent: G, value: A } = n.detail, R = G?.trim() || "", z = p || [];
138
+ w?.(B ? z.filter((J) => J.value !== A) : e ? [...z, { value: A, label: R }] : [{ value: A, label: R }]);
120
139
  };
121
- return a?.addEventListener("comboboxbeforeselect", i), () => a?.removeEventListener("comboboxbeforeselect", i);
122
- }, [e, b]), /* @__PURE__ */ H(
140
+ return l?.addEventListener("comboboxbeforeselect", s), () => l?.removeEventListener("comboboxbeforeselect", s);
141
+ }, [e, p]), /* @__PURE__ */ j(
123
142
  "u-combobox",
124
143
  {
144
+ "data-multiple": e || void 0,
125
145
  ...N({
126
- "data-multiple": e,
127
- oncomboboxbeforeselect: g,
128
- oncomboboxbeforematch: C,
129
- oncomboboxafterselect: p,
130
- ref: m,
131
- ...s
146
+ oncomboboxbeforeselect: C,
147
+ oncomboboxbeforematch: y,
148
+ oncomboboxafterselect: c,
149
+ ref: x,
150
+ ...W
132
151
  }),
133
152
  children: [
134
- b?.map(({ children: a, label: i, value: r }) => /* @__PURE__ */ t("data", { value: r, suppressHydrationWarning: !0, children: a ?? i }, r)),
135
- O || /* @__PURE__ */ H(R, { children: [
136
- /* @__PURE__ */ t(J, { disabled: f, readOnly: u }),
153
+ p?.map(({ children: l, label: s, value: n }) => /* @__PURE__ */ t("data", { value: n, suppressHydrationWarning: !0, children: l ?? s }, n)),
154
+ u || /* @__PURE__ */ j(L, { children: [
155
+ /* @__PURE__ */ t(
156
+ U,
157
+ {
158
+ name: b,
159
+ type: E,
160
+ disabled: D,
161
+ readOnly: h,
162
+ placeholder: r
163
+ }
164
+ ),
137
165
  /* @__PURE__ */ t("del", { ...N({ "aria-label": "Fjern tekst" }) })
138
166
  ] }),
139
- !!j && /* @__PURE__ */ t(L, { "data-nofilter": o || void 0, children: j.map(z).map(({ children: a, label: i, value: r }) => /* @__PURE__ */ t(k, { value: r, label: i, children: a ?? i }, r)) })
167
+ !!H && /* @__PURE__ */ t(T, { "data-nofilter": o, "data-position": a, children: H.map(P).map(({ children: l, label: s, value: n }) => /* @__PURE__ */ t(q, { value: n, label: s, children: l ?? s }, n)) })
140
168
  ]
141
169
  }
142
170
  );
143
171
  }
144
- ), Dt = Object.assign(K, {
145
- Affixes: I,
146
- Combobox: M,
147
- Datalist: L,
148
- Option: k
172
+ ), At = Object.assign(V, {
173
+ Affixes: S,
174
+ Combobox: X,
175
+ Datalist: T,
176
+ Option: q
149
177
  });
150
178
  export {
151
- Dt as Field,
152
- K as FieldComp
179
+ At as Field,
180
+ V as FieldComp
153
181
  };
154
182
  //# sourceMappingURL=field.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["import type {\n\tReactUcombobox,\n\tUHTMLComboboxElement,\n} from \"@u-elements/u-combobox\";\nimport clsx from \"clsx\";\nimport {\n\tforwardRef,\n\ttype JSX,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n} from \"react\";\nimport { HelpText, Input } from \"../react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport { type AnchorPosition, 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\tvalue?: React.ComponentPropsWithRef<\"input\">[\"value\"];\n\tonInput?: (\n\t\te: React.ChangeEvent<\n\t\t\tHTMLInputElement | HTMLSelectElement | HTMLTextAreaElement\n\t\t>,\n\t) => void;\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\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>{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 className={styles.input} ref={ref} {...rest} />\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 && <div className={styles.validation}>{valid}</div>}\n\t\t\t{!!count && <p 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\"?: AnchorPosition;\n};\n\nconst FieldDatalist = forwardRef<HTMLDataListElement, FieldDatalistProps>(\n\tfunction FieldDatalist(props, ref) {\n\t\treturn <u-datalist ref={ref} {...toCustomElementProps(props)} />;\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 = ReactUcombobox & {\n\t\"data-creatable\"?: boolean;\n\t\"data-multiple\"?: boolean;\n\t\"data-nofilter\"?: boolean;\n\tonAfterChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void; // deprecated\n\tonAfterSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonBeforeSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonBeforeMatch?: (e: CustomEvent<HTMLOptionElement>) => void; // Custom event to handle before change\n\tonSelectedChange?: (selected: FieldComboboxSelected) => void; // Allow onChange to be a function that returns void\n\tdisabled?: boolean; // Allow disabled prop to be passed down\n\toptions?: FieldComboboxSelected;\n\treadOnly?: boolean; // Allow disabled prop to be passed down\n\tselected?: FieldComboboxSelected; // Allow value to be a string or an array of strings for multiple select\n};\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\tonAfterChange,\n\t\t\tonBeforeChange,\n\t\t\tonAfterSelect,\n\t\t\tonBeforeSelect,\n\t\t\tonBeforeMatch,\n\t\t\tonSelectedChange,\n\t\t\tchildren,\n\t\t\tdisabled,\n\t\t\toptions,\n\t\t\treadOnly,\n\t\t\tselected,\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\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\t{...toCustomElementProps({\n\t\t\t\t\t\"data-multiple\": multiple,\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 disabled={disabled} readOnly={readOnly} />\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 || undefined}>\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 const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\tCombobox: FieldCombobox,\n\tDatalist: FieldDatalist,\n\tOption: FieldOption,\n});\n"],"names":["toOption","o","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","props","toCustomElementProps","FieldOption","FieldCombobox","multiple","nofilter","onAfterChange","onBeforeChange","onAfterSelect","onBeforeSelect","onBeforeMatch","onSelectedChange","children","disabled","options","readOnly","selected","innerRef","useRef","onSelected","useImperativeHandle","useEffect","self","handleChange","event","handleSelected","remove","textContent","prev","i","Fragment","Input","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAMA,IAAW,CAChBC,MAEA,OAAOA,KAAM,WAAW,EAAE,OAAOA,GAAG,OAAOA,EAAA,IAAMA,GAErCC,IAA4BC,EAAiB,SAGzD;AAAA,EACC,aAAaC;AAAA,EACb,IAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAA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AD,GAAc,0BAAwB,IACtD,UAAAkB,KAAY/B,EAAA,GADHa,CAEX,CACA;AAAA,UACAkB,KAEC,gBAAAhB,EAAAkC,GAAA,EAAA,UAAA;AAAA,YAAC,gBAAAnC,EAAAoC,GAAA,EAAM,UAAAlB,GAAoB,UAAAE,EAAoB,CAAA;AAAA,YAC/C,gBAAApB,EAAC,SAAK,GAAGM,EAAqB,EAAE,cAAc,cAAA,CAAe,EAAG,CAAA;AAAA,UAAA,GACjE;AAAA,UAEA,CAAC,CAACa,KACF,gBAAAnB,EAACI,GAAc,EAAA,iBAAeM,KAAY,QACxC,UAAQS,EAAA,IAAI7C,CAAQ,EAAE,IAAI,CAAC,EAAE,UAAA2C,GAAU,OAAA/B,GAAO,OAAAa,EAAM,MACnD,gBAAAC,EAAAO,GAAA,EAAwB,OAAAR,GAAc,OAAAb,GACrC,UAAA+B,KAAY/B,EADI,GAAAa,CAElB,CACA,EACF,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IAEF;AAAA,EAAA;AAGH,GAEasC,KAAQ,OAAO,OAAO7D,GAAW;AAAA,EAC7C,SAAS2B;AAAA,EACT,UAAUK;AAAA,EACV,UAAUJ;AAAA,EACV,QAAQG;AACT,CAAC;"}
1
+ {"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["import type {\n\tReactUcombobox,\n\tUHTMLComboboxElement,\n} from \"@u-elements/u-combobox\";\nimport clsx from \"clsx\";\nimport {\n\tforwardRef,\n\ttype JSX,\n\tuseEffect,\n\tuseImperativeHandle,\n\tuseRef,\n} from \"react\";\nimport { HelpText, Input, type InputProps } from \"../react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport { type AnchorPosition, 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\tvalue?: React.ComponentPropsWithRef<\"input\">[\"value\"];\n\tonInput?: (\n\t\te: React.ChangeEvent<\n\t\t\tHTMLInputElement | HTMLSelectElement | HTMLTextAreaElement\n\t\t>,\n\t) => void;\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\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\"?: AnchorPosition;\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 = ReactUcombobox & {\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\" | \"readOnly\" | \"placeholder\" | \"type\" | \"name\"\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 const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\tCombobox: FieldCombobox,\n\tDatalist: FieldDatalist,\n\tOption: FieldOption,\n});\n"],"names":["toOption","o","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAMA,IAAW,CAChBC,MAEA,OAAOA,KAAM,WAAW,EAAE,OAAOA,GAAG,OAAOA,EAAA,IAAMA,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,EACD;AAGI,SAAAT,MAAO,YAAY,CAACY,EAAK,YAC5B,OAAO,OAAOA,GAAM;AAAA,IACnB,iCAEI,UAAKA,EAAA,SACJ,IAAIjB,CAAQ,EACb,IAAI,CAAC,EAAE,OAAAY,GAAO,OAAAa,EAAA,MACb,gBAAAC,EA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