@mattilsynet/design 3.0.4 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ class m extends C {
24
24
  "style",
25
25
  null,
26
26
  `@layer leaflet{${f}}
27
- @layer mt.v3-0-4design{${b}`
27
+ @layer mt.v3-0-6design{${b}`
28
28
  ),
29
29
  r("figure")
30
30
  );
@@ -1,60 +1,62 @@
1
1
  import { DSFieldElement as p } from "@digdir/designsystemet-web";
2
- import l from "./styles.module.css.js";
3
- import { getByCSSModule as n, isBrowser as i, onHotReload as g, on as b, onMutation as y, QUICK_EVENT as S, debounce as E, attr as s } from "./utils.js";
2
+ import n from "./styles.module.css.js";
3
+ import { getByCSSModule as l, isBrowser as i, onHotReload as y, on as u, onMutation as S, QUICK_EVENT as E, attr as s, debounce as D } from "./utils.js";
4
4
  const f = /* @__PURE__ */ new WeakSet(), a = (t) => !f.has(t) && f.add(t), o = (t, e, r) => window.dsWarnings === !1 || console.warn(
5
5
  `\x1B[1m@mattilsynet/design:\x1B[m ${t} is deprecated, please use ${e}:`,
6
6
  r
7
- ), D = n("togglegroup"), u = l.button.split(" "), A = () => {
8
- for (const t of D) {
7
+ ), A = l("togglegroup"), g = n.button.split(" "), L = () => {
8
+ for (const t of A) {
9
9
  a(t) && !t.hasAttribute("data-toggle-group") && (s(t, "data-toggle-group", "Valgknapper"), o(
10
10
  'Only setting class="styles.togglegroup"',
11
11
  'data-toggle-group="LABEL-HERE" attribute also for better accessibility',
12
12
  t
13
13
  ));
14
14
  for (const e of t.getElementsByTagName("label"))
15
- a(e) && !e.classList.contains(u[0]) && (e.classList.add(...u), o(
15
+ a(e) && !e.classList.contains(g[0]) && (e.classList.add(...g), o(
16
16
  'Only setting class="styles.button"',
17
17
  '<label class="styles.button">',
18
18
  e
19
19
  ));
20
20
  }
21
- }, L = n("breadcrumbs"), O = () => {
22
- for (const t of L)
23
- a(t) && t.nodeName !== "DS-BREADCRUMBS" && (t.classList.add(...l.breadcrumbs.split(" ")), o(
21
+ }, O = l("breadcrumbs"), C = () => {
22
+ for (const t of O)
23
+ a(t) && t.nodeName !== "DS-BREADCRUMBS" && (t.classList.add(...n.breadcrumbs.split(" ")), o(
24
24
  'Only setting class="styles.breadcrumbs"',
25
25
  '<ds-breadcrumbs class="styles.breadcrumbs">',
26
26
  t
27
27
  ));
28
- }, C = n("errorsummary"), N = () => {
29
- for (const t of C)
28
+ }, N = l("errorsummary"), R = () => {
29
+ for (const t of N)
30
30
  a(t) && t.nodeName !== "DS-ERROR-SUMMARY" && o(
31
31
  'Only setting class="styles.errorsummary"',
32
32
  '<ds-error-summary class="styles.errorsummary">',
33
33
  t
34
34
  );
35
- }, R = n("dialog"), w = () => {
36
- for (const t of R)
37
- if (a(t) && (t.hasAttribute("data-variant") && o(
38
- '<dialog data-variant="drawer">',
39
- '<dialog data-placement="center|left|right|top|bottom">',
40
- t
41
- ), t.isConnected && t.showModal && t.close)) {
35
+ }, w = l("dialog"), b = () => {
36
+ for (const t of w) {
37
+ if (a(t)) {
42
38
  const e = s(t, "data-closedby");
43
39
  e && (s(t, "closedby", e), o(
44
40
  `<dialog data-closedby="${e}">`,
45
41
  `<dialog closedby="${e}">`,
46
42
  t
47
- )), t.matches('[open]:not([data-modal="false"]):not(:modal)') ? (o(
48
- '<dialog data-modal="true">',
49
- '.showModal() or <button command="show-modal" commandfor="DIALOG-ID"></button>',
43
+ )), t.hasAttribute("data-variant") && o(
44
+ '<dialog data-variant="drawer">',
45
+ '<dialog data-placement="center|left|right|top|bottom">',
50
46
  t
51
- ), s(t, "open", null), t.showModal()) : t.matches(":modal:not([open])") && (s(t, "open", ""), t.close());
47
+ );
52
48
  }
49
+ t.isConnected && t.showModal && t.close && (t.matches('[open][data-modal]:not([data-modal="false"]):not(:modal)') ? (o(
50
+ '<dialog data-modal="true">',
51
+ '.showModal() or <button command="show-modal" commandfor="DIALOG-ID"></button>',
52
+ t
53
+ ), s(t, "open", null), t.showModal()) : t.matches(":modal:not([open])") && (s(t, "open", ""), t.close()));
54
+ }
53
55
  }, B = () => {
54
56
  for (const t of document.querySelectorAll("[data-count]"))
55
57
  if (a(t)) {
56
58
  const e = s(t, "data-count");
57
- t.classList.add(...l.validation.split(" ")), s(t, "data-limit", e), o(
59
+ t.classList.add(...n.validation.split(" ")), s(t, "data-limit", e), o(
58
60
  `data-count="${e}"`,
59
61
  `class="styles.validation" data-field="counter" data-limit="${e}"`,
60
62
  t
@@ -76,7 +78,7 @@ const f = /* @__PURE__ */ new WeakSet(), a = (t) => !f.has(t) && f.add(t), o = (
76
78
  }
77
79
  }, h = i() ? document.getElementsByTagName("u-tabs") : [], I = () => {
78
80
  for (const t of h) a(t) && o("u-tabs", "ds-tabs", t);
79
- }, d = l.suggestion.split(" "), v = i() ? document.getElementsByTagName("u-combobox") : [], $ = i() ? document.getElementsByTagName("ds-suggestion") : [], M = () => {
81
+ }, d = n.suggestion.split(" "), v = i() ? document.getElementsByTagName("u-combobox") : [], $ = i() ? document.getElementsByTagName("ds-suggestion") : [], M = () => {
80
82
  for (const t of v)
81
83
  a(t) && (t.classList.add(...d), o("<u-combobox>", '<ds-suggestion class="styles.suggestion">', t));
82
84
  for (const t of $)
@@ -91,7 +93,7 @@ const f = /* @__PURE__ */ new WeakSet(), a = (t) => !f.has(t) && f.add(t), o = (
91
93
  e && !t?.closest('a,button,label,input,select,textarea,[role="button"]') && e.click();
92
94
  const m = t?.closest("dialog");
93
95
  m && t?.closest('[data-command="close"]') && m.close();
94
- }, k = n("field"), c = /* @__PURE__ */ new Set(), F = () => {
96
+ }, k = l("field"), c = /* @__PURE__ */ new Set(), F = () => {
95
97
  for (const t of k)
96
98
  t.nodeName !== "DS-FIELD" && (a(t) || o(
97
99
  'Only setting class="styles.field"',
@@ -101,14 +103,14 @@ const f = /* @__PURE__ */ new WeakSet(), a = (t) => !f.has(t) && f.add(t), o = (
101
103
  }, G = () => {
102
104
  for (const t of c)
103
105
  p.prototype.disconnectedCallback.call(t), c.delete(t);
104
- }, x = `[data-description], .${l.field.split(" ")[0]} label + p`, q = () => {
106
+ }, x = `[data-description], .${n.field.split(" ")[0]} label + p`, q = () => {
105
107
  for (const t of document.querySelectorAll(x))
106
108
  a(t) && t.getAttribute("data-field") !== "description" && (s(t, "data-field", "description"), o(
107
109
  "Descriptions created by data-description of <p> only",
108
110
  'data-field="data-description"',
109
111
  t
110
112
  ));
111
- }, P = n("validation"), _ = () => {
113
+ }, P = l("validation"), _ = () => {
112
114
  for (const t of P)
113
115
  a(t) && !t.hasAttribute("data-field") && (s(t, "data-field", "validation"), o(
114
116
  'Only setting class="styles.validation"',
@@ -118,14 +120,15 @@ const f = /* @__PURE__ */ new WeakSet(), a = (t) => !f.has(t) && f.add(t), o = (
118
120
  }, V = () => {
119
121
  for (const t of document.querySelectorAll("[popover][data-position]"))
120
122
  a(t) && (s(t, "data-placement", s(t, "data-position")), o("data-position", "data-placement", t));
121
- }, W = E(() => {
122
- B(), T(), O(), w(), N(), q(), _(), V(), F(), A(), M(), I();
123
+ }, W = D(() => {
124
+ B(), T(), C(), b(), R(), q(), _(), V(), F(), L(), M(), I();
123
125
  }, 200);
124
- g("deprecations", () => [
126
+ y("deprecations", () => [
125
127
  G,
126
128
  // Return as cleanup function
127
- b(document, "click", U, S),
128
- y(document, W, {
129
+ u(document, "click", U, E),
130
+ u(document, "toggle", b, !0),
131
+ S(document, W, {
129
132
  attributeFilter: [
130
133
  "class",
131
134
  "data-command",
@@ -1 +1 @@
1
- {"version":3,"file":"deprecations.js","sources":["../designsystem/deprecations.ts"],"sourcesContent":["import { DSFieldElement } from \"@digdir/designsystemet-web\";\nimport styles from \"./styles.module.css\";\nimport {\n\tattr,\n\tdebounce,\n\tgetByCSSModule,\n\tisBrowser,\n\ton,\n\tonHotReload,\n\tonMutation,\n\tQUICK_EVENT,\n} from \"./utils\";\n\nconst DEPRECATIONS = new WeakSet<Element>();\nconst deprecate = (el: Element) =>\n\t!DEPRECATIONS.has(el) && DEPRECATIONS.add(el);\n\nconst warn = (from: string, to: string, el: Element) =>\n\twindow.dsWarnings === false ||\n\tconsole.warn(\n\t\t`\\x1B[1m@mattilsynet/design:\\x1B[m ${from} is deprecated, please use ${to}:`,\n\t\tel,\n\t);\n\n// Deprecate togglegroup without data-toggle-group attribute\nconst TOGGLEGROUPS = getByCSSModule(\"togglegroup\");\nconst CSS_BUTTON = styles.button.split(\" \");\nconst deprecateToggleGroup = () => {\n\tfor (const el of TOGGLEGROUPS) {\n\t\tif (deprecate(el) && !el.hasAttribute(\"data-toggle-group\")) {\n\t\t\tattr(el, \"data-toggle-group\", \"Valgknapper\");\n\t\t\twarn(\n\t\t\t\t'Only setting class=\"styles.togglegroup\"',\n\t\t\t\t'data-toggle-group=\"LABEL-HERE\" attribute also for better accessibility',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n\t\tfor (const label of el.getElementsByTagName(\"label\")) {\n\t\t\tif (deprecate(label) && !label.classList.contains(CSS_BUTTON[0])) {\n\t\t\t\tlabel.classList.add(...CSS_BUTTON);\n\t\t\t\twarn(\n\t\t\t\t\t'Only setting class=\"styles.button\"',\n\t\t\t\t\t`<label class=\"styles.button\">`,\n\t\t\t\t\tlabel,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n};\n\n// Deprecate errorsummary without ds-error-summary element\nconst BREADCRUMBS = getByCSSModule(\"breadcrumbs\");\nconst deprecateBreadcrumbs = () => {\n\tfor (const el of BREADCRUMBS)\n\t\tif (deprecate(el) && el.nodeName !== \"DS-BREADCRUMBS\") {\n\t\t\tel.classList.add(...styles.breadcrumbs.split(\" \"));\n\t\t\twarn(\n\t\t\t\t'Only setting class=\"styles.breadcrumbs\"',\n\t\t\t\t'<ds-breadcrumbs class=\"styles.breadcrumbs\">',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\n// Deprecate errorsummary without ds-error-summary element\nconst ERRORSUMMARYS = getByCSSModule(\"errorsummary\");\nconst deprecateErrorSummary = () => {\n\tfor (const el of ERRORSUMMARYS)\n\t\tif (deprecate(el) && el.nodeName !== \"DS-ERROR-SUMMARY\") {\n\t\t\twarn(\n\t\t\t\t'Only setting class=\"styles.errorsummary\"',\n\t\t\t\t'<ds-error-summary class=\"styles.errorsummary\">',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\n// Deprecate data-variant and data-modal and data-closedby on dialogs\nconst DIALOGS = getByCSSModule(\"dialog\") as HTMLCollectionOf<HTMLDialogElement>;\nconst deprecateDialog = () => {\n\tfor (const el of DIALOGS) {\n\t\tif (!deprecate(el)) continue;\n\t\tif (el.hasAttribute(\"data-variant\")) {\n\t\t\twarn(\n\t\t\t\t'<dialog data-variant=\"drawer\">',\n\t\t\t\t'<dialog data-placement=\"center|left|right|top|bottom\">',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n\t\tif (el.isConnected && el.showModal && el.close) {\n\t\t\tconst closedby = attr(el, \"data-closedby\");\n\t\t\tif (closedby) {\n\t\t\t\tattr(el, \"closedby\", closedby);\n\t\t\t\twarn(\n\t\t\t\t\t`<dialog data-closedby=\"${closedby}\">`,\n\t\t\t\t\t`<dialog closedby=\"${closedby}\">`,\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (el.matches('[open]:not([data-modal=\"false\"]):not(:modal)')) {\n\t\t\t\twarn(\n\t\t\t\t\t'<dialog data-modal=\"true\">',\n\t\t\t\t\t'.showModal() or <button command=\"show-modal\" commandfor=\"DIALOG-ID\"></button>',\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t\t\tattr(el, \"open\", null); // Using attribute instead of .close to avoid `close` event\n\t\t\t\tel.showModal();\n\t\t\t} else if (el.matches(\":modal:not([open])\")) {\n\t\t\t\tattr(el, \"open\", \"\"); // Set as open\n\t\t\t\tel.close(); // So we correctly can call .close, removing <dialog> from #top-layer\n\t\t\t}\n\t\t}\n\t}\n};\n\n// Deprecate data-count in favor of data-limit\nconst deprecateCounter = () => {\n\tfor (const el of document.querySelectorAll(\"[data-count]\"))\n\t\tif (deprecate(el)) {\n\t\t\tconst count = attr(el, \"data-count\");\n\t\t\tel.classList.add(...styles.validation.split(\" \"));\n\t\t\tattr(el, \"data-limit\", count);\n\t\t\twarn(\n\t\t\t\t`data-count=\"${count}\"`,\n\t\t\t\t`class=\"styles.validation\" data-field=\"counter\" data-limit=\"${count}\"`,\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\n// Deprecate data-command on buttons and other elements\nconst deprecateDataCommand = () => {\n\tfor (const el of document.querySelectorAll(\"[data-command]\"))\n\t\tif (deprecate(el)) {\n\t\t\tconst command = attr(el, \"data-command\");\n\n\t\t\tif (command === \"row\")\n\t\t\t\twarn(\n\t\t\t\t\t`<${el.nodeName.toLowerCase()} data-command=\"${command}\">`,\n\t\t\t\t\t`<tr data-clickdelegatefor=\"${el.nodeName}-ID\">`,\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t\telse\n\t\t\t\twarn(\n\t\t\t\t\t`<button data-command=\"${command}\">`,\n\t\t\t\t\t`<button command=\"${command?.replace(\"toggle-app-expanded\", \"show-modal\")}\" commandfor=\"TARGET-ID\">`,\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t}\n};\n\n// Deprecate u-tabs\nconst TABS = isBrowser() ? document.getElementsByTagName(\"u-tabs\") : [];\nconst deprecateUTabs = () => {\n\tfor (const el of TABS) if (deprecate(el)) warn(\"u-tabs\", \"ds-tabs\", el);\n};\n\n// Deprecate u-combobox and add class to ds-suggestion\nconst CSS_SUGGESTION = styles.suggestion.split(\" \");\nconst OLD = isBrowser() ? document.getElementsByTagName(\"u-combobox\") : [];\nconst NEW = isBrowser() ? document.getElementsByTagName(\"ds-suggestion\") : [];\nconst deprecateUCombobox = () => {\n\tfor (const el of OLD)\n\t\tif (deprecate(el)) {\n\t\t\tel.classList.add(...CSS_SUGGESTION);\n\t\t\twarn(\"<u-combobox>\", `<ds-suggestion class=\"styles.suggestion\">`, el);\n\t\t}\n\tfor (const el of NEW)\n\t\tif (deprecate(el) && !el.classList.contains(CSS_SUGGESTION[0])) {\n\t\t\tel.classList.add(...CSS_SUGGESTION);\n\t\t\twarn(\n\t\t\t\t\"Only using <ds-suggestion>\",\n\t\t\t\t`<ds-suggestion class=\"styles.suggestion\">`,\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\nconst handleCommandClick = ({ target: el }: Event) => {\n\tif (el instanceof Element === false) return;\n\tconst row = el?.closest(\"tr\")?.querySelector('[data-command=\"row\"]');\n\tconst click =\n\t\trow && !el?.closest('a,button,label,input,select,textarea,[role=\"button\"]');\n\tif (click) (row as HTMLElement).click(); // Forward click to data-command=\"row\" element\n\n\tconst dialog = el?.closest(\"dialog\");\n\tconst close = dialog && el?.closest('[data-command=\"close\"]');\n\tif (close) dialog.close();\n};\n\n// Deprecate fields without ds-field element\nconst FIELDS = getByCSSModule(\"field\");\nconst FIELD_UNBIND = new Set<Element>();\nconst deprecateField = () => {\n\tfor (const el of FIELDS)\n\t\tif (el.nodeName !== \"DS-FIELD\") {\n\t\t\tif (!deprecate(el))\n\t\t\t\twarn(\n\t\t\t\t\t'Only setting class=\"styles.field\"',\n\t\t\t\t\t'<ds-field class=\"styles.field\">',\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t\tif (!FIELD_UNBIND.has(el) && FIELD_UNBIND.add(el)) {\n\t\t\t\tDSFieldElement.prototype.connectedCallback.call(el as DSFieldElement);\n\t\t\t}\n\t\t}\n};\nconst unbindFields = () => {\n\tfor (const el of FIELD_UNBIND) {\n\t\tDSFieldElement.prototype.disconnectedCallback.call(el as DSFieldElement);\n\t\tFIELD_UNBIND.delete(el);\n\t}\n};\n\n// Deprecate validation without data-field=\"validation\"\nconst CSS_DESCRIPTIONS = `[data-description], .${styles.field.split(\" \")[0]} label + p`;\nconst deprecateFeildDescription = () => {\n\tfor (const el of document.querySelectorAll(CSS_DESCRIPTIONS))\n\t\tif (deprecate(el) && el.getAttribute(\"data-field\") !== \"description\") {\n\t\t\tattr(el, \"data-field\", \"description\");\n\t\t\twarn(\n\t\t\t\t\"Descriptions created by data-description of <p> only\",\n\t\t\t\t'data-field=\"data-description\"',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\n// Deprecate validation without data-field=\"validation\"\nconst VALIDATIONS = getByCSSModule(\"validation\");\nconst deprecateFieldValidation = () => {\n\tfor (const el of VALIDATIONS)\n\t\tif (deprecate(el) && !el.hasAttribute(\"data-field\")) {\n\t\t\tattr(el, \"data-field\", \"validation\");\n\t\t\twarn(\n\t\t\t\t'Only setting class=\"styles.validation\"',\n\t\t\t\t'class=\"styles.validation\" data-field=\"validation\"',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\nconst deprecatePopoverPosition = () => {\n\tfor (const el of document.querySelectorAll(\"[popover][data-position]\"))\n\t\tif (deprecate(el)) {\n\t\t\tattr(el, \"data-placement\", attr(el, \"data-position\"));\n\t\t\twarn(\"data-position\", \"data-placement\", el);\n\t\t}\n};\n\nconst handleDeprecations = debounce(() => {\n\tdeprecateCounter();\n\tdeprecateDataCommand();\n\tdeprecateBreadcrumbs();\n\tdeprecateDialog();\n\tdeprecateErrorSummary();\n\tdeprecateFeildDescription();\n\tdeprecateFieldValidation();\n\tdeprecatePopoverPosition();\n\tdeprecateField(); // Should run after other field deprecations to access correct data-attributes\n\tdeprecateToggleGroup();\n\tdeprecateUCombobox();\n\tdeprecateUTabs();\n}, 200);\n\nonHotReload(\"deprecations\", () => [\n\tunbindFields, // Return as cleanup function\n\ton(document, \"click\", handleCommandClick, QUICK_EVENT),\n\tonMutation(document, handleDeprecations, {\n\t\tattributeFilter: [\n\t\t\t\"class\",\n\t\t\t\"data-command\",\n\t\t\t\"data-count\",\n\t\t\t\"data-description\",\n\t\t\t\"data-variant\",\n\t\t\t\"open\",\n\t\t],\n\t\tattributes: true,\n\t\tchildList: true,\n\t\tsubtree: true,\n\t}),\n]);\n"],"names":["DEPRECATIONS","deprecate","el","warn","from","to","TOGGLEGROUPS","getByCSSModule","CSS_BUTTON","styles","deprecateToggleGroup","attr","label","BREADCRUMBS","deprecateBreadcrumbs","ERRORSUMMARYS","deprecateErrorSummary","DIALOGS","deprecateDialog","closedby","deprecateCounter","count","deprecateDataCommand","command","TABS","isBrowser","deprecateUTabs","CSS_SUGGESTION","OLD","NEW","deprecateUCombobox","handleCommandClick","row","dialog","FIELDS","FIELD_UNBIND","deprecateField","DSFieldElement","unbindFields","CSS_DESCRIPTIONS","deprecateFeildDescription","VALIDATIONS","deprecateFieldValidation","deprecatePopoverPosition","handleDeprecations","debounce","onHotReload","on","QUICK_EVENT","onMutation"],"mappings":";;;AAaA,MAAMA,wBAAmB,QAAA,GACnBC,IAAY,CAACC,MAClB,CAACF,EAAa,IAAIE,CAAE,KAAKF,EAAa,IAAIE,CAAE,GAEvCC,IAAO,CAACC,GAAcC,GAAYH,MACvC,OAAO,eAAe,MACtB,QAAQ;AAAA,EACP,qCAAqCE,CAAI,8BAA8BC,CAAE;AAAA,EACzEH;AACD,GAGKI,IAAeC,EAAe,aAAa,GAC3CC,IAAaC,EAAO,OAAO,MAAM,GAAG,GACpCC,IAAuB,MAAM;AAClC,aAAWR,KAAMI,GAAc;AAC9B,IAAIL,EAAUC,CAAE,KAAK,CAACA,EAAG,aAAa,mBAAmB,MACxDS,EAAKT,GAAI,qBAAqB,aAAa,GAC3CC;AAAA,MACC;AAAA,MACA;AAAA,MACAD;AAAA,IAAA;AAGF,eAAWU,KAASV,EAAG,qBAAqB,OAAO;AAClD,MAAID,EAAUW,CAAK,KAAK,CAACA,EAAM,UAAU,SAASJ,EAAW,CAAC,CAAC,MAC9DI,EAAM,UAAU,IAAI,GAAGJ,CAAU,GACjCL;AAAA,QACC;AAAA,QACA;AAAA,QACAS;AAAA,MAAA;AAAA,EAIJ;AACD,GAGMC,IAAcN,EAAe,aAAa,GAC1CO,IAAuB,MAAM;AAClC,aAAWZ,KAAMW;AAChB,IAAIZ,EAAUC,CAAE,KAAK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AM;AACtC,aAAWzC,KAAM,SAAS,iBAAiB,0BAA0B;AACpE,IAAID,EAAUC,CAAE,MACfS,EAAKT,GAAI,kBAAkBS,EAAKT,GAAI,eAAe,CAAC,GACpDC,EAAK,iBAAiB,kBAAkBD,CAAE;AAE7C,GAEM0C,IAAqBC,EAAS,MAAM;AACzC,EAAAzB,EAAA,GACAE,EAAA,GACAR,EAAA,GACAI,EAAA,GACAF,EAAA,GACAwB,EAAA,GACAE,EAAA,GACAC,EAAA,GACAP,EAAA,GACA1B,EAAA,GACAoB,EAAA,GACAJ,EAAA;AACD,GAAG,GAAG;AAENoB,EAAY,gBAAgB,MAAM;AAAA,EACjCR;AAAA;AAAA,EACAS,EAAG,UAAU,SAAShB,GAAoBiB,CAAW;AAAA,EACrDC,EAAW,UAAUL,GAAoB;AAAA,IACxC,iBAAiB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,IAED,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,SAAS;AAAA,EAAA,CACT;AACF,CAAC;"}
1
+ {"version":3,"file":"deprecations.js","sources":["../designsystem/deprecations.ts"],"sourcesContent":["import { DSFieldElement } from \"@digdir/designsystemet-web\";\nimport styles from \"./styles.module.css\";\nimport {\n\tattr,\n\tdebounce,\n\tgetByCSSModule,\n\tisBrowser,\n\ton,\n\tonHotReload,\n\tonMutation,\n\tQUICK_EVENT,\n} from \"./utils\";\n\nconst DEPRECATIONS = new WeakSet<Element>();\nconst deprecate = (el: Element) =>\n\t!DEPRECATIONS.has(el) && DEPRECATIONS.add(el);\n\nconst warn = (from: string, to: string, el: Element) =>\n\twindow.dsWarnings === false ||\n\tconsole.warn(\n\t\t`\\x1B[1m@mattilsynet/design:\\x1B[m ${from} is deprecated, please use ${to}:`,\n\t\tel,\n\t);\n\n// Deprecate togglegroup without data-toggle-group attribute\nconst TOGGLEGROUPS = getByCSSModule(\"togglegroup\");\nconst CSS_BUTTON = styles.button.split(\" \");\nconst deprecateToggleGroup = () => {\n\tfor (const el of TOGGLEGROUPS) {\n\t\tif (deprecate(el) && !el.hasAttribute(\"data-toggle-group\")) {\n\t\t\tattr(el, \"data-toggle-group\", \"Valgknapper\");\n\t\t\twarn(\n\t\t\t\t'Only setting class=\"styles.togglegroup\"',\n\t\t\t\t'data-toggle-group=\"LABEL-HERE\" attribute also for better accessibility',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n\t\tfor (const label of el.getElementsByTagName(\"label\")) {\n\t\t\tif (deprecate(label) && !label.classList.contains(CSS_BUTTON[0])) {\n\t\t\t\tlabel.classList.add(...CSS_BUTTON);\n\t\t\t\twarn(\n\t\t\t\t\t'Only setting class=\"styles.button\"',\n\t\t\t\t\t`<label class=\"styles.button\">`,\n\t\t\t\t\tlabel,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n};\n\n// Deprecate errorsummary without ds-error-summary element\nconst BREADCRUMBS = getByCSSModule(\"breadcrumbs\");\nconst deprecateBreadcrumbs = () => {\n\tfor (const el of BREADCRUMBS)\n\t\tif (deprecate(el) && el.nodeName !== \"DS-BREADCRUMBS\") {\n\t\t\tel.classList.add(...styles.breadcrumbs.split(\" \"));\n\t\t\twarn(\n\t\t\t\t'Only setting class=\"styles.breadcrumbs\"',\n\t\t\t\t'<ds-breadcrumbs class=\"styles.breadcrumbs\">',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\n// Deprecate errorsummary without ds-error-summary element\nconst ERRORSUMMARYS = getByCSSModule(\"errorsummary\");\nconst deprecateErrorSummary = () => {\n\tfor (const el of ERRORSUMMARYS)\n\t\tif (deprecate(el) && el.nodeName !== \"DS-ERROR-SUMMARY\") {\n\t\t\twarn(\n\t\t\t\t'Only setting class=\"styles.errorsummary\"',\n\t\t\t\t'<ds-error-summary class=\"styles.errorsummary\">',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\n// Deprecate data-variant and data-modal and data-closedby on dialogs\nconst DIALOGS = getByCSSModule(\"dialog\") as HTMLCollectionOf<HTMLDialogElement>;\nconst deprecateDialog = () => {\n\tfor (const el of DIALOGS) {\n\t\tif (deprecate(el)) {\n\t\t\tconst closedby = attr(el, \"data-closedby\");\n\t\t\tif (closedby) {\n\t\t\t\tattr(el, \"closedby\", closedby);\n\t\t\t\twarn(\n\t\t\t\t\t`<dialog data-closedby=\"${closedby}\">`,\n\t\t\t\t\t`<dialog closedby=\"${closedby}\">`,\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (el.hasAttribute(\"data-variant\")) {\n\t\t\t\twarn(\n\t\t\t\t\t'<dialog data-variant=\"drawer\">',\n\t\t\t\t\t'<dialog data-placement=\"center|left|right|top|bottom\">',\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (el.isConnected && el.showModal && el.close) {\n\t\t\tif (\n\t\t\t\tel.matches('[open][data-modal]:not([data-modal=\"false\"]):not(:modal)')\n\t\t\t) {\n\t\t\t\twarn(\n\t\t\t\t\t'<dialog data-modal=\"true\">',\n\t\t\t\t\t'.showModal() or <button command=\"show-modal\" commandfor=\"DIALOG-ID\"></button>',\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t\t\tattr(el, \"open\", null); // Using attribute instead of .close to avoid `close` event\n\t\t\t\tel.showModal();\n\t\t\t} else if (el.matches(\":modal:not([open])\")) {\n\t\t\t\tattr(el, \"open\", \"\"); // Set as open\n\t\t\t\tel.close(); // So we correctly can call .close, removing <dialog> from #top-layer\n\t\t\t}\n\t\t}\n\t}\n};\n\n// Deprecate data-count in favor of data-limit\nconst deprecateCounter = () => {\n\tfor (const el of document.querySelectorAll(\"[data-count]\"))\n\t\tif (deprecate(el)) {\n\t\t\tconst count = attr(el, \"data-count\");\n\t\t\tel.classList.add(...styles.validation.split(\" \"));\n\t\t\tattr(el, \"data-limit\", count);\n\t\t\twarn(\n\t\t\t\t`data-count=\"${count}\"`,\n\t\t\t\t`class=\"styles.validation\" data-field=\"counter\" data-limit=\"${count}\"`,\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\n// Deprecate data-command on buttons and other elements\nconst deprecateDataCommand = () => {\n\tfor (const el of document.querySelectorAll(\"[data-command]\"))\n\t\tif (deprecate(el)) {\n\t\t\tconst command = attr(el, \"data-command\");\n\n\t\t\tif (command === \"row\")\n\t\t\t\twarn(\n\t\t\t\t\t`<${el.nodeName.toLowerCase()} data-command=\"${command}\">`,\n\t\t\t\t\t`<tr data-clickdelegatefor=\"${el.nodeName}-ID\">`,\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t\telse\n\t\t\t\twarn(\n\t\t\t\t\t`<button data-command=\"${command}\">`,\n\t\t\t\t\t`<button command=\"${command?.replace(\"toggle-app-expanded\", \"show-modal\")}\" commandfor=\"TARGET-ID\">`,\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t}\n};\n\n// Deprecate u-tabs\nconst TABS = isBrowser() ? document.getElementsByTagName(\"u-tabs\") : [];\nconst deprecateUTabs = () => {\n\tfor (const el of TABS) if (deprecate(el)) warn(\"u-tabs\", \"ds-tabs\", el);\n};\n\n// Deprecate u-combobox and add class to ds-suggestion\nconst CSS_SUGGESTION = styles.suggestion.split(\" \");\nconst OLD = isBrowser() ? document.getElementsByTagName(\"u-combobox\") : [];\nconst NEW = isBrowser() ? document.getElementsByTagName(\"ds-suggestion\") : [];\nconst deprecateUCombobox = () => {\n\tfor (const el of OLD)\n\t\tif (deprecate(el)) {\n\t\t\tel.classList.add(...CSS_SUGGESTION);\n\t\t\twarn(\"<u-combobox>\", `<ds-suggestion class=\"styles.suggestion\">`, el);\n\t\t}\n\tfor (const el of NEW)\n\t\tif (deprecate(el) && !el.classList.contains(CSS_SUGGESTION[0])) {\n\t\t\tel.classList.add(...CSS_SUGGESTION);\n\t\t\twarn(\n\t\t\t\t\"Only using <ds-suggestion>\",\n\t\t\t\t`<ds-suggestion class=\"styles.suggestion\">`,\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\nconst handleCommandClick = ({ target: el }: Event) => {\n\tif (el instanceof Element === false) return;\n\tconst row = el?.closest(\"tr\")?.querySelector('[data-command=\"row\"]');\n\tconst click =\n\t\trow && !el?.closest('a,button,label,input,select,textarea,[role=\"button\"]');\n\tif (click) (row as HTMLElement).click(); // Forward click to data-command=\"row\" element\n\n\tconst dialog = el?.closest(\"dialog\");\n\tconst close = dialog && el?.closest('[data-command=\"close\"]');\n\tif (close) dialog.close();\n};\n\n// Deprecate fields without ds-field element\nconst FIELDS = getByCSSModule(\"field\");\nconst FIELD_UNBIND = new Set<Element>();\nconst deprecateField = () => {\n\tfor (const el of FIELDS)\n\t\tif (el.nodeName !== \"DS-FIELD\") {\n\t\t\tif (!deprecate(el))\n\t\t\t\twarn(\n\t\t\t\t\t'Only setting class=\"styles.field\"',\n\t\t\t\t\t'<ds-field class=\"styles.field\">',\n\t\t\t\t\tel,\n\t\t\t\t);\n\t\t\tif (!FIELD_UNBIND.has(el) && FIELD_UNBIND.add(el)) {\n\t\t\t\tDSFieldElement.prototype.connectedCallback.call(el as DSFieldElement);\n\t\t\t}\n\t\t}\n};\nconst unbindFields = () => {\n\tfor (const el of FIELD_UNBIND) {\n\t\tDSFieldElement.prototype.disconnectedCallback.call(el as DSFieldElement);\n\t\tFIELD_UNBIND.delete(el);\n\t}\n};\n\n// Deprecate validation without data-field=\"validation\"\nconst CSS_DESCRIPTIONS = `[data-description], .${styles.field.split(\" \")[0]} label + p`;\nconst deprecateFeildDescription = () => {\n\tfor (const el of document.querySelectorAll(CSS_DESCRIPTIONS))\n\t\tif (deprecate(el) && el.getAttribute(\"data-field\") !== \"description\") {\n\t\t\tattr(el, \"data-field\", \"description\");\n\t\t\twarn(\n\t\t\t\t\"Descriptions created by data-description of <p> only\",\n\t\t\t\t'data-field=\"data-description\"',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\n// Deprecate validation without data-field=\"validation\"\nconst VALIDATIONS = getByCSSModule(\"validation\");\nconst deprecateFieldValidation = () => {\n\tfor (const el of VALIDATIONS)\n\t\tif (deprecate(el) && !el.hasAttribute(\"data-field\")) {\n\t\t\tattr(el, \"data-field\", \"validation\");\n\t\t\twarn(\n\t\t\t\t'Only setting class=\"styles.validation\"',\n\t\t\t\t'class=\"styles.validation\" data-field=\"validation\"',\n\t\t\t\tel,\n\t\t\t);\n\t\t}\n};\n\nconst deprecatePopoverPosition = () => {\n\tfor (const el of document.querySelectorAll(\"[popover][data-position]\"))\n\t\tif (deprecate(el)) {\n\t\t\tattr(el, \"data-placement\", attr(el, \"data-position\"));\n\t\t\twarn(\"data-position\", \"data-placement\", el);\n\t\t}\n};\n\nconst handleDeprecations = debounce(() => {\n\tdeprecateCounter();\n\tdeprecateDataCommand();\n\tdeprecateBreadcrumbs();\n\tdeprecateDialog();\n\tdeprecateErrorSummary();\n\tdeprecateFeildDescription();\n\tdeprecateFieldValidation();\n\tdeprecatePopoverPosition();\n\tdeprecateField(); // Should run after other field deprecations to access correct data-attributes\n\tdeprecateToggleGroup();\n\tdeprecateUCombobox();\n\tdeprecateUTabs();\n}, 200);\n\nonHotReload(\"deprecations\", () => [\n\tunbindFields, // Return as cleanup function\n\ton(document, \"click\", handleCommandClick, QUICK_EVENT),\n\ton(document, \"toggle\", deprecateDialog, true),\n\tonMutation(document, handleDeprecations, {\n\t\tattributeFilter: [\n\t\t\t\"class\",\n\t\t\t\"data-command\",\n\t\t\t\"data-count\",\n\t\t\t\"data-description\",\n\t\t\t\"data-variant\",\n\t\t\t\"open\",\n\t\t],\n\t\tattributes: true,\n\t\tchildList: true,\n\t\tsubtree: true,\n\t}),\n]);\n"],"names":["DEPRECATIONS","deprecate","el","warn","from","to","TOGGLEGROUPS","getByCSSModule","CSS_BUTTON","styles","deprecateToggleGroup","attr","label","BREADCRUMBS","deprecateBreadcrumbs","ERRORSUMMARYS","deprecateErrorSummary","DIALOGS","deprecateDialog","closedby","deprecateCounter","count","deprecateDataCommand","command","TABS","isBrowser","deprecateUTabs","CSS_SUGGESTION","OLD","NEW","deprecateUCombobox","handleCommandClick","row","dialog","FIELDS","FIELD_UNBIND","deprecateField","DSFieldElement","unbindFields","CSS_DESCRIPTIONS","deprecateFeildDescription","VALIDATIONS","deprecateFieldValidation","deprecatePopoverPosition","handleDeprecations","debounce","onHotReload","on","QUICK_EVENT","onMutation"],"mappings":";;;AAaA,MAAMA,wBAAmB,QAAA,GACnBC,IAAY,CAACC,MAClB,CAACF,EAAa,IAAIE,CAAE,KAAKF,EAAa,IAAIE,CAAE,GAEvCC,IAAO,CAACC,GAAcC,GAAYH,MACvC,OAAO,eAAe,MACtB,QAAQ;AAAA,EACP,qCAAqCE,CAAI,8BAA8BC,CAAE;AAAA,EACzEH;AACD,GAGKI,IAAeC,EAAe,aAAa,GAC3CC,IAAaC,EAAO,OAAO,MAAM,GAAG,GACpCC,IAAuB,MAAM;AAClC,aAAWR,KAAMI,GAAc;AAC9B,IAAIL,EAAUC,CAAE,KAAK,CAACA,EAAG,aAAa,mBAAmB,MACxDS,EAAKT,GAAI,qBAAqB,aAAa,GAC3CC;AAAA,MACC;AAAA,MACA;AAAA,MACAD;AAAA,IAAA;AAGF,eAAWU,KAASV,EAAG,qBAAqB,OAAO;AAClD,MAAID,EAAUW,CAAK,KAAK,CAACA,EAAM,UAAU,SAASJ,EAAW,CAAC,CAAC,MAC9DI,EAAM,UAAU,IAAI,GAAGJ,CAAU,GACjCL;AAAA,QACC;AAAA,QACA;AAAA,QACAS;AAAA,MAAA;AAAA,EAIJ;AACD,GAGMC,IAAcN,EAAe,aAAa,GAC1CO,IAAuB,MAAM;AAClC,aAAWZ,KAAMW;AAChB,IAAIZ,EAAUC,CAAE,KAAKA,EAAG,aAAa,qBACpCA,EAAG,UAAU,IAAI,GAAGO,EAAO,YAAY,MAAM,GAAG,CAAC,GACjDN;AAAA,MACC;AAAA,MACA;AAAA,MACAD;AAAA,IAAA;AAGJ,GAGMa,IAAgBR,EAAe,cAAc,GAC7CS,IA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D,CAAE;AAE7C,GAEM0C,IAAqBC,EAAS,MAAM;AACzC,EAAAzB,EAAA,GACAE,EAAA,GACAR,EAAA,GACAI,EAAA,GACAF,EAAA,GACAwB,EAAA,GACAE,EAAA,GACAC,EAAA,GACAP,EAAA,GACA1B,EAAA,GACAoB,EAAA,GACAJ,EAAA;AACD,GAAG,GAAG;AAENoB,EAAY,gBAAgB,MAAM;AAAA,EACjCR;AAAA;AAAA,EACAS,EAAG,UAAU,SAAShB,GAAoBiB,CAAW;AAAA,EACrDD,EAAG,UAAU,UAAU7B,GAAiB,EAAI;AAAA,EAC5C+B,EAAW,UAAUL,GAAoB;AAAA,IACxC,iBAAiB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,IAED,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,SAAS;AAAA,EAAA,CACT;AACF,CAAC;"}
@@ -6,6 +6,7 @@ export default meta;
6
6
  type Story = StoryObj<typeof meta>;
7
7
  export declare const Default: Story;
8
8
  export declare const React: Story;
9
+ export declare const ReactWithState: Story;
9
10
  export declare const WithClose: Story;
10
11
  export declare const WithBackdropClose: Story;
11
12
  export declare const WithStickyFooter: Story;
@@ -182,7 +182,15 @@ const V = (a) => typeof a == "string" ? { label: a, value: a } : a, ie = s(funct
182
182
  );
183
183
  }), U = s(
184
184
  function({ "data-count": t, "data-limit": n, ...i }, d) {
185
- return /* @__PURE__ */ e(T, { "data-field": "counter", "data-limit": t, ref: d, ...i });
185
+ return /* @__PURE__ */ e(
186
+ T,
187
+ {
188
+ "data-field": "counter",
189
+ "data-limit": n || t,
190
+ ref: d,
191
+ ...i
192
+ }
193
+ );
186
194
  }
187
195
  ), ue = Object.assign(ie, {
188
196
  Affixes: G,
@@ -1 +1 @@
1
- {"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["\"use client\";\nimport type { DSSuggestionElement } from \"@digdir/designsystemet-web\";\nimport type { Placement } from \"@floating-ui/dom\";\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\tCustomReactElementProps,\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\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[] | FieldSuggestionSelected;\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: FieldSuggestionSelected[number] | string,\n): FieldSuggestionSelected[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\": dataValidation,\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 || \"ds-field\";\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\": dataValidation,\n\t\tclass: clsx(styles.field, className),\n\t\tsuppressHydrationWarning: true,\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<ds-field {...shared}>\n\t\t\t{!!label && <FieldLabel>{label}</FieldLabel>}\n\t\t\t{!!helpText && <HelpText aria-label={helpTextLabel}>{helpText}</HelpText>}\n\t\t\t{!!description && <FieldDescription>{description}</FieldDescription>}\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={typeof as === \"string\" ? styles.input : undefined}\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 && <Validation>{validation}</Validation>}\n\t\t\t{!!count && <FieldCount data-limit={count} />}\n\t\t</ds-field>\n\t) : (\n\t\t<ds-field 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/**\n\t * @deprecated Use `data-placement` instead.\n\t */\n\t\"data-position\"?: Placement;\n\t\"data-placement\"?: Placement;\n};\n\nconst FieldDatalist = forwardRef<HTMLDataListElement, FieldDatalistProps>(\n\tfunction FieldDatalist(\n\t\t{ \"data-position\": placement, \"data-nofilter\": filter, ...rest },\n\t\tref,\n\t) {\n\t\treturn (\n\t\t\t<u-datalist\n\t\t\t\tdata-placement={placement} // Backward compatibility\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 = FieldSuggestionSelected; // Backwards compatibility\nexport type FieldComboboxProps = FieldSuggestionProps; // Backwards compatibility\n\nexport type FieldSuggestionSelected = {\n\tlabel: string;\n\tvalue: string;\n\tchildren?: React.ReactNode;\n}[];\nexport type FieldSuggestionProps = Omit<\n\tCustomReactElementProps<DSSuggestionElement>,\n\t\"onChange\" | \"onInput\"\n> & {\n\t\"data-creatable\"?: boolean;\n\t\"data-multiple\"?: boolean;\n\tonAfterChange?: (e: CustomEvent<HTMLDataElement>) => void; // Backwards compatibility\n\tonAfterSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void; // Backwards compatibility\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: FieldSuggestionSelected) => void; // Allow onChange to be a function that returns void\n\toptions?: FieldSuggestionSelected;\n\tselected?: FieldSuggestionSelected; // 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<\n\t\tFieldDatalistProps,\n\t\t\"data-position\" | \"data-placement\" | \"data-nofilter\"\n\t>; // Allow datalist props to be passed down\n\nconst FieldSuggestion = forwardRef<\n\tDSSuggestionElement,\n\tFieldSuggestionProps | FieldSuggestionProps\n>(function FieldSuggestion(\n\t{\n\t\t\"aria-required\": required,\n\t\t\"data-position\": position,\n\t\t\"data-placement\": placement,\n\t\t\"data-nofilter\": nofilter,\n\t\t\"data-multiple\": multiple,\n\t\tonAfterChange, // Backwards compatibility\n\t\tonAfterSelect,\n\t\tonBeforeChange, // Backwards compatibility\n\t\tonBeforeMatch,\n\t\tonBeforeSelect,\n\t\tonSelectedChange,\n\t\tonInput,\n\t\tonChange,\n\t\tchildren,\n\t\tdisabled,\n\t\tname,\n\t\toptions,\n\t\tplaceholder,\n\t\treadOnly,\n\t\tselected,\n\t\ttype,\n\t\t...props\n\t},\n\tref,\n) {\n\tconst innerRef = useRef<DSSuggestionElement>(null);\n\tconst onSelected = useRef(onSelectedChange);\n\tonSelected.current = onSelectedChange; // Sync the latest onSelectedChange function\n\n\t// Deprecated props\n\tif (onAfterChange) {\n\t\tonAfterSelect = onAfterChange;\n\t\twindow.dsWarnings === false ||\n\t\t\tconsole.warn(\n\t\t\t\t`\\x1B[1m@mattilsynet/design - deprecation warning:\\x1B[m onAfterChange is deprecated, please use onAfterSelect instead`,\n\t\t\t);\n\t}\n\n\tif (onBeforeChange) {\n\t\tonBeforeSelect = onBeforeChange;\n\t\twindow.dsWarnings === false ||\n\t\t\tconsole.warn(\n\t\t\t\t`\\x1B[1m@mattilsynet/design - deprecation warning:\\x1B[m onBeforeChange is deprecated, please use onBeforeSelect instead`,\n\t\t\t);\n\t}\n\n\t// Using useEffect for React 18 and lower compatibility\n\tuseImperativeHandle(ref, () => innerRef.current as DSSuggestionElement); // Forward innerRef\n\tuseEffect(() => {\n\t\tconst self = innerRef.current;\n\t\tconst handleChange = (event: CustomEvent<HTMLDataElement>) => {\n\t\t\tconst handleSelected = onSelected.current;\n\t\t\tif (!onSelected) return; // No onSelectedChange function provided, let ds-suggestion handle it\n\t\t\tevent.preventDefault();\n\t\t\tconst { isConnected: remove, textContent, value } = event.detail;\n\t\t\tconst label = textContent?.trim() || \"\";\n\t\t\tconst prev = selected || [];\n\n\t\t\tif (remove) handleSelected?.(prev.filter((i) => i.value !== value));\n\t\t\telse if (multiple) handleSelected?.([...prev, { value, label }]);\n\t\t\telse handleSelected?.([{ value, label }]);\n\t\t};\n\n\t\tself?.addEventListener(\"comboboxbeforeselect\", handleChange);\n\t\treturn () =>\n\t\t\tself?.removeEventListener(\"comboboxbeforeselect\", handleChange);\n\t}, [multiple, selected]);\n\n\treturn (\n\t\t<ds-suggestion\n\t\t\tdata-multiple={multiple || undefined}\n\t\t\t{...toCustomElementProps(\n\t\t\t\t{\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\tstyles.suggestion,\n\t\t\t)}\n\t\t>\n\t\t\t{selected?.map(({ children, label, value }) => (\n\t\t\t\t<data key={value} value={value} suppressHydrationWarning>\n\t\t\t\t\t{children ?? label}\n\t\t\t\t</data>\n\t\t\t))}\n\t\t\t{children || (\n\t\t\t\t<>\n\t\t\t\t\t<Input\n\t\t\t\t\t\taria-required={required}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\tname={name}\n\t\t\t\t\t\tonInput={onInput}\n\t\t\t\t\t\tonChange={onChange}\n\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\ttype={type}\n\t\t\t\t\t/>\n\t\t\t\t\t<del aria-label=\"Fjern tekst\" suppressHydrationWarning />\n\t\t\t\t</>\n\t\t\t)}\n\t\t\t{!!options && (\n\t\t\t\t<FieldDatalist\n\t\t\t\t\tdata-nofilter={nofilter}\n\t\t\t\t\tdata-placement={placement || position}\n\t\t\t\t>\n\t\t\t\t\t{options.map(toOption).map(({ children, label, value }) => (\n\t\t\t\t\t\t<FieldOption key={value} value={value} label={label}>\n\t\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t\t</FieldOption>\n\t\t\t\t\t))}\n\t\t\t\t</FieldDatalist>\n\t\t\t)}\n\t\t</ds-suggestion>\n\t);\n});\n\nexport type FieldLabelProps = React.ComponentPropsWithoutRef<\"label\">;\nconst FieldLabel = forwardRef<HTMLLabelElement, FieldLabelProps>(\n\tfunction FieldLabel(rest, ref) {\n\t\treturn <label suppressHydrationWarning ref={ref} {...rest} />;\n\t},\n);\n\nexport type FieldDescriptionProps = React.ComponentPropsWithoutRef<\"p\">;\nconst FieldDescription = forwardRef<\n\tHTMLParagraphElement,\n\tFieldDescriptionProps\n>(function FieldDescription(rest, ref) {\n\treturn (\n\t\t<div\n\t\t\tsuppressHydrationWarning\n\t\t\tdata-field=\"description\"\n\t\t\tref={ref}\n\t\t\t{...rest}\n\t\t/>\n\t);\n});\n\nexport type FieldCountProps = React.ComponentPropsWithoutRef<\"p\"> & {\n\t/**\n\t * @deprecated Use \"data-limit\" instead\n\t */\n\t\"data-count\"?: number;\n\t\"data-limit\": number;\n};\nconst FieldCount = forwardRef<HTMLParagraphElement, FieldCountProps>(\n\tfunction FieldCount(\n\t\t{ \"data-count\": count, \"data-limit\": limit, ...rest },\n\t\tref,\n\t) {\n\t\treturn (\n\t\t\t<Validation data-field=\"counter\" data-limit={count} ref={ref} {...rest} />\n\t\t);\n\t},\n);\n\nexport const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\t/**\n\t * @deprecated Use Field.Suggestion instead\n\t */\n\tCombobox: FieldSuggestion, // Backwards compatibility\n\tSuggestion: FieldSuggestion,\n\tDatalist: FieldDatalist,\n\tOption: FieldOption,\n\tDescription: FieldDescription,\n\tLabel: FieldLabel,\n\tCount: FieldCount,\n});\n"],"names":["toOption","o","FieldComp","forwardRef","size","dataValidation","as","className","count","description","error","helpText","helpTextLabel","label","prefix","style","suffix","validationContent","rest","ref","Tag","affixes","validation","shared","clsx","styles","value","jsx","jsxs","FieldLabel","HelpText","FieldDescription","FieldAffixes","Validation","FieldCount","FieldDatalist","placement","filter","toCustomElementProps","FieldOption","props","FieldSuggestion","required","position","nofilter","multiple","onAfterChange","onAfterSelect","onBeforeChange","onBeforeMatch","onBeforeSelect","onSelectedChange","onInput","onChange","children","disabled","name","options","placeholder","readOnly","selected","type","innerRef","useRef","onSelected","useImperativeHandle","useEffect","self","handleChange","event","handleSelected","remove","textContent","prev","i","Fragment","Input","limit","Field"],"mappings":";;;;;;;;AAsCA,MAAMA,IAAW,CAChBC,MAEA,OAAOA,KAAM,WAAW,EAAE,OAAOA,GAAG,OAAOA,EAAA,IAAMA,GAErCC,KAA4BC,EAAiB,SAGzD;AAAA,EACC,aAAaC;AAAA,EACb,mBAAmBC;AAAA,EACnB,IAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AAAA,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AAb,GACrC,UAAAyC,KAAYzC,EAAA,GADIa,CAElB,CACA;AAAA,UAAA;AAAA,QAAA;AAAA,MACF;AAAA,IAAA;AAAA,EAAA;AAIJ,CAAC,GAGKG,IAAa1B;AAAA,EAClB,SAAoBe,GAAMC,GAAK;AAC9B,6BAAQ,SAAA,EAAM,0BAAwB,IAAC,KAAAA,GAAW,GAAGD,GAAM;AAAA,EAC5D;AACD,GAGMa,IAAmB5B,EAGvB,SAA0Be,GAAMC,GAAK;AACtC,SACC,gBAAAQ;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,0BAAwB;AAAA,MACxB,cAAW;AAAA,MACX,KAAAR;AAAA,MACC,GAAGD;AAAA,IAAA;AAAA,EAAA;AAGP,CAAC,GASKgB,IAAa/B;AAAA,EAClB,SACC,EAAE,cAAcK,GAAO,cAAcqE,GAAO,GAAG3D,EAAA,GAC/CC,GACC;AACD,WACC,gBAAAQ,EAACM,KAAW,cAAW,WAAU,cAAYzB,GAAO,KAAAW,GAAW,GAAGD,GAAM;AAAA,EAE1E;AACD,GAEa4D,KAAQ,OAAO,OAAO5E,IAAW;AAAA,EAC7C,SAAS8B;AAAA;AAAA;AAAA;AAAA,EAIT,UAAUS;AAAA;AAAA,EACV,YAAYA;AAAA,EACZ,UAAUN;AAAA,EACV,QAAQI;AAAA,EACR,aAAaR;AAAA,EACb,OAAOF;AAAA,EACP,OAAOK;AACR,CAAC;"}
1
+ {"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["\"use client\";\nimport type { DSSuggestionElement } from \"@digdir/designsystemet-web\";\nimport type { Placement } from \"@floating-ui/dom\";\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\tCustomReactElementProps,\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\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[] | FieldSuggestionSelected;\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: FieldSuggestionSelected[number] | string,\n): FieldSuggestionSelected[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\": dataValidation,\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 || \"ds-field\";\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\": dataValidation,\n\t\tclass: clsx(styles.field, className),\n\t\tsuppressHydrationWarning: true,\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<ds-field {...shared}>\n\t\t\t{!!label && <FieldLabel>{label}</FieldLabel>}\n\t\t\t{!!helpText && <HelpText aria-label={helpTextLabel}>{helpText}</HelpText>}\n\t\t\t{!!description && <FieldDescription>{description}</FieldDescription>}\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={typeof as === \"string\" ? styles.input : undefined}\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 && <Validation>{validation}</Validation>}\n\t\t\t{!!count && <FieldCount data-limit={count} />}\n\t\t</ds-field>\n\t) : (\n\t\t<ds-field 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/**\n\t * @deprecated Use `data-placement` instead.\n\t */\n\t\"data-position\"?: Placement;\n\t\"data-placement\"?: Placement;\n};\n\nconst FieldDatalist = forwardRef<HTMLDataListElement, FieldDatalistProps>(\n\tfunction FieldDatalist(\n\t\t{ \"data-position\": placement, \"data-nofilter\": filter, ...rest },\n\t\tref,\n\t) {\n\t\treturn (\n\t\t\t<u-datalist\n\t\t\t\tdata-placement={placement} // Backward compatibility\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 = FieldSuggestionSelected; // Backwards compatibility\nexport type FieldComboboxProps = FieldSuggestionProps; // Backwards compatibility\n\nexport type FieldSuggestionSelected = {\n\tlabel: string;\n\tvalue: string;\n\tchildren?: React.ReactNode;\n}[];\nexport type FieldSuggestionProps = Omit<\n\tCustomReactElementProps<DSSuggestionElement>,\n\t\"onChange\" | \"onInput\"\n> & {\n\t\"data-creatable\"?: boolean;\n\t\"data-multiple\"?: boolean;\n\tonAfterChange?: (e: CustomEvent<HTMLDataElement>) => void; // Backwards compatibility\n\tonAfterSelect?: (e: CustomEvent<HTMLDataElement>) => void; // Custom event to handle before change\n\tonBeforeChange?: (e: CustomEvent<HTMLDataElement>) => void; // Backwards compatibility\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: FieldSuggestionSelected) => void; // Allow onChange to be a function that returns void\n\toptions?: FieldSuggestionSelected;\n\tselected?: FieldSuggestionSelected; // 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<\n\t\tFieldDatalistProps,\n\t\t\"data-position\" | \"data-placement\" | \"data-nofilter\"\n\t>; // Allow datalist props to be passed down\n\nconst FieldSuggestion = forwardRef<\n\tDSSuggestionElement,\n\tFieldSuggestionProps | FieldSuggestionProps\n>(function FieldSuggestion(\n\t{\n\t\t\"aria-required\": required,\n\t\t\"data-position\": position,\n\t\t\"data-placement\": placement,\n\t\t\"data-nofilter\": nofilter,\n\t\t\"data-multiple\": multiple,\n\t\tonAfterChange, // Backwards compatibility\n\t\tonAfterSelect,\n\t\tonBeforeChange, // Backwards compatibility\n\t\tonBeforeMatch,\n\t\tonBeforeSelect,\n\t\tonSelectedChange,\n\t\tonInput,\n\t\tonChange,\n\t\tchildren,\n\t\tdisabled,\n\t\tname,\n\t\toptions,\n\t\tplaceholder,\n\t\treadOnly,\n\t\tselected,\n\t\ttype,\n\t\t...props\n\t},\n\tref,\n) {\n\tconst innerRef = useRef<DSSuggestionElement>(null);\n\tconst onSelected = useRef(onSelectedChange);\n\tonSelected.current = onSelectedChange; // Sync the latest onSelectedChange function\n\n\t// Deprecated props\n\tif (onAfterChange) {\n\t\tonAfterSelect = onAfterChange;\n\t\twindow.dsWarnings === false ||\n\t\t\tconsole.warn(\n\t\t\t\t`\\x1B[1m@mattilsynet/design - deprecation warning:\\x1B[m onAfterChange is deprecated, please use onAfterSelect instead`,\n\t\t\t);\n\t}\n\n\tif (onBeforeChange) {\n\t\tonBeforeSelect = onBeforeChange;\n\t\twindow.dsWarnings === false ||\n\t\t\tconsole.warn(\n\t\t\t\t`\\x1B[1m@mattilsynet/design - deprecation warning:\\x1B[m onBeforeChange is deprecated, please use onBeforeSelect instead`,\n\t\t\t);\n\t}\n\n\t// Using useEffect for React 18 and lower compatibility\n\tuseImperativeHandle(ref, () => innerRef.current as DSSuggestionElement); // Forward innerRef\n\tuseEffect(() => {\n\t\tconst self = innerRef.current;\n\t\tconst handleChange = (event: CustomEvent<HTMLDataElement>) => {\n\t\t\tconst handleSelected = onSelected.current;\n\t\t\tif (!onSelected) return; // No onSelectedChange function provided, let ds-suggestion handle it\n\t\t\tevent.preventDefault();\n\t\t\tconst { isConnected: remove, textContent, value } = event.detail;\n\t\t\tconst label = textContent?.trim() || \"\";\n\t\t\tconst prev = selected || [];\n\n\t\t\tif (remove) handleSelected?.(prev.filter((i) => i.value !== value));\n\t\t\telse if (multiple) handleSelected?.([...prev, { value, label }]);\n\t\t\telse handleSelected?.([{ value, label }]);\n\t\t};\n\n\t\tself?.addEventListener(\"comboboxbeforeselect\", handleChange);\n\t\treturn () =>\n\t\t\tself?.removeEventListener(\"comboboxbeforeselect\", handleChange);\n\t}, [multiple, selected]);\n\n\treturn (\n\t\t<ds-suggestion\n\t\t\tdata-multiple={multiple || undefined}\n\t\t\t{...toCustomElementProps(\n\t\t\t\t{\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\tstyles.suggestion,\n\t\t\t)}\n\t\t>\n\t\t\t{selected?.map(({ children, label, value }) => (\n\t\t\t\t<data key={value} value={value} suppressHydrationWarning>\n\t\t\t\t\t{children ?? label}\n\t\t\t\t</data>\n\t\t\t))}\n\t\t\t{children || (\n\t\t\t\t<>\n\t\t\t\t\t<Input\n\t\t\t\t\t\taria-required={required}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\tname={name}\n\t\t\t\t\t\tonInput={onInput}\n\t\t\t\t\t\tonChange={onChange}\n\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\ttype={type}\n\t\t\t\t\t/>\n\t\t\t\t\t<del aria-label=\"Fjern tekst\" suppressHydrationWarning />\n\t\t\t\t</>\n\t\t\t)}\n\t\t\t{!!options && (\n\t\t\t\t<FieldDatalist\n\t\t\t\t\tdata-nofilter={nofilter}\n\t\t\t\t\tdata-placement={placement || position}\n\t\t\t\t>\n\t\t\t\t\t{options.map(toOption).map(({ children, label, value }) => (\n\t\t\t\t\t\t<FieldOption key={value} value={value} label={label}>\n\t\t\t\t\t\t\t{children ?? label}\n\t\t\t\t\t\t</FieldOption>\n\t\t\t\t\t))}\n\t\t\t\t</FieldDatalist>\n\t\t\t)}\n\t\t</ds-suggestion>\n\t);\n});\n\nexport type FieldLabelProps = React.ComponentPropsWithoutRef<\"label\">;\nconst FieldLabel = forwardRef<HTMLLabelElement, FieldLabelProps>(\n\tfunction FieldLabel(rest, ref) {\n\t\treturn <label suppressHydrationWarning ref={ref} {...rest} />;\n\t},\n);\n\nexport type FieldDescriptionProps = React.ComponentPropsWithoutRef<\"p\">;\nconst FieldDescription = forwardRef<\n\tHTMLParagraphElement,\n\tFieldDescriptionProps\n>(function FieldDescription(rest, ref) {\n\treturn (\n\t\t<div\n\t\t\tsuppressHydrationWarning\n\t\t\tdata-field=\"description\"\n\t\t\tref={ref}\n\t\t\t{...rest}\n\t\t/>\n\t);\n});\n\nexport type FieldCountProps = React.ComponentPropsWithoutRef<\"p\"> & {\n\t/**\n\t * @deprecated Use \"data-limit\" instead\n\t */\n\t\"data-count\"?: number;\n\t\"data-limit\": number;\n};\nconst FieldCount = forwardRef<HTMLParagraphElement, FieldCountProps>(\n\tfunction FieldCount(\n\t\t{ \"data-count\": count, \"data-limit\": limit, ...rest },\n\t\tref,\n\t) {\n\t\treturn (\n\t\t\t<Validation\n\t\t\t\tdata-field=\"counter\"\n\t\t\t\tdata-limit={limit || count}\n\t\t\t\tref={ref}\n\t\t\t\t{...rest}\n\t\t\t/>\n\t\t);\n\t},\n);\n\nexport const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\t/**\n\t * @deprecated Use Field.Suggestion instead\n\t */\n\tCombobox: FieldSuggestion, // Backwards compatibility\n\tSuggestion: FieldSuggestion,\n\tDatalist: FieldDatalist,\n\tOption: FieldOption,\n\tDescription: FieldDescription,\n\tLabel: FieldLabel,\n\tCount: FieldCount,\n});\n"],"names":["toOption","o","FieldComp","forwardRef","size","dataValidation","as","className","count","description","error","helpText","helpTextLabel","label","prefix","style","suffix","validationContent","rest","ref","Tag","affixes","validation","shared","clsx","styles","value","jsx","jsxs","FieldLabel","HelpText","FieldDescription","FieldAffixes","Validation","FieldCount","FieldDatalist","placement","filter","toCustomElementProps","FieldOption","props","FieldSuggestion","required","position","nofilter","multiple","onAfterChange","onAfterSelect","onBeforeChange","onBeforeMatch","onBeforeSelect","onSelectedChange","onInput","onChange","children","disabled","name","options","placeholder","readOnly","selected","type","innerRef","useRef","onSelected","useImperativeHandle","useEffect","self","handleChange","event","handleSelected","remove","textContent","prev","i","Fragment","Input","limit","Field"],"mappings":";;;;;;;;AAsCA,MAAMA,IAAW,CAChBC,MAEA,OAAOA,KAAM,WAAW,EAAE,OAAOA,GAAG,OAAOA,EAAA,IAAMA,GAErCC,KAA4BC,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;A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