@mattilsynet/design 1.1.2 → 1.1.4

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.
Files changed (50) hide show
  1. package/mtds/app/app-observer.d.ts +0 -0
  2. package/mtds/app/app-observer.js +34 -0
  3. package/mtds/app/app-observer.js.map +1 -0
  4. package/mtds/app/app-toggle.js +12 -0
  5. package/mtds/app/app-toggle.js.map +1 -0
  6. package/mtds/app/app-toggle2.js +26 -0
  7. package/mtds/app/app-toggle2.js.map +1 -0
  8. package/mtds/app/app.d.ts +18 -0
  9. package/mtds/app/app.js +36 -0
  10. package/mtds/app/app.js.map +1 -0
  11. package/mtds/app/app.stories.d.ts +16 -0
  12. package/mtds/card/card.d.ts +1 -1
  13. package/mtds/card/card.js +3 -3
  14. package/mtds/card/card.js.map +1 -1
  15. package/mtds/divider/divider.d.ts +2 -2
  16. package/mtds/divider/divider.js.map +1 -1
  17. package/mtds/field/field-observer.js +26 -26
  18. package/mtds/field/field-observer.js.map +1 -1
  19. package/mtds/field/field.d.ts +2 -4
  20. package/mtds/field/field.js +44 -35
  21. package/mtds/field/field.js.map +1 -1
  22. package/mtds/field/field.stories.d.ts +1 -0
  23. package/mtds/index.d.ts +3 -1
  24. package/mtds/index.iife.js +5 -5
  25. package/mtds/index.js +6 -4
  26. package/mtds/index.js.map +1 -1
  27. package/mtds/layout/layout.d.ts +1 -7
  28. package/mtds/layout/layout.js +12 -15
  29. package/mtds/layout/layout.js.map +1 -1
  30. package/mtds/layout/layout.stories.d.ts +0 -1
  31. package/mtds/logo/logo-observer.js +9 -9
  32. package/mtds/logo/logo-observer.js.map +1 -1
  33. package/mtds/package.json.js +5 -0
  34. package/mtds/package.json.js.map +1 -0
  35. package/mtds/popover/popover-observer.js +13 -13
  36. package/mtds/popover/popover-observer.js.map +1 -1
  37. package/mtds/react.d.ts +1 -0
  38. package/mtds/react.js +60 -59
  39. package/mtds/react.js.map +1 -1
  40. package/mtds/styles.css +1 -1
  41. package/mtds/styles.json +36 -35
  42. package/mtds/styles.module.css.js +82 -80
  43. package/mtds/styles.module.css.js.map +1 -1
  44. package/mtds/tailwind.css +2 -0
  45. package/mtds/utils.js +35 -26
  46. package/mtds/utils.js.map +1 -1
  47. package/package.json +7 -7
  48. package/mtds/layout/app-observer.d.ts +0 -1
  49. package/mtds/layout/app-observer.js +0 -34
  50. package/mtds/layout/app-observer.js.map +0 -1
