@mattilsynet/design 3.0.1 → 3.0.3

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,40 +1,40 @@
1
- import { jsx as e, jsxs as a } from "react/jsx-runtime";
2
- import i from "clsx";
1
+ import { jsx as e, jsxs as i } from "react/jsx-runtime";
2
+ import c from "clsx";
3
3
  import { forwardRef as p } from "react";
4
- import c from "../styles.module.css.js";
4
+ import l from "../styles.module.css.js";
5
5
  const f = p(
6
- function({ "data-toggle-group": o, className: g, ...r }, t) {
6
+ function({ "data-toggle-group": o, className: t, ...g }, r) {
7
7
  return /* @__PURE__ */ e(
8
8
  "fieldset",
9
9
  {
10
- className: i(c.togglegroup, g),
10
+ className: c(l.togglegroup, t),
11
11
  "data-toggle-group": o || "Valgknapper",
12
- ref: t,
13
- ...r
12
+ ref: r,
13
+ ...g
14
14
  }
15
15
  );
16
16
  }
17
17
  ), d = p(
18
- function({ children: o, checked: g, defaultChecked: r, value: t, name: s, onChange: m, ...n }, u) {
19
- return /* @__PURE__ */ a("label", { ref: u, ...n, children: [
18
+ function({ children: o, checked: t, defaultChecked: g, value: r, name: a, onChange: m, ...n }, u) {
19
+ return /* @__PURE__ */ i("label", { ref: u, ...n, className: l.button, children: [
20
20
  /* @__PURE__ */ e(
21
21
  "input",
22
22
  {
23
23
  type: "radio",
24
- checked: g,
25
- defaultChecked: r,
26
- value: t,
27
- name: s,
24
+ checked: t,
25
+ defaultChecked: g,
26
+ value: r,
27
+ name: a,
28
28
  onChange: m
29
29
  }
30
30
  ),
31
31
  o
32
32
  ] });
33
33
  }
34
- ), b = Object.assign(f, {
34
+ ), I = Object.assign(f, {
35
35
  Item: d
36
36
  });
37
37
  export {
38
- b as Togglegroup
38
+ I as Togglegroup
39
39
  };
40
40
  //# sourceMappingURL=togglegroup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"togglegroup.js","sources":["../../designsystem/togglegroup/togglegroup.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef } from \"react\";\nimport type { InputProps } from \"../react\";\nimport styles from \"../styles.module.css\";\n\nexport type TogglegroupProps = React.ComponentPropsWithoutRef<\"fieldset\"> & {\n\t\"data-toggle-group\"?: string;\n};\nexport type TogglegroupItemProps = Omit<\n\tReact.ComponentPropsWithoutRef<\"label\">,\n\t\"onChange\"\n> &\n\tPick<InputProps, \"defaultChecked\" | \"checked\" | \"onChange\" | \"value\"> &\n\tRequired<Pick<InputProps, \"name\">>; // Make name required\n\nconst TogglegroupComp = forwardRef<HTMLFieldSetElement, TogglegroupProps>(\n\tfunction Togglegroup(\n\t\t{ \"data-toggle-group\": label, className, ...rest },\n\t\tref,\n\t) {\n\t\treturn (\n\t\t\t<fieldset\n\t\t\t\tclassName={clsx(styles.togglegroup, className)}\n\t\t\t\tdata-toggle-group={label || \"Valgknapper\"}\n\t\t\t\tref={ref}\n\t\t\t\t{...rest}\n\t\t\t/>\n\t\t);\n\t},\n);\nconst TogglegroupItem = forwardRef<HTMLLabelElement, TogglegroupItemProps>(\n\tfunction TogglegroupItem(\n\t\t{ children, checked, defaultChecked, value, name, onChange, ...rest },\n\t\tref,\n\t) {\n\t\treturn (\n\t\t\t<label ref={ref} {...rest}>\n\t\t\t\t<input\n\t\t\t\t\t{...{ type: \"radio\", checked, defaultChecked, value, name, onChange }}\n\t\t\t\t/>\n\t\t\t\t{children}\n\t\t\t</label>\n\t\t);\n\t},\n);\n\nexport const Togglegroup = Object.assign(TogglegroupComp, {\n\tItem: TogglegroupItem,\n});\n"],"names":["TogglegroupComp","forwardRef","label","className","rest","ref","jsx","clsx","styles","TogglegroupItem","children","checked","defaultChecked","value","name","onChange","jsxs","Togglegroup"],"mappings":";;;;AAeA,MAAMA,IAAkBC;AAAA,EACvB,SACC,EAAE,qBAAqBC,GAAO,WAAAC,GAAW,GAAGC,EAAA,GAC5CC,GACC;AACD,WACC,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACA,WAAWC,EAAKC,EAAO,aAAaL,CAAS;AAAA,QAC7C,qBAAmBD,KAAS;AAAA,QAC5B,KAAAG;AAAA,QACC,GAAGD;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACD,GACMK,IAAkBR;AAAA,EACvB,SACC,EAAE,UAAAS,GAAU,SAAAC,GAAS,gBAAAC,GAAgB,OAAAC,GAAO,MAAAC,GAAM,UAAAC,GAAU,GAAGX,EAAA,GAC/DC,GACC;AACD,WACC,gBAAAW,EAAC,SAAA,EAAM,KAAAX,GAAW,GAAGD,GACpB,UAAA;AAAA,MAAA,gBAAAE;AAAA,QAAC;AAAA,QAAA;AAAA,UACM,MAAM;AAAA,UAAS,SAAAK;AAAA,UAAS,gBAAAC;AAAA,UAAgB,OAAAC;AAAA,UAAO,MAAAC;AAAA,UAAM,UAAAC;AAAA,QAAS;AAAA,MAAA;AAAA,MAEpEL;AAAA,IAAA,GACF;AAAA,EAEF;AACD,GAEaO,IAAc,OAAO,OAAOjB,GAAiB;AAAA,EACzD,MAAMS;AACP,CAAC;"}
1
+ {"version":3,"file":"togglegroup.js","sources":["../../designsystem/togglegroup/togglegroup.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef } from \"react\";\nimport type { InputProps } from \"../react\";\nimport styles from \"../styles.module.css\";\n\nexport type TogglegroupProps = React.ComponentPropsWithoutRef<\"fieldset\"> & {\n\t\"data-toggle-group\"?: string;\n};\nexport type TogglegroupItemProps = Omit<\n\tReact.ComponentPropsWithoutRef<\"label\">,\n\t\"onChange\"\n> &\n\tPick<InputProps, \"defaultChecked\" | \"checked\" | \"onChange\" | \"value\"> &\n\tRequired<Pick<InputProps, \"name\">>; // Make name required\n\nconst TogglegroupComp = forwardRef<HTMLFieldSetElement, TogglegroupProps>(\n\tfunction Togglegroup(\n\t\t{ \"data-toggle-group\": label, className, ...rest },\n\t\tref,\n\t) {\n\t\treturn (\n\t\t\t<fieldset\n\t\t\t\tclassName={clsx(styles.togglegroup, className)}\n\t\t\t\tdata-toggle-group={label || \"Valgknapper\"}\n\t\t\t\tref={ref}\n\t\t\t\t{...rest}\n\t\t\t/>\n\t\t);\n\t},\n);\nconst TogglegroupItem = forwardRef<HTMLLabelElement, TogglegroupItemProps>(\n\tfunction TogglegroupItem(\n\t\t{ children, checked, defaultChecked, value, name, onChange, ...rest },\n\t\tref,\n\t) {\n\t\treturn (\n\t\t\t<label ref={ref} {...rest} className={styles.button}>\n\t\t\t\t<input\n\t\t\t\t\t{...{ type: \"radio\", checked, defaultChecked, value, name, onChange }}\n\t\t\t\t/>\n\t\t\t\t{children}\n\t\t\t</label>\n\t\t);\n\t},\n);\n\nexport const Togglegroup = Object.assign(TogglegroupComp, {\n\tItem: TogglegroupItem,\n});\n"],"names":["TogglegroupComp","forwardRef","label","className","rest","ref","jsx","clsx","styles","TogglegroupItem","children","checked","defaultChecked","value","name","onChange","Togglegroup"],"mappings":";;;;AAeA,MAAMA,IAAkBC;AAAA,EACvB,SACC,EAAE,qBAAqBC,GAAO,WAAAC,GAAW,GAAGC,EAAA,GAC5CC,GACC;AACD,WACC,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACA,WAAWC,EAAKC,EAAO,aAAaL,CAAS;AAAA,QAC7C,qBAAmBD,KAAS;AAAA,QAC5B,KAAAG;AAAA,QACC,GAAGD;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACD,GACMK,IAAkBR;AAAA,EACvB,SACC,EAAE,UAAAS,GAAU,SAAAC,GAAS,gBAAAC,GAAgB,OAAAC,GAAO,MAAAC,GAAM,UAAAC,GAAU,GAAGX,EAAA,GAC/DC,GACC;AACD,6BACE,SAAA,EAAM,KAAAA,GAAW,GAAGD,GAAM,WAAWI,EAAO,QAC5C,UAAA;AAAA,MAAA,gBAAAF;AAAA,QAAC;AAAA,QAAA;AAAA,UACM,MAAM;AAAA,UAAS,SAAAK;AAAA,UAAS,gBAAAC;AAAA,UAAgB,OAAAC;AAAA,UAAO,MAAAC;AAAA,UAAM,UAAAC;AAAA,QAAS;AAAA,MAAA;AAAA,MAEpEL;AAAA,IAAA,GACF;AAAA,EAEF;AACD,GAEaM,IAAc,OAAO,OAAOhB,GAAiB;AAAA,EACzD,MAAMS;AACP,CAAC;"}
package/mtds/utils.d.ts CHANGED
@@ -8,11 +8,11 @@ export declare function debounce<T extends unknown[]>(callback: (...args: T) =>
8
8
  /**
9
9
  * attr
10
10
  * @description Utility to quickly get, set and remove attributes
11
- * @param el The Element to use as EventTarget
11
+ * @param el The Element to read/write attributes from
12
12
  * @param name The attribute name to get, set or remove, or a object to set multiple attributes
13
13
  * @param value A valid attribute value or null to remove attribute
14
14
  */
15
- export declare function attr(el: Element, name: string, value?: string | null): string | null;
15
+ export declare const attr: (el: Element, name: string, value?: string | null) => string | null;
16
16
  /**
17
17
  * on
18
18
  * @param el The Element to use as EventTarget
package/mtds/utils.js CHANGED
@@ -1,42 +1,39 @@
1
1
  import u from "clsx";
2
2
  import l from "./styles.module.css.js";
3
- const E = { capture: !0, passive: !0 }, c = () => typeof window < "u" && typeof document < "u", y = (e) => c() ? document.getElementsByClassName(l[e].split(" ")[0]) : [];
4
- function b(e, t) {
3
+ const E = { capture: !0, passive: !0 }, d = () => typeof window < "u" && typeof document < "u", y = (e) => d() ? document.getElementsByClassName(l[e].split(" ")[0]) : [];
4
+ function C(e, t) {
5
5
  let n;
6
6
  return function(...o) {
7
7
  clearTimeout(n), n = setTimeout(() => e.apply(this, o), t);
8
8
  };
9
9
  }
10
- function a(e, t, n) {
11
- return n === void 0 ? e.getAttribute(t) ?? null : (n === null ? e.removeAttribute(t) : e.getAttribute(t) !== n && e.setAttribute(t, n), null);
12
- }
13
- const f = (e, ...t) => {
10
+ const a = (e, t, n) => n === void 0 ? e.getAttribute(t) ?? null : (n === null ? e.removeAttribute(t) : e.getAttribute(t) !== n && e.setAttribute(t, n), null), m = (e, ...t) => {
14
11
  const [n, ...o] = t;
15
12
  for (const s of n.split(" ")) e.addEventListener(s, ...o);
16
- return () => m(e, ...t);
17
- }, m = (e, ...t) => {
13
+ return () => f(e, ...t);
14
+ }, f = (e, ...t) => {
18
15
  const [n, ...o] = t;
19
16
  for (const s of n.split(" ")) e.removeEventListener(s, ...o);
20
- }, C = (e, t) => {
21
- if (!c()) return;
17
+ }, b = (e, t) => {
18
+ if (!d()) return;
22
19
  window._mtdsHotReloadCleanup || (window._mtdsHotReloadCleanup = /* @__PURE__ */ new Map());
23
20
  const n = () => {
24
21
  window._mtdsHotReloadCleanup?.get(e)?.map((o) => o()), window._mtdsHotReloadCleanup?.set(e, t());
25
22
  };
26
- document.readyState !== "complete" ? f(window, "load", n) : document.fonts?.ready?.then(n) || setTimeout(n, 0);
23
+ document.readyState !== "complete" ? m(window, "load", n) : document.fonts?.ready?.then(n) || setTimeout(n, 0);
27
24
  }, g = (e, t, n) => {
28
25
  let o = 0;
29
26
  const s = () => {
30
- if (!c()) return i();
27
+ if (!e.isConnected) return i();
31
28
  t(r), r.takeRecords(), o = 0;
32
29
  }, i = () => r?.disconnect?.(), r = new MutationObserver(() => {
33
30
  o || (o = requestAnimationFrame(s));
34
31
  });
35
32
  return r.observe(e, n), s(), i;
36
- }, d = "aria-selected", v = (e, t) => Object.assign({}, e, {
33
+ }, c = "aria-selected", v = (e, t) => Object.assign({}, e, {
37
34
  suppressHydrationWarning: !0,
38
35
  // Make Next.js happy
39
- [d]: e[d] === void 0 ? void 0 : `${(e[d] || "false") !== "false"}`,
36
+ [c]: e[c] === void 0 ? void 0 : `${(e[c] || "false") !== "false"}`,
40
37
  // Ensure aria-selected boolean is string
41
38
  class: u(t, e.className),
42
39
  // Use class instead of className
@@ -49,18 +46,18 @@ const f = (e, ...t) => {
49
46
  if (n && (o.textContent = n), t) for (const [s, i] of Object.entries(t)) a(o, s, i);
50
47
  return o;
51
48
  }, T = typeof HTMLElement > "u" ? class {
52
- } : HTMLElement, M = (e, t) => !c() || window.customElements.get(e) || window.customElements.define(e, t);
49
+ } : HTMLElement, M = (e, t) => !d() || window.customElements.get(e) || window.customElements.define(e, t);
53
50
  export {
54
51
  T as MTDSElement,
55
52
  E as QUICK_EVENT,
56
53
  a as attr,
57
- b as debounce,
54
+ C as debounce,
58
55
  M as defineElement,
59
56
  y as getByCSSModule,
60
- c as isBrowser,
61
- m as off,
62
- f as on,
63
- C as onHotReload,
57
+ d as isBrowser,
58
+ f as off,
59
+ m as on,
60
+ b as onHotReload,
64
61
  g as onMutation,
65
62
  H as tag,
66
63
  v as toCustomElementProps
package/mtds/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../designsystem/utils.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport styles from \"./styles.module.css\";\n\nexport const QUICK_EVENT = { capture: true, passive: true };\nexport const isBrowser = () =>\n\ttypeof window !== \"undefined\" && typeof document !== \"undefined\"; // Using function to play nice with Vitest where DOM can come and go\n\nexport const getByCSSModule = (key: string) =>\n\tisBrowser() ? document.getElementsByClassName(styles[key].split(\" \")[0]) : [];\n\nexport function debounce<T extends unknown[]>(\n\tcallback: (...args: T) => void,\n\tdelay: number,\n) {\n\tlet timer: ReturnType<typeof setTimeout>;\n\n\treturn function (this: unknown, ...args: T) {\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(() => callback.apply(this, args), delay);\n\t};\n}\n\n/**\n * attr\n * @description Utility to quickly get, set and remove attributes\n * @param el The Element to use as EventTarget\n * @param name The attribute name to get, set or remove, or a object to set multiple attributes\n * @param value A valid attribute value or null to remove attribute\n */\nexport function attr(\n\tel: Element,\n\tname: string,\n\tvalue?: string | null,\n): string | null {\n\tif (value === undefined) return el.getAttribute(name) ?? null; // Fallback to null only if el is undefined\n\tif (value === null) el.removeAttribute(name);\n\telse if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n\treturn null;\n}\n\n/**\n * on\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\tel: Node | Window | ShadowRoot,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): (() => void) => {\n\tconst [types, ...options] = rest;\n\tfor (const type of types.split(\" \")) el.addEventListener(type, ...options);\n\treturn () => off(el, ...rest);\n};\n\n/**\n * off\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\tel: Node | Window | ShadowRoot,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => {\n\tconst [types, ...options] = rest;\n\tfor (const type of types.split(\" \")) el.removeEventListener(type, ...options);\n};\n\ndeclare global {\n\tinterface Window {\n\t\t_mtdsHotReloadCleanup?: Map<string, Array<() => void>>;\n\t}\n}\n\n/**\n * onHotReload\n * @description Runs a callback when window is loaded in browser, and ensures cleanup when hot-reloading\n * @param key The key to identify setup and corresponding cleanup\n * @param callback The callback to run when the page is ready\n */\nexport const onHotReload = (key: string, setup: () => Array<() => void>) => {\n\tif (!isBrowser()) return; // Skip if not in modern browser environment, but on each call as Vitest might have unloaded jsdom between tests\n\tif (!window._mtdsHotReloadCleanup) window._mtdsHotReloadCleanup = new Map(); // Hot reload cleanup support supporting all build tools\n\n\tconst run = () => {\n\t\twindow._mtdsHotReloadCleanup?.get(key)?.map((cleanup) => cleanup()); // Run previous cleanup\n\t\twindow._mtdsHotReloadCleanup?.set(key, setup()); // Store new cleanup\n\t};\n\n\tif (document.readyState !== \"complete\") on(window, \"load\", run);\n\telse document.fonts?.ready?.then(run) || setTimeout(run, 0); // Prefer fonts ready promise if available, but fallback to setTimeout\n};\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport const onMutation = (\n\tel: Node,\n\tcallback: (observer: MutationObserver) => void,\n\toptions: MutationObserverInit,\n) => {\n\tlet queue = 0;\n\tconst onFrame = () => {\n\t\tif (!isBrowser()) return cleanup(); // If using JSDOM, the document might have been removed\n\t\tcallback(observer);\n\t\tobserver.takeRecords(); // Clear records to avoid multiple triggers\n\t\tqueue = 0;\n\t};\n\tconst cleanup = () => observer?.disconnect?.();\n\tconst observer = new MutationObserver(() => {\n\t\tif (!queue) queue = requestAnimationFrame(onFrame); // requestAnimationFrame only runs when page is not visible\n\t});\n\n\tobserver.observe(el, options);\n\tonFrame(); // Initial run\n\treturn cleanup;\n};\n\n/**\n * toCustomElementProps\n * @description Utility to quickly convert props to custom element attributes\n * @param props The props to convert\n * @returns The converted props\n */\nconst SELECTED = \"aria-selected\";\nexport const toCustomElementProps = <T extends Record<string, unknown>>(\n\trest: T,\n\tklass?: string,\n) =>\n\tObject.assign({}, rest, {\n\t\tsuppressHydrationWarning: true, // Make Next.js happy\n\t\t[SELECTED]:\n\t\t\trest[SELECTED] === undefined\n\t\t\t\t? undefined\n\t\t\t\t: (`${(rest[SELECTED] || \"false\") !== \"false\"}` as unknown as boolean), // Ensure aria-selected boolean is string\n\t\tclass: clsx(klass, rest.className as string), // Use class instead of className\n\t\thidden: !!rest.hidden, // Ensure boolean prop behaviour\n\t\topen: !!rest.open, // Ensure boolean prop behaviour\n\t});\n\n/**\n * tag\n * @description creates element and assigns properties\n * @param tagName The tagname of element to create\n * @param attrs Optional attributes to add to the element\n * @param text Optional text content to add to the element\n * @return HTMLElement with props\n */\nexport const tag = <TagName extends keyof HTMLElementTagNameMap>(\n\ttagName: TagName,\n\tattrs?: Record<string, string | null> | null,\n\ttext?: string | null,\n): HTMLElementTagNameMap[TagName] => {\n\tconst el = document.createElement(tagName);\n\tif (text) el.textContent = text;\n\tif (attrs) for (const [key, val] of Object.entries(attrs)) attr(el, key, val);\n\treturn el;\n};\n\n// Make sure we have a HTMLElement to extend (for server side rendering)\nexport const MTDSElement =\n\ttypeof HTMLElement === \"undefined\"\n\t\t? (class {} as typeof HTMLElement)\n\t\t: HTMLElement;\n\n/**\n * defineElement\n * @description Defines a customElement if running in browser and if not already registered\n */\nexport const defineElement = (\n\tname: string,\n\tinstance: CustomElementConstructor,\n) =>\n\t!isBrowser() ||\n\twindow.customElements.get(name) ||\n\twindow.customElements.define(name, instance);\n"],"names":["QUICK_EVENT","isBrowser","getByCSSModule","key","styles","debounce","callback","delay","timer","args","attr","el","name","value","on","rest","types","options","type","off","onHotReload","setup","run","cleanup","onMutation","queue","onFrame","observer","SELECTED","toCustomElementProps","klass","clsx","tag","tagName","attrs","text","val","MTDSElement","defineElement","instance"],"mappings":";;AAGO,MAAMA,IAAc,EAAE,SAAS,IAAM,SAAS,GAAA,GACxCC,IAAY,MACxB,OAAO,SAAW,OAAe,OAAO,WAAa,KAEzCC,IAAiB,CAACC,MAC9BF,EAAA,IAAc,SAAS,uBAAuBG,EAAOD,CAAG,EAAE,MAAM,GAAG,EAAE,CAAC,CAAC,IAAI,CAAA;AAErE,SAASE,EACfC,GACAC,GACC;AACD,MAAIC;AAEJ,SAAO,YAA4BC,GAAS;AAC3C,iBAAaD,CAAK,GAClBA,IAAQ,WAAW,MAAMF,EAAS,MAAM,MAAMG,CAAI,GAAGF,CAAK;AAAA,EAC3D;AACD;AASO,SAASG,EACfC,GACAC,GACAC,GACgB;AAChB,SAAIA,MAAU,SAAkBF,EAAG,aAAaC,CAAI,KAAK,QACrDC,MAAU,OAAMF,EAAG,gBAAgBC,CAAI,IAClCD,EAAG,aAAaC,CAAI,MAAMC,KAAOF,EAAG,aAAaC,GAAMC,CAAK,GAC9D;AACR;AAQO,MAAMC,IAAK,CACjBH,MACGI,MACe;AAClB,QAAM,CAACC,GAAO,GAAGC,CAAO,IAAIF;AAC5B,aAAWG,KAAQF,EAAM,MAAM,GAAG,EAAG,CAAAL,EAAG,iBAAiBO,GAAM,GAAGD,CAAO;AACzE,SAAO,MAAME,EAAIR,GAAI,GAAGI,CAAI;AAC7B,GAQaI,IAAM,CAClBR,MACGI,MACO;AACV,QAAM,CAACC,GAAO,GAAGC,CAAO,IAAIF;AAC5B,aAAWG,KAAQF,EAAM,MAAM,GAAG,EAAG,CAAAL,EAAG,oBAAoBO,GAAM,GAAGD,CAAO;AAC7E,GAcaG,IAAc,CAACjB,GAAakB,MAAmC;AAC3E,MA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AC/B,GAAKiC,CAAG,KAAK,OAAO,QAAQF,CAAK,EAAG,CAAAxB,EAAKC,GAAIR,GAAKiC,CAAG;AAC5E,SAAOzB;AACR,GAGa0B,IACZ,OAAO,cAAgB,MACnB,MAAM;AAAC,IACR,aAMSC,IAAgB,CAC5B1B,GACA2B,MAEA,CAACtC,OACD,OAAO,eAAe,IAAIW,CAAI,KAC9B,OAAO,eAAe,OAAOA,GAAM2B,CAAQ;"}
1
+ {"version":3,"file":"utils.js","sources":["../designsystem/utils.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport styles from \"./styles.module.css\";\n\nexport const QUICK_EVENT = { capture: true, passive: true };\nexport const isBrowser = () =>\n\ttypeof window !== \"undefined\" && typeof document !== \"undefined\"; // Using function to play nice with Vitest where DOM can come and go\n\nexport const getByCSSModule = (key: string) =>\n\tisBrowser() ? document.getElementsByClassName(styles[key].split(\" \")[0]) : [];\n\nexport function debounce<T extends unknown[]>(\n\tcallback: (...args: T) => void,\n\tdelay: number,\n) {\n\tlet timer: ReturnType<typeof setTimeout>;\n\n\treturn function (this: unknown, ...args: T) {\n\t\tclearTimeout(timer);\n\t\ttimer = setTimeout(() => callback.apply(this, args), delay);\n\t};\n}\n\n/**\n * attr\n * @description Utility to quickly get, set and remove attributes\n * @param el The Element to read/write attributes from\n * @param name The attribute name to get, set or remove, or a object to set multiple attributes\n * @param value A valid attribute value or null to remove attribute\n */\nexport const attr = (\n\tel: Element,\n\tname: string,\n\tvalue?: string | null,\n): string | null => {\n\tif (value === undefined) return el.getAttribute(name) ?? null; // Fallback to null only if el is undefined\n\tif (value === null) el.removeAttribute(name);\n\telse if (el.getAttribute(name) !== value) el.setAttribute(name, value);\n\treturn null;\n};\n\n/**\n * on\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\tel: Node | Window | ShadowRoot,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): (() => void) => {\n\tconst [types, ...options] = rest;\n\tfor (const type of types.split(\" \")) el.addEventListener(type, ...options);\n\treturn () => off(el, ...rest);\n};\n\n/**\n * off\n * @param el The Element to use as EventTarget\n * @param types A space separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\tel: Node | Window | ShadowRoot,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => {\n\tconst [types, ...options] = rest;\n\tfor (const type of types.split(\" \")) el.removeEventListener(type, ...options);\n};\n\ndeclare global {\n\tinterface Window {\n\t\t_mtdsHotReloadCleanup?: Map<string, Array<() => void>>;\n\t}\n}\n\n/**\n * onHotReload\n * @description Runs a callback when window is loaded in browser, and ensures cleanup when hot-reloading\n * @param key The key to identify setup and corresponding cleanup\n * @param callback The callback to run when the page is ready\n */\nexport const onHotReload = (key: string, setup: () => Array<() => void>) => {\n\tif (!isBrowser()) return; // Skip if not in modern browser environment, but on each call as Vitest might have unloaded jsdom between tests\n\tif (!window._mtdsHotReloadCleanup) window._mtdsHotReloadCleanup = new Map(); // Hot reload cleanup support supporting all build tools\n\n\tconst run = () => {\n\t\twindow._mtdsHotReloadCleanup?.get(key)?.map((cleanup) => cleanup()); // Run previous cleanup\n\t\twindow._mtdsHotReloadCleanup?.set(key, setup()); // Store new cleanup\n\t};\n\n\tif (document.readyState !== \"complete\") on(window, \"load\", run);\n\telse document.fonts?.ready?.then(run) || setTimeout(run, 0); // Prefer fonts ready promise if available, but fallback to setTimeout\n};\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport const onMutation = (\n\tel: Node,\n\tcallback: (observer: MutationObserver) => void,\n\toptions: MutationObserverInit,\n) => {\n\tlet queue = 0;\n\tconst onFrame = () => {\n\t\tif (!el.isConnected) return cleanup(); // Disconnect if element is removed from DOM\n\t\tcallback(observer);\n\t\tobserver.takeRecords(); // Clear records to avoid multiple triggers\n\t\tqueue = 0;\n\t};\n\tconst cleanup = () => observer?.disconnect?.();\n\tconst observer = new MutationObserver(() => {\n\t\tif (!queue) queue = requestAnimationFrame(onFrame); // requestAnimationFrame only runs when page is visible\n\t});\n\n\tobserver.observe(el, options);\n\tonFrame(); // Initial run\n\treturn cleanup;\n};\n\n/**\n * toCustomElementProps\n * @description Utility to quickly convert props to custom element attributes\n * @param props The props to convert\n * @returns The converted props\n */\nconst SELECTED = \"aria-selected\";\nexport const toCustomElementProps = <T extends Record<string, unknown>>(\n\trest: T,\n\tklass?: string,\n) =>\n\tObject.assign({}, rest, {\n\t\tsuppressHydrationWarning: true, // Make Next.js happy\n\t\t[SELECTED]:\n\t\t\trest[SELECTED] === undefined\n\t\t\t\t? undefined\n\t\t\t\t: (`${(rest[SELECTED] || \"false\") !== \"false\"}` as unknown as boolean), // Ensure aria-selected boolean is string\n\t\tclass: clsx(klass, rest.className as string), // Use class instead of className\n\t\thidden: !!rest.hidden, // Ensure boolean prop behaviour\n\t\topen: !!rest.open, // Ensure boolean prop behaviour\n\t});\n\n/**\n * tag\n * @description creates element and assigns properties\n * @param tagName The tagname of element to create\n * @param attrs Optional attributes to add to the element\n * @param text Optional text content to add to the element\n * @return HTMLElement with props\n */\nexport const tag = <TagName extends keyof HTMLElementTagNameMap>(\n\ttagName: TagName,\n\tattrs?: Record<string, string | null> | null,\n\ttext?: string | null,\n): HTMLElementTagNameMap[TagName] => {\n\tconst el = document.createElement(tagName);\n\tif (text) el.textContent = text;\n\tif (attrs) for (const [key, val] of Object.entries(attrs)) attr(el, key, val);\n\treturn el;\n};\n\n// Make sure we have a HTMLElement to extend (for server side rendering)\nexport const MTDSElement =\n\ttypeof HTMLElement === \"undefined\"\n\t\t? (class {} as typeof HTMLElement)\n\t\t: HTMLElement;\n\n/**\n * defineElement\n * @description Defines a customElement if running in browser and if not already registered\n */\nexport const defineElement = (\n\tname: string,\n\tinstance: CustomElementConstructor,\n) =>\n\t!isBrowser() ||\n\twindow.customElements.get(name) ||\n\twindow.customElements.define(name, instance);\n"],"names":["QUICK_EVENT","isBrowser","getByCSSModule","key","styles","debounce","callback","delay","timer","args","attr","el","name","value","on","rest","types","options","type","off","onHotReload","setup","run","cleanup","onMutation","queue","onFrame","observer","SELECTED","toCustomElementProps","klass","clsx","tag","tagName","attrs","text","val","MTDSElement","defineElement","instance"],"mappings":";;AAGO,MAAMA,IAAc,EAAE,SAAS,IAAM,SAAS,GAAA,GACxCC,IAAY,MACxB,OAAO,SAAW,OAAe,OAAO,WAAa,KAEzCC,IAAiB,CAACC,MAC9BF,EAAA,IAAc,SAAS,uBAAuBG,EAAOD,CAAG,EAAE,MAAM,GAAG,EAAE,CAAC,CAAC,IAAI,CAAA;AAErE,SAASE,EACfC,GACAC,GACC;AACD,MAAIC;AAEJ,SAAO,YAA4BC,GAAS;AAC3C,iBAAaD,CAAK,GAClBA,IAAQ,WAAW,MAAMF,EAAS,MAAM,MAAMG,CAAI,GAAGF,CAAK;AAAA,EAC3D;AACD;AASO,MAAMG,IAAO,CACnBC,GACAC,GACAC,MAEIA,MAAU,SAAkBF,EAAG,aAAaC,CAAI,KAAK,QACrDC,MAAU,OAAMF,EAAG,gBAAgBC,CAAI,IAClCD,EAAG,aAAaC,CAAI,MAAMC,KAAOF,EAAG,aAAaC,GAAMC,CAAK,GAC9D,OASKC,IAAK,CACjBH,MACGI,MACe;AAClB,QAAM,CAACC,GAAO,GAAGC,CAAO,IAAIF;AAC5B,aAAWG,KAAQF,EAAM,MAAM,GAAG,EAAG,CAAAL,EAAG,iBAAiBO,GAAM,GAAGD,CAAO;AACzE,SAAO,MAAME,EAAIR,GAAI,GAAGI,CAAI;AAC7B,GAQaI,IAAM,CAClBR,MACGI,MACO;AACV,QAAM,CAACC,GAAO,GAAGC,CAAO,IAAIF;AAC5B,aAAWG,KAAQF,EAAM,MAAM,GAAG,EAAG,CAAAL,EAAG,oBAAoBO,GAAM,GAAGD,CAAO;AAC7E,GAcaG,IAAc,CAACjB,GAAakB,MAAmC;AAC3E,MAAI,CAACpB,IAAa;AAClB,EAAK,OAAO,0BAAuB,OAAO,4CAA4B,IAAA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B,EAAKC,GAAIR,GAAKiC,CAAG;AAC5E,SAAOzB;AACR,GAGa0B,IACZ,OAAO,cAAgB,MACnB,MAAM;AAAC,IACR,aAMSC,IAAgB,CAC5B1B,GACA2B,MAEA,CAACtC,OACD,OAAO,eAAe,IAAIW,CAAI,KAC9B,OAAO,eAAe,OAAOA,GAAM2B,CAAQ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mattilsynet/design",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,24 +54,24 @@
54
54
  "storybook:build": "npm run build && storybook build"
55
55
  },
56
56
  "devDependencies": {
57
- "@biomejs/biome": "2.3.13",
57
+ "@biomejs/biome": "2.3.14",
58
58
  "@digdir/designsystemet-css": "^0.0.0-fix-designsystemet-web-20260128130007",
59
59
  "@digdir/designsystemet-types": "^0.0.0-fix-designsystemet-web-20260128130007",
60
60
  "@handsontable/react-wrapper": "^16.2.0",
61
61
  "@phosphor-icons/core": "^2.1.1",
62
62
  "@phosphor-icons/react": "^2.1.10",
63
- "@storybook/addon-docs": "^10.2.2",
64
- "@storybook/addon-themes": "^10.2.2",
65
- "@storybook/react-vite": "^10.2.2",
63
+ "@storybook/addon-docs": "^10.2.5",
64
+ "@storybook/addon-themes": "^10.2.5",
65
+ "@storybook/react-vite": "^10.2.5",
66
66
  "@tanstack/react-table": "^8.21.3",
67
67
  "@turf/boolean-point-in-polygon": "^7.3.3",
68
68
  "@turf/helpers": "^7.3.3",
69
69
  "@types/leaflet": "^1.9.21",
70
70
  "@types/leaflet.markercluster": "^1.5.6",
71
- "@types/node": "^25.1.0",
72
- "@types/react": "^19.2.10",
71
+ "@types/node": "^25.2.0",
72
+ "@types/react": "^19.2.11",
73
73
  "@types/react-dom": "^19.2.3",
74
- "@vitejs/plugin-react": "^5.1.2",
74
+ "@vitejs/plugin-react": "^5.1.3",
75
75
  "fast-glob": "^3.3.3",
76
76
  "handsontable": "^16.2.0",
77
77
  "leaflet": "^2.0.0-alpha.1",
@@ -80,7 +80,7 @@
80
80
  "react": "^19.2.4",
81
81
  "react-dom": "^19.2.4",
82
82
  "react-moveable": "^0.56.0",
83
- "storybook": "^10.2.2",
83
+ "storybook": "^10.2.5",
84
84
  "typescript": "^5.9.3",
85
85
  "vite": "^7.3.1",
86
86
  "vite-plugin-dts": "^4.5.4"