File without changes
@@ -0,0 +1,34 @@
1
+ import m from "../styles.module.css.js";
2
+ import { onLoaded as w, onMutation as C, on as c, QUICK_EVENT as p, debounce as T } from "../utils.js";
3
+ import "./app-toggle.js";
4
+ const f = m.app.split(" ")[0], P = m.sticky.split(" ")[0], _ = '[data-command="toggle-app-expanded"]', g = `.${f} > dialog,.${f} dialog ~ main`, h = (e) => {
5
+ document.startViewTransition ? document.startViewTransition(e) : e();
6
+ };
7
+ function E({ target: e }) {
8
+ e instanceof HTMLButtonElement && e.matches(_) && h(() => {
9
+ var l;
10
+ if (getComputedStyle(e).position === "sticky") (l = window.mtdsAppToggle) == null || l.call(window);
11
+ else {
12
+ const o = document.querySelector(g);
13
+ o == null || o.setAttribute("data-closedby", "any"), o == null || o.showModal();
14
+ }
15
+ });
16
+ }
17
+ function I() {
18
+ var e;
19
+ (e = document.querySelector(g)) == null || e.close();
20
+ }
21
+ let d = 0, s, n = 0, t, a = 0, r = 0, y = !1, u = 0, i = 0;
22
+ function H([e]) {
23
+ t = e, S();
24
+ }
25
+ function S() {
26
+ var o;
27
+ if (!(t != null && t.isConnected)) return;
28
+ const e = window.scrollY, l = e < i;
29
+ i = e, l !== s && (d = (((o = t.parentElement) == null ? void 0 : o.getBoundingClientRect().top) || 0) + i, s = l, a = t.offsetHeight, r = t.getBoundingClientRect().top + i, y = t.offsetHeight <= window.innerHeight, u = window.innerHeight), !(n === -1 && y) && (n !== -1 && (y || s && i <= r) ? (t.style.setProperty("--pos", "sticky"), t.style.setProperty("--top", "0px"), n = -1) : n === -1 && !s ? (t.style.setProperty("--pos", "relative"), t.style.setProperty("--top", `${Math.max(0, i - d)}px`), n = 0) : n !== 1 && !s && i + u >= r + a ? (t.style.setProperty("--pos", "sticky"), t.style.setProperty("--top", `${u - a}px`), n = 1) : n === 1 && s && (t.style.setProperty("--pos", "relative"), t.style.setProperty("--top", `${r - d}px`), n = 0));
30
+ }
31
+ w(() => {
32
+ C(document.documentElement, P, H), c(document, "click", E, p), c(window, "resize", T(I, 100), p), c(window, "scroll", S, p);
33
+ });
34
+ //# sourceMappingURL=app-observer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-observer.js","sources":["../../designsystem/app/app-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { QUICK_EVENT, debounce, on, onLoaded, onMutation } from \"../utils\";\nimport \"./app-toggle\";\n\nconst CSS_APP = styles.app.split(\" \")[0];\nconst CSS_STICKY = styles.sticky.split(\" \")[0];\nconst CSS_TOGGLE = '[data-command=\"toggle-app-expanded\"]';\nconst CSS_SIDEBAR = `.${CSS_APP} > dialog,.${CSS_APP} dialog ~ main`;\n\nconst useTransition = (callback: () => void) => {\n\tif (!document.startViewTransition) callback();\n\telse document.startViewTransition(callback);\n};\n\nfunction handleToggleClick({ target: el }: Event) {\n\tif (el instanceof HTMLButtonElement && el.matches(CSS_TOGGLE))\n\t\tuseTransition(() => {\n\t\t\t// @ts-expect-error window.mtdsAppToggle comes from app-toggle.js\n\t\t\tif (getComputedStyle(el).position === \"sticky\") window.mtdsAppToggle?.();\n\t\t\telse {\n\t\t\t\tconst sidebar = document.querySelector<HTMLDialogElement>(CSS_SIDEBAR);\n\t\t\t\tsidebar?.setAttribute(\"data-closedby\", \"any\"); // Allow closing by clicking outside\n\t\t\t\tsidebar?.showModal();\n\t\t\t}\n\t\t});\n}\n\nfunction handleResize() {\n\tdocument.querySelector<HTMLDialogElement>(CSS_SIDEBAR)?.close();\n}\n\n// Scroll state\nlet MIN_Y = 0; // Offset to avoid scroll jump when sticky is set to relative\nlet SCROLL_UP: boolean;\nlet STICK = 0; // -1 = stick top, 0 = relative, 1 = stick bottom\nlet STICK_EL: HTMLElement;\nlet STICK_H = 0;\nlet STICK_Y = 0;\nlet STUCK = false; // Used to figure if nav is larger than viewport\nlet WIN_H = 0;\nlet WIN_Y = 0;\n\nfunction handleMutation([sticky]: HTMLCollectionOf<HTMLElement>) {\n\tSTICK_EL = sticky;\n\thandleScroll(); // Run on connect\n}\n\nfunction handleScroll() {\n\tif (!STICK_EL?.isConnected) return;\n\tconst NEXT_Y = window.scrollY;\n\tconst NEXT_UP = NEXT_Y < WIN_Y;\n\tWIN_Y = NEXT_Y;\n\n\t// Only calculate if scroll direction has changed\n\tif (NEXT_UP !== SCROLL_UP) {\n\t\tMIN_Y = (STICK_EL.parentElement?.getBoundingClientRect().top || 0) + WIN_Y;\n\t\tSCROLL_UP = NEXT_UP;\n\t\tSTICK_H = STICK_EL.offsetHeight;\n\t\tSTICK_Y = STICK_EL.getBoundingClientRect().top + WIN_Y;\n\t\tSTUCK = STICK_EL.offsetHeight <= window.innerHeight;\n\t\tWIN_H = window.innerHeight;\n\t}\n\n\tif (STICK === -1 && STUCK) return; // Allways sticky when sidebar is smaller than viewport\n\tif (STICK !== -1 && (STUCK || (SCROLL_UP && WIN_Y <= STICK_Y))) {\n\t\tSTICK_EL.style.setProperty(\"--pos\", \"sticky\");\n\t\tSTICK_EL.style.setProperty(\"--top\", \"0px\");\n\t\tSTICK = -1; // Not sticking to top and sidebar is smaller than viewport or scrolling up\n\t} else if (STICK === -1 && !SCROLL_UP) {\n\t\tSTICK_EL.style.setProperty(\"--pos\", \"relative\");\n\t\tSTICK_EL.style.setProperty(\"--top\", `${Math.max(0, WIN_Y - MIN_Y)}px`);\n\t\tSTICK = 0; // Sticking to top and scrolling down\n\t} else if (STICK !== 1 && !SCROLL_UP && WIN_Y + WIN_H >= STICK_Y + STICK_H) {\n\t\tSTICK_EL.style.setProperty(\"--pos\", \"sticky\");\n\t\tSTICK_EL.style.setProperty(\"--top\", `${WIN_H - STICK_H}px`);\n\t\tSTICK = 1; // Not sticking to bottom and scrolling down\n\t} else if (STICK === 1 && SCROLL_UP) {\n\t\tSTICK_EL.style.setProperty(\"--pos\", \"relative\");\n\t\tSTICK_EL.style.setProperty(\"--top\", `${STICK_Y - MIN_Y}px`);\n\t\tSTICK = 0; // Sticking to bottom and scrolling up\n\t}\n}\n\nonLoaded(() => {\n\tonMutation(document.documentElement, CSS_STICKY, handleMutation);\n\ton(document, \"click\", handleToggleClick, QUICK_EVENT);\n\ton(window, \"resize\", debounce(handleResize, 100), QUICK_EVENT);\n\ton(window, \"scroll\", handleScroll, QUICK_EVENT);\n});\n"],"names":["CSS_APP","styles","CSS_STICKY","CSS_TOGGLE","CSS_SIDEBAR","useTransition","callback","handleToggleClick","el","sidebar","handleResize","_a","MIN_Y","SCROLL_UP","STICK","STICK_EL","STICK_H","STICK_Y","STUCK","WIN_H","WIN_Y","handleMutation","sticky","handleScroll","NEXT_Y","NEXT_UP","onLoaded","onMutation","on","QUICK_EVENT","debounce"],"mappings":";;;AAIA,MAAMA,IAAUC,EAAO,IAAI,MAAM,GAAG,EAAE,CAAC,GACjCC,IAAaD,EAAO,OAAO,MAAM,GAAG,EAAE,CAAC,GACvCE,IAAa,wCACbC,IAAc,IAAIJ,CAAO,cAAcA,CAAO,kBAE9CK,IAAgB,CAACC,MAAyB;AAC3C,EAAC,SAAS,sBACT,SAAS,oBAAoBA,CAAQ,IADEA,EAAA;AAE7C;AAEA,SAASC,EAAkB,EAAE,QAAQC,KAAa;AACjD,EAAIA,aAAc,qBAAqBA,EAAG,QAAQL,CAAU,KAC3DE,EAAc,MAAM;;AAEnB,QAAI,iBAAiBG,CAAE,EAAE,aAAa,sBAAiB;SAClD;AACE,YAAAC,IAAU,SAAS,cAAiCL,CAAW;AAC5D,MAAAK,KAAA,QAAAA,EAAA,aAAa,iBAAiB,QACvCA,KAAA,QAAAA,EAAS;AAAA,IAAU;AAAA,EACpB,CACA;AACH;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;AAEAY,EAAS,MAAM;AACH,EAAAC,EAAA,SAAS,iBAAiBzB,GAAYmB,CAAc,GAC5DO,EAAA,UAAU,SAASrB,GAAmBsB,CAAW,GACpDD,EAAG,QAAQ,UAAUE,EAASpB,GAAc,GAAG,GAAGmB,CAAW,GAC1DD,EAAA,QAAQ,UAAUL,GAAcM,CAAW;AAC/C,CAAC;"}
@@ -0,0 +1,12 @@
1
+ typeof window < "u" && window.CSSStyleSheet && document.adoptedStyleSheets && (() => {
2
+ const e = "--mtds-app-expanded", t = new CSSStyleSheet();
3
+ document.adoptedStyleSheets.push(t), window.mtdsAppToggle = (l = !0) => {
4
+ var d, n;
5
+ try {
6
+ const o = !((d = window.localStorage.getItem(e)) != null && d.includes("false")), S = l ? !o : o;
7
+ (n = t.replaceSync) == null || n.call(t, `:root { ${e}: var(${e}--${S})}`), window.localStorage.setItem(e, S);
8
+ } catch {
9
+ }
10
+ }, window.mtdsAppToggle(!1);
11
+ })();
12
+ //# sourceMappingURL=app-toggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-toggle.js","sources":["../../designsystem/app/app-toggle.js"],"sourcesContent":["if (\n\ttypeof window !== \"undefined\" &&\n\twindow.CSSStyleSheet &&\n\tdocument.adoptedStyleSheets\n)\n\t(() => {\n\t\tconst key = \"--mtds-app-expanded\";\n\t\tconst sheet = new CSSStyleSheet();\n\n\t\tdocument.adoptedStyleSheets.push(sheet);\n\t\twindow.mtdsAppToggle = (toggle = true) => {\n\t\t\ttry {\n\t\t\t\tconst prev = !window.localStorage.getItem(key)?.includes(\"false\");\n\t\t\t\tconst next = toggle ? !prev : prev;\n\n\t\t\t\tsheet.replaceSync?.(`:root { ${key}: var(${key}--${next})}`);\n\t\t\t\twindow.localStorage.setItem(key, next);\n\t\t\t} catch (err) {} // LocalStorage is full or replaceSync is not supported\n\t\t};\n\t\twindow.mtdsAppToggle(false); // Set and store initial state\n\t})();\n"],"names":["key","sheet","toggle","_a","_b","prev","next"],"mappings":"AACC,OAAO,SAAW,OAClB,OAAO,iBACP,SAAS,uBAER,MAAM;AACN,QAAMA,IAAM,uBACNC,IAAQ,IAAI,cAAe;AAEjC,WAAS,mBAAmB,KAAKA,CAAK,GACtC,OAAO,gBAAgB,CAACC,IAAS,OAAS;AAV5C,QAAAC,GAAAC;AAWG,QAAI;AACH,YAAMC,IAAO,GAACF,IAAA,OAAO,aAAa,QAAQH,CAAG,MAA/B,QAAAG,EAAkC,SAAS,WACnDG,IAAOJ,IAAS,CAACG,IAAOA;AAE9B,OAAAD,IAAAH,EAAM,gBAAN,QAAAG,EAAA,KAAAH,GAAoB,WAAWD,CAAG,SAASA,CAAG,KAAKM,CAAI,OACvD,OAAO,aAAa,QAAQN,GAAKM,CAAI;AAAA,IACzC,QAAiB;AAAA,IAAE;AAAA,EAChB,GACD,OAAO,cAAc,EAAK;AAC5B,GAAK;"}
@@ -0,0 +1,26 @@
1
+ const t = `if (
2
+ typeof window !== "undefined" &&
3
+ window.CSSStyleSheet &&
4
+ document.adoptedStyleSheets
5
+ )
6
+ (() => {
7
+ const key = "--mtds-app-expanded";
8
+ const sheet = new CSSStyleSheet();
9
+
10
+ document.adoptedStyleSheets.push(sheet);
11
+ window.mtdsAppToggle = (toggle = true) => {
12
+ try {
13
+ const prev = !window.localStorage.getItem(key)?.includes("false");
14
+ const next = toggle ? !prev : prev;
15
+
16
+ sheet.replaceSync?.(\`:root { \${key}: var(\${key}--\${next})}\`);
17
+ window.localStorage.setItem(key, next);
18
+ } catch (err) {} // LocalStorage is full or replaceSync is not supported
19
+ };
20
+ window.mtdsAppToggle(false); // Set and store initial state
21
+ })();
22
+ `;
23
+ export {
24
+ t as default
25
+ };
26
+ //# sourceMappingURL=app-toggle2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-toggle2.js","sources":["../../designsystem/app/app-toggle.js?raw"],"sourcesContent":["export default \"if (\\n\\ttypeof window !== \\\"undefined\\\" &&\\n\\twindow.CSSStyleSheet &&\\n\\tdocument.adoptedStyleSheets\\n)\\n\\t(() => {\\n\\t\\tconst key = \\\"--mtds-app-expanded\\\";\\n\\t\\tconst sheet = new CSSStyleSheet();\\n\\n\\t\\tdocument.adoptedStyleSheets.push(sheet);\\n\\t\\twindow.mtdsAppToggle = (toggle = true) => {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tconst prev = !window.localStorage.getItem(key)?.includes(\\\"false\\\");\\n\\t\\t\\t\\tconst next = toggle ? !prev : prev;\\n\\n\\t\\t\\t\\tsheet.replaceSync?.(`:root { ${key}: var(${key}--${next})}`);\\n\\t\\t\\t\\twindow.localStorage.setItem(key, next);\\n\\t\\t\\t} catch (err) {} // LocalStorage is full or replaceSync is not supported\\n\\t\\t};\\n\\t\\twindow.mtdsAppToggle(false); // Set and store initial state\\n\\t})();\\n\""],"names":["script"],"mappings":"AAAA,MAAeA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;"}
@@ -0,0 +1,18 @@
1
+ import { JSX } from 'react';
2
+ import { PolymorphicComponentPropWithRef } from '../react-types';
3
+ export type AppHeaderProps = React.ComponentPropsWithoutRef<"header">;
4
+ export type AppSidebarProps = React.ComponentPropsWithoutRef<"dialog">;
5
+ export type AppStickyProps = React.ComponentPropsWithoutRef<"div">;
6
+ export type AppMainProps = React.ComponentPropsWithoutRef<"main">;
7
+ export type AppFooterProps = React.ComponentPropsWithoutRef<"footer">;
8
+ export type AppProps<As extends React.ElementType = "div"> = PolymorphicComponentPropWithRef<As>;
9
+ type AppComponent = <As extends React.ElementType = "div">(props: AppProps<As>) => JSX.Element;
10
+ export declare const App: AppComponent & {
11
+ Header: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & React.RefAttributes<HTMLElement>>;
12
+ Sidebar: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.DialogHTMLAttributes<HTMLDialogElement>, HTMLDialogElement>, "ref"> & React.RefAttributes<HTMLDialogElement>>;
13
+ Sticky: AppComponent;
14
+ Main: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & React.RefAttributes<HTMLElement>>;
15
+ Footer: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & React.RefAttributes<HTMLElement>>;
16
+ Script: () => import("react/jsx-runtime").JSX.Element;
17
+ };
18
+ export {};
@@ -0,0 +1,36 @@
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import { clsx as a } from "../external/clsx/dist/clsx.js";
3
+ import { forwardRef as p } from "react";
4
+ import c from "../styles.module.css.js";
5
+ import m from "./app-toggle2.js";
6
+ const f = p(function({ as: r, className: t, ...n }, e) {
7
+ return /* @__PURE__ */ o(r || "div", { className: a(c.app, t), ref: e, ...n });
8
+ }), d = p(function({ as: r, className: t, ...n }, e) {
9
+ return /* @__PURE__ */ o(r || "div", { className: a(c.sticky, t), ref: e, ...n });
10
+ }), y = Object.assign(f, {
11
+ Header: p(
12
+ function(r, t) {
13
+ return /* @__PURE__ */ o("header", { ref: t, ...r });
14
+ }
15
+ ),
16
+ Sidebar: p(
17
+ function(r, t) {
18
+ return /* @__PURE__ */ o("dialog", { role: "navigation", ref: t, ...r });
19
+ }
20
+ ),
21
+ Sticky: d,
22
+ Main: p(function(r, t) {
23
+ return /* @__PURE__ */ o("main", { ref: t, ...r });
24
+ }),
25
+ Footer: p(
26
+ function(r, t) {
27
+ return /* @__PURE__ */ o("footer", { ref: t, ...r });
28
+ }
29
+ ),
30
+ // Needed to avoid flash of unstyled content and still be Next.js hydration compatible
31
+ Script: () => /* @__PURE__ */ o("script", { id: "mtds-app-script", children: m })
32
+ });
33
+ export {
34
+ y as App
35
+ };
36
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sources":["../../designsystem/app/app.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { type JSX, forwardRef } from \"react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport script from \"./app-toggle.js?raw\";\n\nexport type AppHeaderProps = React.ComponentPropsWithoutRef<\"header\">;\nexport type AppSidebarProps = React.ComponentPropsWithoutRef<\"dialog\">;\nexport type AppStickyProps = React.ComponentPropsWithoutRef<\"div\">;\nexport type AppMainProps = React.ComponentPropsWithoutRef<\"main\">;\nexport type AppFooterProps = React.ComponentPropsWithoutRef<\"footer\">;\nexport type AppProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As>;\n\ntype AppComponent = <As extends React.ElementType = \"div\">(\n\tprops: AppProps<As>,\n) => JSX.Element;\n\nconst AppComp = forwardRef<null>(function App<\n\tAs extends React.ElementType = \"div\",\n>({ as, className, ...rest }: AppProps<As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || \"div\";\n\n\treturn <Tag className={clsx(styles.app, className)} ref={ref} {...rest} />;\n}) as AppComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nconst AppSticky = forwardRef<null>(function App<\n\tAs extends React.ElementType = \"div\",\n>({ as, className, ...rest }: AppProps<As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || \"div\";\n\n\treturn <Tag className={clsx(styles.sticky, className)} ref={ref} {...rest} />;\n}) as AppComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport const App = Object.assign(AppComp, {\n\tHeader: forwardRef<HTMLElement, AppHeaderProps>(\n\t\tfunction AppHeader(rest, ref) {\n\t\t\treturn <header ref={ref} {...rest} />;\n\t\t},\n\t),\n\tSidebar: forwardRef<HTMLDialogElement, AppSidebarProps>(\n\t\tfunction AppSidebar(rest, ref) {\n\t\t\treturn <dialog role=\"navigation\" ref={ref} {...rest} />;\n\t\t},\n\t),\n\tSticky: AppSticky,\n\tMain: forwardRef<HTMLElement, AppMainProps>(function AppMain(rest, ref) {\n\t\treturn <main ref={ref} {...rest} />;\n\t}),\n\tFooter: forwardRef<HTMLElement, AppFooterProps>(\n\t\tfunction AppFooter(rest, ref) {\n\t\t\treturn <footer ref={ref} {...rest} />;\n\t\t},\n\t),\n\t// Needed to avoid flash of unstyled content and still be Next.js hydration compatible\n\tScript: () => <script id=\"mtds-app-script\">{script}</script>,\n});\n"],"names":["AppComp","forwardRef","as","className","rest","ref","jsx","clsx","styles","AppSticky","App","script"],"mappings":";;;;;AAqBA,MAAMA,IAAUC,EAAiB,SAE/B,EAAE,IAAAC,GAAI,WAAAC,GAAW,GAAGC,EAAK,GAAiBC,GAA0B;AAG9D,SAAA,gBAAAC,EAFKJ,KAAM,OAEN,EAAA,WAAWK,EAAKC,EAAO,KAAKL,CAAS,GAAG,KAAAE,GAAW,GAAGD,EAAM,CAAA;AACzE,CAAC,GAEKK,IAAYR,EAAiB,SAEjC,EAAE,IAAAC,GAAI,WAAAC,GAAW,GAAGC,EAAK,GAAiBC,GAA0B;AAG9D,SAAA,gBAAAC,EAFKJ,KAAM,OAEN,EAAA,WAAWK,EAAKC,EAAO,QAAQL,CAAS,GAAG,KAAAE,GAAW,GAAGD,EAAM,CAAA;AAC5E,CAAC,GAEYM,IAAM,OAAO,OAAOV,GAAS;AAAA,EACzC,QAAQC;AAAA,IACP,SAAmBG,GAAMC,GAAK;AAC7B,aAAQ,gBAAAC,EAAA,UAAA,EAAO,KAAAD,GAAW,GAAGD,EAAM,CAAA;AAAA,IAAA;AAAA,EAErC;AAAA,EACA,SAASH;AAAA,IACR,SAAoBG,GAAMC,GAAK;AAC9B,+BAAQ,UAAO,EAAA,MAAK,cAAa,KAAAA,GAAW,GAAGD,GAAM;AAAA,IAAA;AAAA,EAEvD;AAAA,EACA,QAAQK;AAAA,EACR,MAAMR,EAAsC,SAAiBG,GAAMC,GAAK;AACvE,WAAQ,gBAAAC,EAAA,QAAA,EAAK,KAAAD,GAAW,GAAGD,EAAM,CAAA;AAAA,EAAA,CACjC;AAAA,EACD,QAAQH;AAAA,IACP,SAAmBG,GAAMC,GAAK;AAC7B,aAAQ,gBAAAC,EAAA,UAAA,EAAO,KAAAD,GAAW,GAAGD,EAAM,CAAA;AAAA,IAAA;AAAA,EAErC;AAAA;AAAA,EAEA,QAAQ,MAAM,gBAAAE,EAAC,UAAO,EAAA,IAAG,mBAAmB,UAAOK,EAAA,CAAA;AACpD,CAAC;"}
@@ -0,0 +1,16 @@
1
+ import { StoryObj } from '@storybook/react';
2
+ declare const meta: {
3
+ title: string;
4
+ parameters: {
5
+ layout: string;
6
+ };
7
+ decorators: ((Story: import('@storybook/core/csf').PartialStoryFn<import('@storybook/react').ReactRenderer, {
8
+ [x: string]: any;
9
+ }>) => import("react/jsx-runtime").JSX.Element)[];
10
+ };
11
+ export default meta;
12
+ type Story = StoryObj<typeof meta>;
13
+ export declare const Default: Story;
14
+ export declare const React: Story;
15
+ export declare const WithFooter: Story;
16
+ export declare const WithComplexContent: Story;
@@ -5,8 +5,8 @@ type CardBaseProps<Href> = {
5
5
  };
6
6
  export type CardProps<Href, As extends React.ElementType = Href extends string ? "a" : "div"> = PolymorphicComponentPropWithRef<As, CardBaseProps<Href>>;
7
7
  type CardComponent = <Href, As extends React.ElementType = Href extends string ? "a" : "div">(props: CardProps<Href, As>) => JSX.Element;
8
+ export declare const Card: CardComponent;
8
9
  export type GroupProps<As extends React.ElementType = "div"> = PolymorphicComponentPropWithRef<As>;
9
10
  type GroupComponent = <As extends React.ElementType = "div">(props: GroupProps<As>) => JSX.Element;
10
11
  export declare const Group: GroupComponent;
11
- export declare const Card: CardComponent;
12
12
  export {};
package/mtds/card/card.js CHANGED
@@ -2,14 +2,14 @@ import { jsx as c } from "react/jsx-runtime";
2
2
  import { clsx as m } from "../external/clsx/dist/clsx.js";
3
3
  import { forwardRef as n } from "react";
4
4
  import f from "../styles.module.css.js";
5
- const i = n(function({ as: o, className: t, ...r }, a) {
5
+ const g = n(function({ as: o, className: t, ...r }, a) {
6
6
  const s = o || (r.href ? "a" : "div");
7
7
  return /* @__PURE__ */ c(s, { className: m(f.card, t), ref: a, ...r });
8
8
  }), l = n(function({ as: o, className: t, ...r }, a) {
9
9
  return /* @__PURE__ */ c(o || "div", { className: m(f.group, t), ref: a, ...r });
10
- }), C = i;
10
+ });
11
11
  export {
12
- C as Card,
12
+ g as Card,
13
13
  l as Group
14
14
  };
15
15
  //# sourceMappingURL=card.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"card.js","sources":["../../designsystem/card/card.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { type JSX, forwardRef } from \"react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\n\ntype CardBaseProps<Href> = {\n\thref?: Href;\n};\n\nexport type CardProps<\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n> = PolymorphicComponentPropWithRef<As, CardBaseProps<Href>>;\n\ntype CardComponent = <\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n>(\n\tprops: CardProps<Href, As>,\n) => JSX.Element;\n\nconst CardComp: CardComponent = forwardRef<null>(function Card<\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n>({ as, className, ...rest }: CardProps<Href, As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || (rest.href ? \"a\" : \"div\");\n\n\treturn <Tag className={clsx(styles.card, className)} ref={ref} {...rest} />;\n}) as CardComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport type GroupProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As>;\n\ntype GroupComponent = <As extends React.ElementType = \"div\">(\n\tprops: GroupProps<As>,\n) => JSX.Element;\n\nexport const Group: GroupComponent = forwardRef<null>(function Group<\n\tAs extends React.ElementType = \"div\",\n>({ as, className, ...rest }: GroupProps<As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || \"div\";\n\n\treturn <Tag className={clsx(styles.group, className)} ref={ref} {...rest} />;\n}) as GroupComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\n// export type CardDetailsProps = React.ComponentPropsWithoutRef<\"details\">;\n// const CardDetails = forwardRef<HTMLDetailsElement, CardDetailsProps>(\n// \tfunction CardDetails({ className, ...rest }, ref) {\n// \t\treturn (\n// \t\t\t<u-details class={clsx(styles.card, className)} ref={ref} {...rest} />\n// \t\t);\n// \t},\n// );\n\n// export type CardSummaryProps = React.ComponentPropsWithoutRef<\"summary\">;\n// const CardSummary = forwardRef<HTMLElement, CardSummaryProps>(\n// \tfunction CardSummary({ className, ...rest }, ref) {\n// \t\treturn <u-summary class={className} ref={ref} {...rest} />;\n// \t},\n// );\n\nexport const Card = CardComp;\n"],"names":["CardComp","forwardRef","as","className","rest","ref","Tag","jsx","clsx","styles","Group","Card"],"mappings":";;;;AAwBA,MAAMA,IAA0BC,EAAiB,SAG/C,EAAE,IAAAC,GAAI,WAAAC,GAAW,GAAGC,EAAK,GAAwBC,GAA0B;AAC5E,QAAMC,IAAMJ,MAAOE,EAAK,OAAO,MAAM;AAE9B,SAAA,gBAAAG,EAACD,GAAI,EAAA,WAAWE,EAAKC,EAAO,MAAMN,CAAS,GAAG,KAAAE,GAAW,GAAGD,EAAM,CAAA;AAC1E,CAAC,GASYM,IAAwBT,EAAiB,SAEpD,EAAE,IAAAC,GAAI,WAAAC,GAAW,GAAGC,EAAK,GAAmBC,GAA0B;AAGhE,SAAA,gBAAAE,EAFKL,KAAM,OAEN,EAAA,WAAWM,EAAKC,EAAO,OAAON,CAAS,GAAG,KAAAE,GAAW,GAAGD,EAAM,CAAA;AAC3E,CAAC,GAkBYO,IAAOX;"}
1
+ {"version":3,"file":"card.js","sources":["../../designsystem/card/card.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { type JSX, forwardRef } from \"react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\n\ntype CardBaseProps<Href> = {\n\thref?: Href;\n};\n\nexport type CardProps<\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n> = PolymorphicComponentPropWithRef<As, CardBaseProps<Href>>;\n\ntype CardComponent = <\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n>(\n\tprops: CardProps<Href, As>,\n) => JSX.Element;\n\nexport const Card: CardComponent = forwardRef<null>(function Card<\n\tHref,\n\tAs extends React.ElementType = Href extends string ? \"a\" : \"div\",\n>({ as, className, ...rest }: CardProps<Href, As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || (rest.href ? \"a\" : \"div\");\n\n\treturn <Tag className={clsx(styles.card, className)} ref={ref} {...rest} />;\n}) as CardComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n\nexport type GroupProps<As extends React.ElementType = \"div\"> =\n\tPolymorphicComponentPropWithRef<As>;\n\ntype GroupComponent = <As extends React.ElementType = \"div\">(\n\tprops: GroupProps<As>,\n) => JSX.Element;\n\nexport const Group: GroupComponent = forwardRef<null>(function Group<\n\tAs extends React.ElementType = \"div\",\n>({ as, className, ...rest }: GroupProps<As>, ref?: PolymorphicRef<As>) {\n\tconst Tag = as || \"div\";\n\n\treturn <Tag className={clsx(styles.group, className)} ref={ref} {...rest} />;\n}) as GroupComponent; // Needed to tell Typescript this does not return ReactNode but acutally JSX.Element\n"],"names":["Card","forwardRef","as","className","rest","ref","Tag","jsx","clsx","styles","Group"],"mappings":";;;;AAwBa,MAAAA,IAAsBC,EAAiB,SAGlD,EAAE,IAAAC,GAAI,WAAAC,GAAW,GAAGC,EAAK,GAAwBC,GAA0B;AAC5E,QAAMC,IAAMJ,MAAOE,EAAK,OAAO,MAAM;AAE9B,SAAA,gBAAAG,EAACD,GAAI,EAAA,WAAWE,EAAKC,EAAO,MAAMN,CAAS,GAAG,KAAAE,GAAW,GAAGD,EAAM,CAAA;AAC1E,CAAC,GASYM,IAAwBT,EAAiB,SAEpD,EAAE,IAAAC,GAAI,WAAAC,GAAW,GAAGC,EAAK,GAAmBC,GAA0B;AAGhE,SAAA,gBAAAE,EAFKL,KAAM,OAEN,EAAA,WAAWM,EAAKC,EAAO,OAAON,CAAS,GAAG,KAAAE,GAAW,GAAGD,EAAM,CAAA;AAC3E,CAAC;"}
@@ -1,6 +1,6 @@
1
1
  export type DividerProps = React.ComponentPropsWithoutRef<"hr"> & {
2
- "data-gap"?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "18" | "22" | "26" | "30" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 22 | 26 | 30 | "none" | "sm" | "md" | "lg" | "xl";
2
+ "data-gap"?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "18" | "22" | "26" | "30" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 22 | 26 | 30 | "none" | "xs" | "sm" | "md" | "lg" | "xl";
3
3
  };
4
4
  export declare const Divider: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLHRElement>, HTMLHRElement>, "ref"> & {
5
- "data-gap"?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "18" | "22" | "26" | "30" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 22 | 26 | 30 | "none" | "sm" | "md" | "lg" | "xl";
5
+ "data-gap"?: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "18" | "22" | "26" | "30" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 22 | 26 | 30 | "none" | "xs" | "sm" | "md" | "lg" | "xl";
6
6
  } & React.RefAttributes<HTMLHRElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"divider.js","sources":["../../designsystem/divider/divider.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef } from \"react\";\nimport styles from \"../styles.module.css\";\n\nexport type DividerProps = React.ComponentPropsWithoutRef<\"hr\"> & {\n\t\"data-gap\"?:\n\t\t| \"0\"\n\t\t| \"1\"\n\t\t| \"2\"\n\t\t| \"3\"\n\t\t| \"4\"\n\t\t| \"5\"\n\t\t| \"6\"\n\t\t| \"7\"\n\t\t| \"8\"\n\t\t| \"9\"\n\t\t| \"10\"\n\t\t| \"11\"\n\t\t| \"12\"\n\t\t| \"13\"\n\t\t| \"14\"\n\t\t| \"15\"\n\t\t| \"18\"\n\t\t| \"22\"\n\t\t| \"26\"\n\t\t| \"30\"\n\t\t| 0\n\t\t| 1\n\t\t| 2\n\t\t| 3\n\t\t| 4\n\t\t| 5\n\t\t| 6\n\t\t| 7\n\t\t| 8\n\t\t| 9\n\t\t| 10\n\t\t| 11\n\t\t| 12\n\t\t| 13\n\t\t| 14\n\t\t| 15\n\t\t| 18\n\t\t| 22\n\t\t| 26\n\t\t| 30\n\t\t// Backwards compatibility:\n\t\t| \"none\"\n\t\t| \"sm\"\n\t\t| \"md\"\n\t\t| \"lg\"\n\t\t| \"xl\";\n};\n\nexport const Divider = forwardRef<HTMLHRElement, DividerProps>(function Divider(\n\t{ className, ...rest },\n\tref,\n) {\n\treturn (\n\t\t// biome-ignore lint/a11y/noAriaHiddenOnFocusable: This is a decorative element\n\t\t<hr\n\t\t\taria-hidden=\"true\"\n\t\t\tclassName={clsx(styles.divider, className)}\n\t\t\tref={ref}\n\t\t\t{...rest}\n\t\t/>\n\t);\n});\n"],"names":["Divider","forwardRef","className","rest","ref","jsx","clsx","styles"],"mappings":";;;;AAsDa,MAAAA,IAAUC,EAAwC,SAC9D,EAAE,WAAAC,GAAW,GAAGC,EAAK,GACrBC,GACC;AACD;AAAA;AAAA,IAEC,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACA,eAAY;AAAA,QACZ,WAAWC,EAAKC,EAAO,SAASL,CAAS;AAAA,QACzC,KAAAE;AAAA,QACC,GAAGD;AAAA,MAAA;AAAA,IAAA;AAAA;AAGP,CAAC;"}
1
+ {"version":3,"file":"divider.js","sources":["../../designsystem/divider/divider.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { forwardRef } from \"react\";\nimport styles from \"../styles.module.css\";\n\nexport type DividerProps = React.ComponentPropsWithoutRef<\"hr\"> & {\n\t\"data-gap\"?:\n\t\t| \"0\"\n\t\t| \"1\"\n\t\t| \"2\"\n\t\t| \"3\"\n\t\t| \"4\"\n\t\t| \"5\"\n\t\t| \"6\"\n\t\t| \"7\"\n\t\t| \"8\"\n\t\t| \"9\"\n\t\t| \"10\"\n\t\t| \"11\"\n\t\t| \"12\"\n\t\t| \"13\"\n\t\t| \"14\"\n\t\t| \"15\"\n\t\t| \"18\"\n\t\t| \"22\"\n\t\t| \"26\"\n\t\t| \"30\"\n\t\t| 0\n\t\t| 1\n\t\t| 2\n\t\t| 3\n\t\t| 4\n\t\t| 5\n\t\t| 6\n\t\t| 7\n\t\t| 8\n\t\t| 9\n\t\t| 10\n\t\t| 11\n\t\t| 12\n\t\t| 13\n\t\t| 14\n\t\t| 15\n\t\t| 18\n\t\t| 22\n\t\t| 26\n\t\t| 30\n\t\t// Backwards compatibility:\n\t\t| \"none\"\n\t\t| \"xs\"\n\t\t| \"sm\"\n\t\t| \"md\"\n\t\t| \"lg\"\n\t\t| \"xl\";\n};\n\nexport const Divider = forwardRef<HTMLHRElement, DividerProps>(function Divider(\n\t{ className, ...rest },\n\tref,\n) {\n\treturn (\n\t\t// biome-ignore lint/a11y/noAriaHiddenOnFocusable: This is a decorative element\n\t\t<hr\n\t\t\taria-hidden=\"true\"\n\t\t\tclassName={clsx(styles.divider, className)}\n\t\t\tref={ref}\n\t\t\t{...rest}\n\t\t/>\n\t);\n});\n"],"names":["Divider","forwardRef","className","rest","ref","jsx","clsx","styles"],"mappings":";;;;AAuDa,MAAAA,IAAUC,EAAwC,SAC9D,EAAE,WAAAC,GAAW,GAAGC,EAAK,GACrBC,GACC;AACD;AAAA;AAAA,IAEC,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACA,eAAY;AAAA,QACZ,WAAWC,EAAKC,EAAO,SAASL,CAAS;AAAA,QACzC,KAAAE;AAAA,QACC,GAAGD;AAAA,MAAA;AAAA,IAAA;AAAA;AAGP,CAAC;"}
@@ -1,17 +1,17 @@
1
1
  import { UHTMLDataListElement as L } from "../external/@u-elements/u-datalist/dist/u-datalist.js";
2
2
  import u from "../styles.module.css.js";
3
- import { onLoaded as I, onMutation as T, on as f, QUICK_EVENT as C, isInputLike as m, attr as s, useId as d } from "../utils.js";
4
- const g = u.field.split(" ")[0], P = "--mtds-text-count-over", b = "--mtds-text-count-under", p = u.validation.split(" "), x = p[0];
3
+ import { onLoaded as I, onMutation as T, on as f, QUICK_EVENT as C, isInputLike as m, attr as a, useId as c } from "../utils.js";
4
+ const g = u.field.split(" ")[0], b = "--mtds-text-count-over", P = "--mtds-text-count-under", p = u.validation.split(" "), x = p[0];
5
5
  function _(t) {
6
6
  for (const e of t)
7
7
  if (e.isConnected) {
8
- const l = [], a = [];
9
- let n = null, i = null, r = !0;
10
- for (const o of e.getElementsByTagName("*"))
11
- o instanceof HTMLLabelElement ? l.push(o) : o instanceof L ? i = o : m(o) ? n = o : o.classList.contains(x) ? (r = s(o, "data-color") === "success" || !o.clientWidth || !o.clientHeight, a.unshift(d(o))) : o instanceof HTMLParagraphElement && a.push(d(o));
12
- if (n) {
13
- for (const o of l) o.htmlFor = d(n);
14
- D(n, i), v(n), h(n), s(n, "aria-describedby", a.join(" ") || null), s(n, "aria-invalid", `${!r}`);
8
+ const i = [], n = [];
9
+ let o = null, l = null, r = !0;
10
+ for (const s of e.getElementsByTagName("*"))
11
+ s instanceof HTMLLabelElement ? i.push(s) : s instanceof L ? o = s : m(s) ? l = s : s.hasAttribute("data-description") ? n.push(s) : s.classList.contains(x) ? (r = a(s, "data-color") === "success" || !s.clientWidth || !s.clientHeight, n.unshift(s)) : s instanceof HTMLParagraphElement && (n.some((d) => d.contains(s)) || n.push(s));
12
+ if (l) {
13
+ for (const s of i) s.htmlFor = c(l);
14
+ A(l, o), v(l), h(l), a(l, "aria-describedby", n.map(c).join(" ") || null), a(l, "aria-invalid", `${!r}`);
15
15
  }
16
16
  }
17
17
  }
@@ -21,35 +21,35 @@ function h(t) {
21
21
  `${t.scrollHeight}px`
22
22
  ));
23
23
  }
24
- function D(t, e) {
25
- if (s(t, "list", e ? d(e) : null), !e) return;
26
- t.hasAttribute("placeholder") || s(t, "placeholder", "");
27
- const l = window.getComputedStyle(e), a = t.closest("u-tags"), n = (i) => l.getPropertyValue(`--mtds-text-${i}`);
28
- s(e, "data-sr-plural", n("datalist-plural")), s(e, "data-sr-singular", n("datalist-singular")), a && (s(a, "data-sr-added", n("tags-added")), s(a, "data-sr-empty", n("tags-empty")), s(a, "data-sr-found", n("tags-found")), s(a, "data-sr-of", n("tags-of")), s(a, "data-sr-remove", n("tags-remove")), s(a, "data-sr-removed", n("tags-removed")));
24
+ function A(t, e) {
25
+ if (a(t, "list", e ? c(e) : null), !e) return;
26
+ t.hasAttribute("placeholder") || a(t, "placeholder", "");
27
+ const i = window.getComputedStyle(e), n = t.closest("u-tags"), o = (l) => i.getPropertyValue(`--mtds-text-${l}`);
28
+ a(e, "data-sr-plural", o("datalist-plural")), a(e, "data-sr-singular", o("datalist-singular")), n && (a(n, "data-sr-added", o("tags-added")), a(n, "data-sr-empty", o("tags-empty")), a(n, "data-sr-found", o("tags-found")), a(n, "data-sr-of", o("tags-of")), a(n, "data-sr-remove", o("tags-remove")), a(n, "data-sr-removed", o("tags-removed")));
29
29
  }
30
30
  function v(t) {
31
- var a, n;
32
- const e = t == null ? void 0 : t.nextElementSibling, l = e && s(e, "data-count");
33
- if (e && l) {
34
- const i = Number(l) - t.value.length, r = i < 0, o = s(e, "aria-live") === "polite", c = window.getComputedStyle(e || t), y = ((a = c.getPropertyValue(P)) == null ? void 0 : a.slice(1, -1)) || "", S = ((n = c.getPropertyValue(b)) == null ? void 0 : n.slice(1, -1)) || "";
35
- if (o !== r) {
36
- s(e, "aria-live", r ? "polite" : "off");
31
+ var n, o;
32
+ const e = t == null ? void 0 : t.nextElementSibling, i = e && a(e, "data-count");
33
+ if (e && i) {
34
+ const l = Number(i) - t.value.length, r = l < 0, s = a(e, "aria-live") === "polite", d = window.getComputedStyle(e || t), y = ((n = d.getPropertyValue(b)) == null ? void 0 : n.slice(1, -1)) || "", S = ((o = d.getPropertyValue(P)) == null ? void 0 : o.slice(1, -1)) || "";
35
+ if (s !== r) {
36
+ a(e, "aria-live", r ? "polite" : "off");
37
37
  for (const E of p) e.classList.toggle(E, r);
38
38
  }
39
39
  e.textContent = (r ? y : S).replace(
40
40
  "%d",
41
- `${Math.abs(i)}`
41
+ `${Math.abs(l)}`
42
42
  );
43
43
  }
44
44
  }
45
- function M({ target: t }) {
45
+ function D({ target: t }) {
46
46
  m(t) && (v(t), h(t));
47
47
  }
48
- function V(t) {
49
- var e, l;
50
- (l = (e = t.target) == null ? void 0 : e.closest) != null && l.call(e, `.${g}`) && t.preventDefault();
48
+ function M(t) {
49
+ var e, i;
50
+ (i = (e = t.target) == null ? void 0 : e.closest) != null && i.call(e, `.${g}`) && t.preventDefault();
51
51
  }
52
52
  I(() => {
53
- T(document.documentElement, g, _), f(document, "input", M, C), f(document, "invalid", V, !0);
53
+ T(document.documentElement, g, _), f(document, "input", D, C), f(document, "invalid", M, !0);
54
54
  });
55
55
  //# sourceMappingURL=field-observer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"field-observer.js","sources":["../../designsystem/field/field-observer.ts"],"sourcesContent":["import { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\tQUICK_EVENT,\n\tattr,\n\tisInputLike,\n\ton,\n\tonLoaded,\n\tonMutation,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELD = styles.field.split(\" \")[0];\nconst CSS_PROPERTY_OVER = \"--mtds-text-count-over\";\nconst CSS_PROPERTY_UNDER = \"--mtds-text-count-under\";\nconst CSS_VALIDATIONS = styles.validation.split(\" \");\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\n\nfunction handleMutation(fields: HTMLCollectionOf<Element>) {\n\tfor (const field of fields)\n\t\tif (field.isConnected) {\n\t\t\tconst labels: HTMLLabelElement[] = [];\n\t\t\tconst descs: string[] = [];\n\t\t\tlet input: HTMLInputElement | null = null;\n\t\t\tlet datalist: UHTMLDataListElement | 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 UHTMLDataListElement) datalist = el;\n\t\t\t\telse if (isInputLike(el)) input = el;\n\t\t\t\telse if (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t\t// Must be before instanceof HTMLParagraphElement since validation can also be a <p>\n\t\t\t\t\tvalid =\n\t\t\t\t\t\tattr(el, \"data-color\") === \"success\" ||\n\t\t\t\t\t\t!el.clientWidth ||\n\t\t\t\t\t\t!el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\t\tdescs.unshift(useId(el));\n\t\t\t\t} else if (el instanceof HTMLParagraphElement) descs.push(useId(el));\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\trenderDatalist(input, datalist);\n\t\t\t\trenderCounter(input);\n\t\t\t\trenderTextareaSize(input);\n\t\t\t\tattr(input, \"aria-describedby\", descs.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\nfunction renderDatalist(\n\tinput: HTMLInputElement,\n\tlist?: UHTMLDataListElement | null,\n) {\n\tattr(input, \"list\", list ? useId(list) : null);\n\n\tif (!list) return;\n\tif (!input.hasAttribute(\"placeholder\")) attr(input, \"placeholder\", \"\"); // Needed to render dropdown chevron when <datalist> is present\n\n\t// Setup translations from CSS custom properties\n\tconst style = window.getComputedStyle(list);\n\tconst tags = input.closest(\"u-tags\");\n\tconst i11n = (key: string) => style.getPropertyValue(`--mtds-text-${key}`);\n\n\tattr(list, \"data-sr-plural\", i11n(\"datalist-plural\"));\n\tattr(list, \"data-sr-singular\", i11n(\"datalist-singular\"));\n\n\tif (tags) {\n\t\tattr(tags, \"data-sr-added\", i11n(\"tags-added\"));\n\t\tattr(tags, \"data-sr-empty\", i11n(\"tags-empty\"));\n\t\tattr(tags, \"data-sr-found\", i11n(\"tags-found\"));\n\t\tattr(tags, \"data-sr-of\", i11n(\"tags-of\"));\n\t\tattr(tags, \"data-sr-remove\", i11n(\"tags-remove\"));\n\t\tattr(tags, \"data-sr-removed\", i11n(\"tags-removed\"));\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 = style.getPropertyValue(CSS_PROPERTY_OVER)?.slice(1, -1) || \"\"; // slice to trim quotes\n\t\tconst under =\n\t\t\tstyle.getPropertyValue(CSS_PROPERTY_UNDER)?.slice(1, -1) || \"\"; // slice to trim quotes\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\n// Update when typing\nfunction handleInput({ target }: Event) {\n\tif (isInputLike(target)) {\n\t\trenderCounter(target);\n\t\trenderTextareaSize(target);\n\n\t\t// const input = event.target;\n\t\t// const list = input.list;\n\t\t// if (list) {\n\t\t// console.log('etterpå');\n\t\t// if (isDatalistClick(event)) return; // User clicked option element\n\t\t// if (attr(list, 'data-filter') === 'false') syncDatalistState(input); // Allow custom filtering\n\t\t// }\n\t}\n}\n\n// Prevent browsers from showing default validation bubbles\nfunction handleInvalid(event: Event) {\n\tif ((event.target as Element)?.closest?.(`.${CSS_FIELD}`))\n\t\tevent.preventDefault();\n}\n\nonLoaded(() => {\n\tonMutation(document.documentElement, CSS_FIELD, handleMutation);\n\ton(document, \"input\", handleInput, QUICK_EVENT);\n\ton(document, \"invalid\", handleInvalid, true); // Use capture as invalid does noe buttle\n});\n"],"names":["CSS_FIELD","styles","CSS_PROPERTY_OVER","CSS_PROPERTY_UNDER","CSS_VALIDATIONS","CSS_VALIDATION","handleMutation","fields","field","labels","descs","input","datalist","valid","el","UHTMLDataListElement","isInputLike","attr","useId","label","renderDatalist","renderCounter","renderTextareaSize","textarea","list","style","tags","i11n","key","limit","remainder","nextInvalid","prevInvalid","over","_a","under","_b","css","handleInput","target","handleInvalid","event","onLoaded","onMutation","on","QUICK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ACpD,iBAAWM,KAAOjC,EAAiB,CAAAU,EAAG,UAAU,OAAOuB,GAAKN,CAAW;AAAA,IAAA;AAErE,IAAAjB,EAAA,eAAeiB,IAAcE,IAAOE,GAAO;AAAA,MAC7C;AAAA,MACA,GAAG,KAAK,IAAIL,CAAS,CAAC;AAAA,IACvB;AAAA,EAAA;AAEF;AAGA,SAASQ,EAAY,EAAE,QAAAC,KAAiB;AACnC,EAAAvB,EAAYuB,CAAM,MACrBlB,EAAckB,CAAM,GACpBjB,EAAmBiB,CAAM;AAU3B;AAGA,SAASC,EAAcC,GAAc;;AACpC,GAAKL,KAAAF,IAAAO,EAAM,WAAN,gBAAAP,EAA0B,YAA1B,QAAAE,EAAA,KAAAF,GAAoC,IAAIlC,CAAS,OACrDyC,EAAM,eAAe;AACvB;AAEAC,EAAS,MAAM;AACH,EAAAC,EAAA,SAAS,iBAAiB3C,GAAWM,CAAc,GAC3DsC,EAAA,UAAU,SAASN,GAAaO,CAAW,GAC3CD,EAAA,UAAU,WAAWJ,GAAe,EAAI;AAC5C,CAAC;"}
1
+ {"version":3,"file":"field-observer.js","sources":["../../designsystem/field/field-observer.ts"],"sourcesContent":["import { UHTMLDataListElement } from \"@u-elements/u-datalist\";\nimport styles from \"../styles.module.css\";\nimport {\n\tQUICK_EVENT,\n\tattr,\n\tisInputLike,\n\ton,\n\tonLoaded,\n\tonMutation,\n\tuseId,\n} from \"../utils\";\n\nconst CSS_FIELD = styles.field.split(\" \")[0];\nconst CSS_PROPERTY_OVER = \"--mtds-text-count-over\";\nconst CSS_PROPERTY_UNDER = \"--mtds-text-count-under\";\nconst CSS_VALIDATIONS = styles.validation.split(\" \");\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\n\nfunction handleMutation(fields: HTMLCollectionOf<Element>) {\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\tlet datalist: UHTMLDataListElement | 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 UHTMLDataListElement) datalist = el;\n\t\t\t\telse if (isInputLike(el)) 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 =\n\t\t\t\t\t\tattr(el, \"data-color\") === \"success\" ||\n\t\t\t\t\t\t!el.clientWidth ||\n\t\t\t\t\t\t!el.clientHeight; // Only set invalid if Validation is visible\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\trenderDatalist(input, datalist);\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\nfunction renderDatalist(\n\tinput: HTMLInputElement,\n\tlist?: UHTMLDataListElement | null,\n) {\n\tattr(input, \"list\", list ? useId(list) : null);\n\n\tif (!list) return;\n\tif (!input.hasAttribute(\"placeholder\")) attr(input, \"placeholder\", \"\"); // Needed to render dropdown chevron when <datalist> is present\n\n\t// Setup translations from CSS custom properties\n\tconst style = window.getComputedStyle(list);\n\tconst tags = input.closest(\"u-tags\");\n\tconst i11n = (key: string) => style.getPropertyValue(`--mtds-text-${key}`);\n\n\tattr(list, \"data-sr-plural\", i11n(\"datalist-plural\"));\n\tattr(list, \"data-sr-singular\", i11n(\"datalist-singular\"));\n\n\tif (tags) {\n\t\tattr(tags, \"data-sr-added\", i11n(\"tags-added\"));\n\t\tattr(tags, \"data-sr-empty\", i11n(\"tags-empty\"));\n\t\tattr(tags, \"data-sr-found\", i11n(\"tags-found\"));\n\t\tattr(tags, \"data-sr-of\", i11n(\"tags-of\"));\n\t\tattr(tags, \"data-sr-remove\", i11n(\"tags-remove\"));\n\t\tattr(tags, \"data-sr-removed\", i11n(\"tags-removed\"));\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 = style.getPropertyValue(CSS_PROPERTY_OVER)?.slice(1, -1) || \"\"; // slice to trim quotes\n\t\tconst under =\n\t\t\tstyle.getPropertyValue(CSS_PROPERTY_UNDER)?.slice(1, -1) || \"\"; // slice to trim quotes\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\n// Update when typing\nfunction handleInput({ target }: Event) {\n\tif (isInputLike(target)) {\n\t\trenderCounter(target);\n\t\trenderTextareaSize(target);\n\n\t\t// const input = event.target;\n\t\t// const list = input.list;\n\t\t// if (list) {\n\t\t// console.log('etterpå');\n\t\t// if (isDatalistClick(event)) return; // User clicked option element\n\t\t// if (attr(list, 'data-filter') === 'false') syncDatalistState(input); // Allow custom filtering\n\t\t// }\n\t}\n}\n\n// Prevent browsers from showing default validation bubbles\nfunction handleInvalid(event: Event) {\n\tif ((event.target as Element)?.closest?.(`.${CSS_FIELD}`))\n\t\tevent.preventDefault();\n}\n\nonLoaded(() => {\n\tonMutation(document.documentElement, CSS_FIELD, handleMutation);\n\ton(document, \"input\", handleInput, QUICK_EVENT);\n\ton(document, \"invalid\", handleInvalid, true); // Use capture as invalid does noe buttle\n});\n"],"names":["CSS_FIELD","styles","CSS_PROPERTY_OVER","CSS_PROPERTY_UNDER","CSS_VALIDATIONS","CSS_VALIDATION","handleMutation","fields","field","labels","descs","datalist","input","valid","el","UHTMLDataListElement","isInputLike","attr","desc","label","useId","renderDatalist","renderCounter","renderTextareaSize","textarea","list","style","tags","i11n","key","limit","remainder","nextInvalid","prevInvalid","over","_a","under","_b","css","handleInput","target","handleInvalid","event","onLoaded","onMutation","on","QUICK_EVENT"],"mappings":";;;AAYA,MAAMA,IAAYC,EAAO,MAAM,MAAM,GAAG,EAAE,CAAC,GACrCC,IAAoB,0BACpBC,IAAqB,2BACrBC,IAAkBH,EAAO,WAAW,MAAM,GAAG,GAC7CI,IAAiBD,EAAgB,CAAC;AAExC,SAASE,EAAeC,GAAmC;AAC1D,aAAWC,KAASD;AACnB,QAAIC,EAAM,aAAa;AACtB,YAAMC,IAA6B,CAAC,GAC9BC,IAAmB,CAAC;AAC1B,UAAIC,IAAwC,MACxCC,IAAiC,MACjCC,IAAQ;AAEZ,iBAAWC,KAAMN,EAAM,qBAAqB,GAAG;AAC9C,QAAIM,aAAc,mBAAyBL,EAAA,KAAKK,CAAE,IACzCA,aAAcC,IAAiCJ,IAAAG,IAC/CE,EAAYF,CAAE,IAAWF,IAAAE,IACzBA,EAAG,aAAa,kBAAkB,IAAGJ,EAAM,KAAKI,C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KAAAF,GAAoC,IAAInC,CAAS,OACrD0C,EAAM,eAAe;AACvB;AAEAC,EAAS,MAAM;AACH,EAAAC,EAAA,SAAS,iBAAiB5C,GAAWM,CAAc,GAC3DuC,EAAA,UAAU,SAASN,GAAaO,CAAW,GAC3CD,EAAA,UAAU,WAAWJ,GAAe,EAAI;AAC5C,CAAC;"}
@@ -1,9 +1,7 @@
1
1
  import { ReactUtags, UHTMLTagsElement } from '@u-elements/u-tags';
2
2
  import { JSX } from 'react';
3
- import { InputProps } from '../input/input';
4
3
  import { PolymorphicComponentPropWithRef } from '../react-types';
5
- type FieldBaseProps = InputProps & {
6
- className?: InputProps["className"];
4
+ type FieldBaseProps = {
7
5
  count?: number;
8
6
  description?: React.ReactNode;
9
7
  error?: React.ReactNode;
@@ -15,7 +13,7 @@ type FieldBaseProps = InputProps & {
15
13
  value: string;
16
14
  }>;
17
15
  prefix?: string;
18
- style?: InputProps["style"];
16
+ readOnly?: boolean;
19
17
  suffix?: string;
20
18
  validation?: React.ReactNode;
21
19
  };
@@ -1,7 +1,8 @@
1
- import { jsx as i, Fragment as w, jsxs as O } from "react/jsx-runtime";
1
+ import { jsx as i, Fragment as C, jsxs as O } from "react/jsx-runtime";
2
2
  import { clsx as j } from "../external/clsx/dist/clsx.js";
3
- import { forwardRef as n } from "react";
3
+ import { forwardRef as a } from "react";
4
4
  import "../alert/alert.js";
5
+ import "../app/app.js";
5
6
  import "../avatar/avatar.js";
6
7
  import "../badge/badge.js";
7
8
  import "../breadcrumbs/breadcrumbs.js";
@@ -14,7 +15,7 @@ import "../divider/divider.js";
14
15
  import "../errorsummary/errorsummary.js";
15
16
  import "../fieldset/fieldset.js";
16
17
  import "../heading/heading.js";
17
- import { HelpText as E } from "../helptext/helptext.js";
18
+ import { HelpText as W } from "../helptext/helptext.js";
18
19
  import "../input/input.js";
19
20
  import "../layout/layout.js";
20
21
  import "../link/link.js";
@@ -30,66 +31,74 @@ import "../tag/tag.js";
30
31
  import "../validation/validation.js";
31
32
  import e from "../styles.module.css.js";
32
33
  import { toCustomElementProps as f } from "../utils.js";
33
- const H = n(function({
34
+ const w = a(function({
34
35
  "data-size": r,
35
36
  as: t,
36
- className: l,
37
+ className: p,
37
38
  count: u,
38
39
  description: h,
39
- error: A,
40
+ error: T,
40
41
  helpText: F,
41
- helpTextLabel: D,
42
+ helpTextLabel: A,
42
43
  label: g,
43
- options: p,
44
+ options: l,
44
45
  prefix: s,
45
- style: y,
46
+ style: D,
46
47
  suffix: d,
47
- validation: z,
48
- ...m
48
+ validation: H,
49
+ ...n
49
50
  }, c) {
50
- const v = t || "div", C = !!d || !!s, b = z || A, x = {
51
+ const v = t || "div", z = !!d || !!s, b = H || T, x = {
51
52
  "data-size": r,
52
- className: j(e.field, l),
53
- style: y
53
+ className: j(e.field, p),
54
+ style: D
54
55
  };
55
- return t === "select" && !m.children && Object.assign(m, {
56
- children: /* @__PURE__ */ i(w, { children: p == null ? void 0 : p.map((o) => typeof o == "string" ? { label: o, value: o } : o).map(({ label: o, value: N }) => /* @__PURE__ */ i("option", { value: N, children: o }, N)) })
56
+ return t === "select" && !n.children && Object.assign(n, {
57
+ children: /* @__PURE__ */ i(C, { children: l == null ? void 0 : l.map((o) => typeof o == "string" ? { label: o, value: o } : o).map(({ label: o, value: N }) => /* @__PURE__ */ i("option", { value: N, children: o }, N)) })
57
58
  }), t ? /* @__PURE__ */ O("div", { ...x, children: [
58
- !!g && /* @__PURE__ */ i("label", { children: g }),
59
- !!F && /* @__PURE__ */ i(E, { "aria-label": D, children: F }),
59
+ !!g && /* @__PURE__ */ i("label", { suppressHydrationWarning: !0, children: g }),
60
+ !!F && /* @__PURE__ */ i(W, { "aria-label": A, children: F }),
60
61
  !!h && /* @__PURE__ */ i("p", { children: h }),
61
- C ? /* @__PURE__ */ O(T, { children: [
62
+ z ? /* @__PURE__ */ O(y, { children: [
62
63
  !!s && /* @__PURE__ */ i("span", { children: s }),
63
- /* @__PURE__ */ i(v, { className: e.input, ref: c, ...m }),
64
+ /* @__PURE__ */ i(v, { className: e.input, ref: c, ...n }),
64
65
  !!d && /* @__PURE__ */ i("span", { children: d })
65
- ] }) : /* @__PURE__ */ i(v, { className: e.input, ref: c, ...m }),
66
+ ] }) : /* @__PURE__ */ i(
67
+ v,
68
+ {
69
+ className: e.input,
70
+ suppressHydrationWarning: !0,
71
+ ref: c,
72
+ ...n
73
+ }
74
+ ),
66
75
  !!b && /* @__PURE__ */ i("div", { className: e.validation, children: b }),
67
76
  !!u && /* @__PURE__ */ i("p", { "data-count": u })
68
- ] }) : /* @__PURE__ */ i("div", { ref: c, ...x, ...m });
69
- }), T = n(
70
- function({ className: r, ...t }, l) {
71
- return /* @__PURE__ */ i("div", { className: j(e.affixes, r), ref: l, ...t });
77
+ ] }) : /* @__PURE__ */ i("div", { ref: c, ...x, ...n });
78
+ }), y = a(
79
+ function({ className: r, ...t }, p) {
80
+ return /* @__PURE__ */ i("div", { className: j(e.affixes, r), ref: p, ...t });
72
81
  }
73
- ), P = n(
82
+ ), E = a(
74
83
  function(r, t) {
75
84
  return /* @__PURE__ */ i("u-datalist", { ref: t, ...f(r) });
76
85
  }
77
- ), R = n(
86
+ ), P = a(
78
87
  function(r, t) {
79
88
  return /* @__PURE__ */ i("u-option", { ref: t, ...f(r) });
80
89
  }
81
- ), k = n(
90
+ ), R = a(
82
91
  function(r, t) {
83
92
  return /* @__PURE__ */ i("u-tags", { ref: t, ...f(r) });
84
93
  }
85
- ), ui = Object.assign(H, {
86
- Affixes: T,
87
- Datalist: P,
88
- Tags: k,
89
- Option: R
94
+ ), hi = Object.assign(w, {
95
+ Affixes: y,
96
+ Datalist: E,
97
+ Tags: R,
98
+ Option: P
90
99
  });
91
100
  export {
92
- ui as Field,
93
- H as FieldComp
101
+ hi as Field,
102
+ w as FieldComp
94
103
  };
95
104
  //# sourceMappingURL=field.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["import type { ReactUtags, UHTMLTagsElement } from \"@u-elements/u-tags\";\nimport clsx from \"clsx\";\nimport { type JSX, forwardRef } from \"react\";\nimport type { InputProps } from \"../input/input\";\nimport { HelpText } from \"../react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport { toCustomElementProps } from \"../utils\";\n\ntype FieldBaseProps = InputProps & {\n\tclassName?: InputProps[\"className\"];\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?: Array<string | { label: string; value: string }>;\n\tprefix?: string;\n\tstyle?: InputProps[\"style\"];\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\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\toptions,\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{options\n\t\t\t\t\t\t?.map((o) => (typeof o === \"string\" ? { label: o, value: o } : o))\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\treturn as ? (\n\t\t<div {...shared}>\n\t\t\t{!!label && <label>{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 className={styles.input} ref={ref} {...rest} />\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\nconst FieldAffixes = forwardRef<HTMLDivElement, FieldProps>(\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\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\">;\n\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 FieldTagsProps = ReactUtags;\n\nconst FieldTags = forwardRef<UHTMLTagsElement, FieldTagsProps>(\n\tfunction FieldTags(props, ref) {\n\t\treturn <u-tags ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\tDatalist: FieldDatalist,\n\tTags: FieldTags,\n\tOption: FieldOption,\n});\n"],"names":["FieldComp","forwardRef","size","as","className","count","description","error","helpText","helpTextLabel","label","options","prefix","style","suffix","validation","rest","ref","Tag","affixes","valid","shared","clsx","styles","jsx","Fragment","value","jsxs","HelpText","FieldAffixes","FieldDatalist","props","toCustomElementProps","FieldOption","FieldTags","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCa,MAAAA,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,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,YAAAC;AAAA,EACA,GAAGC;AACJ,GACAC,GACC;AACD,QAAMC,IAAMf,KAAM,OACZgB,IAAU,CAAC,CAACL,KAAU,CAAC,CAACF,GACxBQ,IAAQL,KAAcR,GACtBc,IAAS;AAAA,IACd,aAAanB;AAAA,IACb,WAAWoB,EAAKC,EAAO,OAAOnB,CAAS;AAAA,IACvC,OAAAS;AAAA,EACD;AAGI,SAAAV,MAAO,YAAY,CAACa,EAAK,YAC5B,OAAO,OAAOA,GAAM;AAAA,IACnB,UACC,gBAAAQ,EAAAC,GAAA,EACE,UACEd,KAAA,gBAAAA,EAAA,IAAI,CAAC,MAAO,OAAO,KAAM,WAAW,EAAE,OAAO,GAAG,OAAO,EAAE,IAAI,GA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AGxE,GAIMc,IAAgB7B;AAAA,EACrB,SAAuB8B,GAAOd,GAAK;AAClC,6BAAQ,cAAW,EAAA,KAAAA,GAAW,GAAGe,EAAqBD,CAAK,GAAG;AAAA,EAAA;AAEhE,GAIME,IAAchC;AAAA,EACnB,SAAqB8B,GAAOd,GAAK;AAChC,6BAAQ,YAAS,EAAA,KAAAA,GAAW,GAAGe,EAAqBD,CAAK,GAAG;AAAA,EAAA;AAE9D,GAIMG,IAAYjC;AAAA,EACjB,SAAmB8B,GAAOd,GAAK;AAC9B,6BAAQ,UAAO,EAAA,KAAAA,GAAW,GAAGe,EAAqBD,CAAK,GAAG;AAAA,EAAA;AAE5D,GAEaI,KAAQ,OAAO,OAAOnC,GAAW;AAAA,EAC7C,SAAS6B;AAAA,EACT,UAAUC;AAAA,EACV,MAAMI;AAAA,EACN,QAAQD;AACT,CAAC;"}
1
+ {"version":3,"file":"field.js","sources":["../../designsystem/field/field.tsx"],"sourcesContent":["import type { ReactUtags, UHTMLTagsElement } from \"@u-elements/u-tags\";\nimport clsx from \"clsx\";\nimport { type JSX, forwardRef } from \"react\";\nimport { HelpText } from \"../react\";\nimport type {\n\tPolymorphicComponentPropWithRef,\n\tPolymorphicRef,\n} from \"../react-types\";\nimport styles from \"../styles.module.css\";\nimport { toCustomElementProps } from \"../utils\";\n\ntype FieldBaseProps = {\n\tcount?: number;\n\tdescription?: React.ReactNode;\n\terror?: React.ReactNode; // Kept for backwards compatibility\n\thelpText?: React.ReactNode;\n\thelpTextLabel?: string;\n\tlabel?: React.ReactNode;\n\toptions?: Array<string | { label: string; value: string }>;\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\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\toptions,\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{options\n\t\t\t\t\t\t?.map((o) => (typeof o === \"string\" ? { label: o, value: o } : o))\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={styles.input}\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\nconst FieldAffixes = forwardRef<HTMLDivElement, FieldProps>(\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\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\">;\n\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 FieldTagsProps = ReactUtags;\n\nconst FieldTags = forwardRef<UHTMLTagsElement, FieldTagsProps>(\n\tfunction FieldTags(props, ref) {\n\t\treturn <u-tags ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport const Field = Object.assign(FieldComp, {\n\tAffixes: FieldAffixes,\n\tDatalist: FieldDatalist,\n\tTags: FieldTags,\n\tOption: FieldOption,\n});\n"],"names":["FieldComp","forwardRef","size","as","className","count","description","error","helpText","helpTextLabel","label","options","prefix","style","suffix","validation","rest","ref","Tag","affixes","valid","shared","clsx","styles","jsx","Fragment","value","jsxs","HelpText","FieldAffixes","FieldDatalist","props","toCustomElementProps","FieldOption","FieldTags","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCa,MAAAA,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5D,GAEaI,KAAQ,OAAO,OAAOnC,GAAW;AAAA,EAC7C,SAAS6B;AAAA,EACT,UAAUC;AAAA,EACV,MAAMI;AAAA,EACN,QAAQD;AACT,CAAC;"}
@@ -159,6 +159,7 @@ export declare const Toggles: Story;
159
159
  export declare const WithValidation: Story;
160
160
  export declare const WithAffixes: Story;
161
161
  export declare const WithCharacterCount: Story;
162
+ export declare const WithCustomDescriptionTag: Story;
162
163
  export declare const WithDatalist: Story;
163
164
  export declare const WithTags: Story;
164
165
  export declare const ReactWithDatalist: Story;