@mattilsynet/design 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mtds/card/card.d.ts +1 -6
- package/mtds/card/card.js +11 -22
- package/mtds/card/card.js.map +1 -1
- package/mtds/details/details.js +9 -9
- package/mtds/details/details.js.map +1 -1
- package/mtds/dialog/dialog-observer.js +12 -17
- package/mtds/dialog/dialog-observer.js.map +1 -1
- package/mtds/field/field-observer.js +20 -19
- package/mtds/field/field-observer.js.map +1 -1
- package/mtds/field/field.js +56 -55
- package/mtds/field/field.js.map +1 -1
- package/mtds/fieldset/fieldset-observer.js +16 -15
- package/mtds/fieldset/fieldset-observer.js.map +1 -1
- package/mtds/index.iife.js +5 -5
- package/mtds/layout/app-observer.js +23 -25
- package/mtds/layout/app-observer.js.map +1 -1
- package/mtds/layout/layout.stories.d.ts +1 -0
- package/mtds/logo/logo-observer.js +8 -10
- package/mtds/logo/logo-observer.js.map +1 -1
- package/mtds/popover/popover-observer.js +15 -15
- package/mtds/popover/popover-observer.js.map +1 -1
- package/mtds/progress/progress.js +8 -15
- package/mtds/progress/progress.js.map +1 -1
- package/mtds/styles.css +1 -1
- package/mtds/styles.json +35 -35
- package/mtds/styles.module.css.js +25 -25
- package/mtds/table/table-observer.js +1 -3
- package/mtds/table/table-observer.js.map +1 -1
- package/mtds/tabs/tabs.js +20 -18
- package/mtds/tabs/tabs.js.map +1 -1
- package/mtds/tooltip/tooltip-observer.js +24 -24
- package/mtds/tooltip/tooltip-observer.js.map +1 -1
- package/mtds/utils.d.ts +16 -8
- package/mtds/utils.js +50 -66
- package/mtds/utils.js.map +1 -1
- package/package.json +1 -2
- package/mtds/index.iife.js.map +0 -1
package/mtds/card/card.d.ts
CHANGED
|
@@ -8,10 +8,5 @@ type CardComponent = <Href, As extends React.ElementType = Href extends string ?
|
|
|
8
8
|
export type GroupProps<As extends React.ElementType = "div"> = PolymorphicComponentPropWithRef<As>;
|
|
9
9
|
type GroupComponent = <As extends React.ElementType = "div">(props: GroupProps<As>) => JSX.Element;
|
|
10
10
|
export declare const Group: GroupComponent;
|
|
11
|
-
export
|
|
12
|
-
export type CardSummaryProps = React.ComponentPropsWithoutRef<"summary">;
|
|
13
|
-
export declare const Card: CardComponent & {
|
|
14
|
-
Details: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.DetailsHTMLAttributes<HTMLDetailsElement>, HTMLDetailsElement>, "ref"> & React.RefAttributes<HTMLDetailsElement>>;
|
|
15
|
-
Summary: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & React.RefAttributes<HTMLElement>>;
|
|
16
|
-
};
|
|
11
|
+
export declare const Card: CardComponent;
|
|
17
12
|
export {};
|
package/mtds/card/card.js
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
2
2
|
import { clsx as m } from "../external/clsx/dist/clsx.js";
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
return /* @__PURE__ */ s
|
|
8
|
-
}),
|
|
9
|
-
return /* @__PURE__ */
|
|
10
|
-
}),
|
|
11
|
-
function({ className: a, ...o }, r) {
|
|
12
|
-
return /* @__PURE__ */ s("u-details", { class: m(u.card, a), ref: r, ...o });
|
|
13
|
-
}
|
|
14
|
-
), f = t(
|
|
15
|
-
function({ className: a, ...o }, r) {
|
|
16
|
-
return /* @__PURE__ */ s("u-summary", { class: a, ref: r, ...o });
|
|
17
|
-
}
|
|
18
|
-
), x = Object.assign(e, {
|
|
19
|
-
Details: d,
|
|
20
|
-
Summary: f
|
|
21
|
-
});
|
|
3
|
+
import { forwardRef as n } from "react";
|
|
4
|
+
import f from "../styles.module.css.js";
|
|
5
|
+
const i = n(function({ as: o, className: t, ...r }, a) {
|
|
6
|
+
const s = o || (r.href ? "a" : "div");
|
|
7
|
+
return /* @__PURE__ */ c(s, { className: m(f.card, t), ref: a, ...r });
|
|
8
|
+
}), l = n(function({ as: o, className: t, ...r }, a) {
|
|
9
|
+
return /* @__PURE__ */ c(o || "div", { className: m(f.group, t), ref: a, ...r });
|
|
10
|
+
}), C = i;
|
|
22
11
|
export {
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
C as Card,
|
|
13
|
+
l as Group
|
|
25
14
|
};
|
|
26
15
|
//# sourceMappingURL=card.js.map
|
package/mtds/card/card.js.map
CHANGED
|
@@ -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\
|
|
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;"}
|
package/mtds/details/details.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
-
import { clsx as i } from "../external/clsx/dist/clsx.js";
|
|
3
2
|
import { forwardRef as o } from "react";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import i from "../styles.module.css.js";
|
|
4
|
+
import { toCustomElementProps as s } from "../utils.js";
|
|
5
|
+
const a = o(
|
|
6
|
+
function(t, r) {
|
|
7
|
+
return /* @__PURE__ */ m("u-details", { ref: r, ...s(t, i.details) });
|
|
8
8
|
}
|
|
9
9
|
), n = o(
|
|
10
|
-
function(
|
|
11
|
-
return /* @__PURE__ */ m("u-summary", {
|
|
10
|
+
function(t, r) {
|
|
11
|
+
return /* @__PURE__ */ m("u-summary", { ref: r, ...s(t) });
|
|
12
12
|
}
|
|
13
|
-
),
|
|
13
|
+
), c = Object.assign(a, { Summary: n });
|
|
14
14
|
export {
|
|
15
|
-
|
|
15
|
+
c as Details
|
|
16
16
|
};
|
|
17
17
|
//# sourceMappingURL=details.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"details.js","sources":["../../designsystem/details/details.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"details.js","sources":["../../designsystem/details/details.tsx"],"sourcesContent":["import { forwardRef } from \"react\";\nimport styles from \"../styles.module.css\";\nimport { toCustomElementProps } from \"../utils\";\n\nexport type DetailsProps = React.ComponentPropsWithoutRef<\"details\">;\nconst DetailsComp = forwardRef<HTMLDetailsElement, DetailsProps>(\n\tfunction Details(props, ref) {\n\t\treturn (\n\t\t\t<u-details ref={ref} {...toCustomElementProps(props, styles.details)} />\n\t\t);\n\t},\n);\n\nexport type SummaryProps = React.ComponentPropsWithoutRef<\"summary\">;\nconst DetailsSummary = forwardRef<HTMLElement, SummaryProps>(\n\tfunction DetailsSummary(props, ref) {\n\t\treturn <u-summary ref={ref} {...toCustomElementProps(props)} />;\n\t},\n);\n\nexport const Details = Object.assign(DetailsComp, { Summary: DetailsSummary });\n"],"names":["DetailsComp","forwardRef","props","ref","jsx","toCustomElementProps","styles","DetailsSummary","Details"],"mappings":";;;;AAKA,MAAMA,IAAcC;AAAA,EACnB,SAAiBC,GAAOC,GAAK;AAE3B,WAAA,gBAAAC,EAAC,eAAU,KAAAD,GAAW,GAAGE,EAAqBH,GAAOI,EAAO,OAAO,GAAG;AAAA,EAAA;AAGzE,GAGMC,IAAiBN;AAAA,EACtB,SAAwBC,GAAOC,GAAK;AACnC,6BAAQ,aAAU,EAAA,KAAAA,GAAW,GAAGE,EAAqBH,CAAK,GAAG;AAAA,EAAA;AAE/D,GAEaM,IAAU,OAAO,OAAOR,GAAa,EAAE,SAASO,EAAgB,CAAA;"}
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { IS_BROWSER as m, onLoaded as
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
) : [],
|
|
6
|
-
t.stopImmediatePropagation(), t.stopPropagation();
|
|
7
|
-
}, I = () => {
|
|
1
|
+
import d from "../styles.module.css.js";
|
|
2
|
+
import { IS_BROWSER as m, onLoaded as r, on as f, QUICK_EVENT as u, createOptimizedMutationObserver as p, attr as e } from "../utils.js";
|
|
3
|
+
const g = d.dialog.split(" ")[0], b = m ? document.getElementsByClassName(
|
|
4
|
+
g
|
|
5
|
+
) : [], h = () => {
|
|
8
6
|
for (const t of b)
|
|
9
|
-
t.matches('[open]:not([data-modal="false"]):not(:modal)')
|
|
10
|
-
|
|
11
|
-
// Re-enable closing events
|
|
12
|
-
));
|
|
13
|
-
}, L = ({ clientX: t, clientY: n, target: o }) => {
|
|
7
|
+
t.isConnected && t.showModal && t.close && (t.matches('[open]:not([data-modal="false"]):not(:modal)') ? (e(t, "open", null), t.showModal()) : t.matches(":modal:not([open])") && (e(t, "open", ""), t.close()));
|
|
8
|
+
}, E = ({ clientX: t, clientY: n, target: o }) => {
|
|
14
9
|
var s;
|
|
15
|
-
if (o instanceof HTMLDialogElement &&
|
|
16
|
-
const { top:
|
|
17
|
-
|
|
10
|
+
if (o instanceof HTMLDialogElement && e(o, "data-closedby") === "any") {
|
|
11
|
+
const { top: i, right: a, bottom: c, left: l } = o.getBoundingClientRect();
|
|
12
|
+
i <= n && n <= c && l <= t && t <= a || o.close();
|
|
18
13
|
} else o instanceof Element && o.closest('button[data-command="close"]') && ((s = o == null ? void 0 : o.closest("dialog")) == null || s.close());
|
|
19
14
|
};
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
r(() => {
|
|
16
|
+
f(document, "click", E, u), p(h).observe(
|
|
22
17
|
document.documentElement,
|
|
23
18
|
{
|
|
24
19
|
attributeFilter: ["open"],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-observer.js","sources":["../../designsystem/dialog/dialog-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {\n\tIS_BROWSER,\n\tQUICK_EVENT,\n\tattr,\n\tcreateOptimizedMutationObserver,\n\ton,\n\tonLoaded,\n} from \"../utils\";\n\nconst CSS_DIALOG = styles.dialog.split(\" \")[0];\nconst DIALOGS = IS_BROWSER\n\t? (document.getElementsByClassName(\n\t\t\tCSS_DIALOG,\n\t\t) as HTMLCollectionOf<HTMLDialogElement>)\n\t: [];\nconst
|
|
1
|
+
{"version":3,"file":"dialog-observer.js","sources":["../../designsystem/dialog/dialog-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport {\n\tIS_BROWSER,\n\tQUICK_EVENT,\n\tattr,\n\tcreateOptimizedMutationObserver,\n\ton,\n\tonLoaded,\n} from \"../utils\";\n\nconst CSS_DIALOG = styles.dialog.split(\" \")[0];\nconst DIALOGS = IS_BROWSER\n\t? (document.getElementsByClassName(\n\t\t\tCSS_DIALOG,\n\t\t) as HTMLCollectionOf<HTMLDialogElement>)\n\t: [];\n\nconst handleModal = () => {\n\tfor (const dialog of DIALOGS)\n\t\tif (dialog.isConnected && dialog.showModal && dialog.close) {\n\t\t\tif (dialog.matches('[open]:not([data-modal=\"false\"]):not(:modal)')) {\n\t\t\t\tattr(dialog, \"open\", null); // Using attribute instead of .close to avoid `close` event\n\t\t\t\tdialog.showModal();\n\t\t\t} else if (dialog.matches(\":modal:not([open])\")) {\n\t\t\t\tattr(dialog, \"open\", \"\"); // Set as open\n\t\t\t\tdialog.close(); // So we correclty can call .close, removing <dialog> from #top-layer\n\t\t\t}\n\t\t}\n};\n\nconst handleClick = ({ clientX: x, clientY: y, target: el }: MouseEvent) => {\n\tif (el instanceof HTMLDialogElement && attr(el, \"data-closedby\") === \"any\") {\n\t\tconst { top, right, bottom, left } = el.getBoundingClientRect();\n\t\tconst isInside = top <= y && y <= bottom && left <= x && x <= right;\n\n\t\tif (!isInside) el.close();\n\t} else if (\n\t\tel instanceof Element &&\n\t\tel.closest('button[data-command=\"close\"]')\n\t) {\n\t\tel?.closest(\"dialog\")?.close();\n\t}\n};\n\nonLoaded(() => {\n\ton(document, \"click\", handleClick as EventListener, QUICK_EVENT);\n\tcreateOptimizedMutationObserver(handleModal).observe(\n\t\tdocument.documentElement,\n\t\t{\n\t\t\tattributeFilter: [\"open\"],\n\t\t\tattributes: true,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t},\n\t);\n});\n"],"names":["CSS_DIALOG","styles","DIALOGS","IS_BROWSER","handleModal","dialog","attr","handleClick","x","y","el","top","right","bottom","left","_a","onLoaded","on","QUICK_EVENT","createOptimizedMutationObserver"],"mappings":";;AAUA,MAAMA,IAAaC,EAAO,OAAO,MAAM,GAAG,EAAE,CAAC,GACvCC,IAAUC,IACZ,SAAS;AAAA,EACVH;AACD,IACC,CAAC,GAEEI,IAAc,MAAM;AACzB,aAAWC,KAAUH;AACpB,IAAIG,EAAO,eAAeA,EAAO,aAAaA,EAAO,UAChDA,EAAO,QAAQ,8CAA8C,KAC3DC,EAAAD,GAAQ,QAAQ,IAAI,GACzBA,EAAO,UAAU,KACPA,EAAO,QAAQ,oBAAoB,MACxCC,EAAAD,GAAQ,QAAQ,EAAE,GACvBA,EAAO,MAAM;AAGjB,GAEME,IAAc,CAAC,EAAE,SAASC,GAAG,SAASC,GAAG,QAAQC,QAAqB;;AAC3E,MAAIA,aAAc,qBAAqBJ,EAAKI,GAAI,eAAe,MAAM,OAAO;AAC3E,UAAM,EAAE,KAAAC,GAAK,OAAAC,GAAO,QAAAC,GAAQ,MAAAC,EAAK,IAAIJ,EAAG,sBAAsB;AAG1D,IAFaC,KAAOF,KAAKA,KAAKI,KAAUC,KAAQN,KAAKA,KAAKI,KAE/CF,EAAG,MAAM;AAAA,EAAA,OAExBA,aAAc,WACdA,EAAG,QAAQ,8BAA8B,OAErCK,IAAAL,KAAA,gBAAAA,EAAA,QAAQ,cAAR,QAAAK,EAAmB;AAEzB;AAEAC,EAAS,MAAM;AACX,EAAAC,EAAA,UAAU,SAASV,GAA8BW,CAAW,GAC/DC,EAAgCf,CAAW,EAAE;AAAA,IAC5C,SAAS;AAAA,IACT;AAAA,MACC,iBAAiB,CAAC,MAAM;AAAA,MACxB,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,SAAS;AAAA,IAAA;AAAA,EAEX;AACD,CAAC;"}
|
|
@@ -1,18 +1,19 @@
|
|
|
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
|
|
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
4
|
const g = u.field.split(" ")[0], P = "--mtds-text-count-over", b = "--mtds-text-count-under", p = u.validation.split(" "), x = p[0];
|
|
5
5
|
function _(t) {
|
|
6
|
-
for (const e of t)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
for (const e of t)
|
|
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}`);
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
|
-
}
|
|
16
17
|
}
|
|
17
18
|
function h(t) {
|
|
18
19
|
t instanceof HTMLTextAreaElement && (t.style.setProperty("--mtds-textarea-height", "auto"), t.style.setProperty(
|
|
@@ -21,18 +22,18 @@ function h(t) {
|
|
|
21
22
|
));
|
|
22
23
|
}
|
|
23
24
|
function D(t, e) {
|
|
24
|
-
if (
|
|
25
|
-
t.hasAttribute("placeholder") ||
|
|
26
|
-
const l = window.getComputedStyle(e),
|
|
27
|
-
|
|
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")));
|
|
28
29
|
}
|
|
29
30
|
function v(t) {
|
|
30
|
-
var
|
|
31
|
-
const e = t == null ? void 0 : t.nextElementSibling, l = e &&
|
|
31
|
+
var a, n;
|
|
32
|
+
const e = t == null ? void 0 : t.nextElementSibling, l = e && s(e, "data-count");
|
|
32
33
|
if (e && l) {
|
|
33
|
-
const i = Number(l) - t.value.length, r = i < 0,
|
|
34
|
-
if (
|
|
35
|
-
|
|
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");
|
|
36
37
|
for (const E of p) e.classList.toggle(E, r);
|
|
37
38
|
}
|
|
38
39
|
e.textContent = (r ? y : S).replace(
|
|
@@ -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\tconst labels: HTMLLabelElement[] = [];\n\t\tconst descs: string[] = [];\n\t\tlet input: HTMLInputElement | null = null;\n\t\tlet datalist: UHTMLDataListElement | null = null;\n\t\tlet valid = true;\n\n\t\tfor (const el of field.getElementsByTagName(\"*\")) {\n\t\t\tif (el instanceof HTMLLabelElement) labels.push(el);\n\t\t\telse if (el instanceof UHTMLDataListElement) datalist = el;\n\t\t\telse if (isInputLike(el)) input = el;\n\t\t\telse if (el.classList.contains(CSS_VALIDATION)) {\n\t\t\t\t// Must be before instanceof HTMLParagraphElement since validation can also be a <p>\n\t\t\t\tvalid =\n\t\t\t\t\tattr(el, \"data-color\") === \"success\" ||\n\t\t\t\t\t!el.clientWidth ||\n\t\t\t\t\t!el.clientHeight; // Only set invalid if Validation is visible\n\t\t\t\tdescs.unshift(useId(el));\n\t\t\t} else if (el instanceof HTMLParagraphElement) descs.push(useId(el));\n\t\t}\n\n\t\tif (input) {\n\t\t\tfor (const label of labels) label.htmlFor = useId(input);\n\t\t\trenderDatalist(input, datalist);\n\t\t\trenderCounter(input);\n\t\t\trenderTextareaSize(input);\n\t\t\tattr(input, \"aria-describedby\", descs.join(\" \"))
|
|
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_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,IAAkB,CAAC;AACzB,UAAIC,IAAiC,MACjCC,IAAwC,MACxCC,IAAQ;AAEZ,iBAAWC,KAAMN,EAAM,qBAAqB,GAAG;AAC9C,QAAIM,aAAc,mBAAyBL,EAAA,KAAKK,CAAE,IACzCA,aAAcC,IAAiCH,IAAAE,IAC/CE,EAAYF,CAAE,IAAWH,IAAAG,IACzBA,EAAG,UAAU,SAAST,CAAc,KAG3CQ,IAAAI,EAAKH,GAAI,YAAY,MAAM,aAC3B,CAACA,EAAG,eACJ,CAACA,EAAG,cACCJ,EAAA,QAAQQ,EAAMJ,CAAE,CAAC,KACbA,aAAc,0BAA4B,KAAKI,EAAMJ,CAAE,CAAC;AAGpE,UAAIH,GAAO;AACV,mBAAWQ,KAASV,EAAc,CAAAU,EAAA,UAAUD,EAAMP,CAAK;AACvD,QAAAS,EAAeT,GAAOC,CAAQ,GAC9BS,EAAcV,CAAK,GACnBW,EAAmBX,CAAK,GACxBM,EAAKN,GAAO,oBAAoBD,EAAM,KAAK,GAAG,KAAK,IAAI,GACvDO,EAAKN,GAAO,gBAAgB,GAAG,CAACE,CAAK,EAAE;AAAA,MAAA;AAAA,IACxC;AAEH;AAGA,SAASS,EAAmBC,GAAmB;AAC9C,EAAIA,aAAoB,wBACdA,EAAA,MAAM,YAAY,0BAA0B,MAAM,GAC3DA,EAAS,MAAM;AAAA,IACd;AAAA,IACA,GAAGA,EAAS,YAAY;AAAA,EACzB;AAEF;AAEA,SAASH,EACRT,GACAa,GACC;AAGD,MAFAP,EAAKN,GAAO,QAAQa,IAAON,EAAMM,CAAI,IAAI,IAAI,GAEzC,CAACA,EAAM;AACP,EAACb,EAAM,aAAa,aAAa,KAAQM,EAAAN,GAAO,eAAe,EAAE;AAG/D,QAAAc,IAAQ,OAAO,iBAAiBD,CAAI,GACpCE,IAAOf,EAAM,QAAQ,QAAQ,GAC7BgB,IAAO,CAACC,MAAgBH,EAAM,iBAAiB,eAAeG,CAAG,EAAE;AAEzE,EAAAX,EAAKO,GAAM,kBAAkBG,EAAK,iBAAiB,CAAC,GACpDV,EAAKO,GAAM,oBAAoBG,EAAK,mBAAmB,CAAC,GAEpDD,MACHT,EAAKS,GAAM,iBAAiBC,EAAK,YAAY,CAAC,GAC9CV,EAAKS,GAAM,iBAAiBC,EAAK,YAAY,CAAC,GAC9CV,EAAKS,GAAM,iBAAiBC,EAAK,YAAY,CAAC,GAC9CV,EAAKS,GAAM,cAAcC,EAAK,SAAS,CAAC,GACxCV,EAAKS,GAAM,kBAAkBC,EAAK,aAAa,CAAC,GAChDV,EAAKS,GAAM,mBAAmBC,EAAK,cAAc,CAAC;AAEpD;AAEA,SAASN,EAAcV,GAAyB;;AAC/C,QAAMG,IAAKH,KAAA,gBAAAA,EAAO,oBACZkB,IAAQf,KAAMG,EAAKH,GAAI,YAAY;AAEzC,MAAIA,KAAMe,GAAO;AAChB,UAAMC,IAAY,OAAOD,CAAK,IAAIlB,EAAM,MAAM,QACxCoB,IAAcD,IAAY,GAC1BE,IAAcf,EAAKH,GAAI,WAAW,MAAM,UACxCW,IAAQ,OAAO,iBAAiBX,KAAMH,CAAK,GAC3CsB,MAAOC,IAAAT,EAAM,iBAAiBvB,CAAiB,MAAxC,gBAAAgC,EAA2C,MAAM,GAAG,QAAO,IAClEC,MACLC,IAAAX,EAAM,iBAAiBtB,CAAkB,MAAzC,gBAAAiC,EAA4C,MAAM,GAAG,QAAO;AAE7D,QAAIJ,MAAgBD,GAAa;AAChC,MAAAd,EAAKH,GAAI,aAAaiB,IAAc,WAAW,KAAK;AACpD,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;"}
|
package/mtds/field/field.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as i, Fragment as w, jsxs as
|
|
2
|
-
import { clsx as
|
|
3
|
-
import { forwardRef as
|
|
1
|
+
import { jsx as i, Fragment as w, jsxs as O } from "react/jsx-runtime";
|
|
2
|
+
import { clsx as j } from "../external/clsx/dist/clsx.js";
|
|
3
|
+
import { forwardRef as n } from "react";
|
|
4
4
|
import "../alert/alert.js";
|
|
5
5
|
import "../avatar/avatar.js";
|
|
6
6
|
import "../badge/badge.js";
|
|
@@ -14,7 +14,7 @@ import "../divider/divider.js";
|
|
|
14
14
|
import "../errorsummary/errorsummary.js";
|
|
15
15
|
import "../fieldset/fieldset.js";
|
|
16
16
|
import "../heading/heading.js";
|
|
17
|
-
import { HelpText as
|
|
17
|
+
import { HelpText as E } from "../helptext/helptext.js";
|
|
18
18
|
import "../input/input.js";
|
|
19
19
|
import "../layout/layout.js";
|
|
20
20
|
import "../link/link.js";
|
|
@@ -28,67 +28,68 @@ import "../table/table.js";
|
|
|
28
28
|
import "../tabs/tabs.js";
|
|
29
29
|
import "../tag/tag.js";
|
|
30
30
|
import "../validation/validation.js";
|
|
31
|
-
import
|
|
32
|
-
|
|
31
|
+
import e from "../styles.module.css.js";
|
|
32
|
+
import { toCustomElementProps as f } from "../utils.js";
|
|
33
|
+
const H = n(function({
|
|
33
34
|
"data-size": r,
|
|
34
35
|
as: t,
|
|
35
|
-
className:
|
|
36
|
-
count:
|
|
37
|
-
description:
|
|
38
|
-
error:
|
|
39
|
-
helpText:
|
|
40
|
-
helpTextLabel:
|
|
41
|
-
label:
|
|
42
|
-
options:
|
|
43
|
-
prefix:
|
|
44
|
-
style:
|
|
45
|
-
suffix:
|
|
46
|
-
validation:
|
|
47
|
-
...
|
|
48
|
-
},
|
|
49
|
-
const
|
|
36
|
+
className: l,
|
|
37
|
+
count: u,
|
|
38
|
+
description: h,
|
|
39
|
+
error: A,
|
|
40
|
+
helpText: F,
|
|
41
|
+
helpTextLabel: D,
|
|
42
|
+
label: g,
|
|
43
|
+
options: p,
|
|
44
|
+
prefix: s,
|
|
45
|
+
style: y,
|
|
46
|
+
suffix: d,
|
|
47
|
+
validation: z,
|
|
48
|
+
...m
|
|
49
|
+
}, c) {
|
|
50
|
+
const v = t || "div", C = !!d || !!s, b = z || A, x = {
|
|
50
51
|
"data-size": r,
|
|
51
|
-
className:
|
|
52
|
-
style:
|
|
52
|
+
className: j(e.field, l),
|
|
53
|
+
style: y
|
|
53
54
|
};
|
|
54
|
-
return t === "select" && !
|
|
55
|
-
children: /* @__PURE__ */ i(w, { children:
|
|
56
|
-
}), t ? /* @__PURE__ */
|
|
57
|
-
!!
|
|
58
|
-
!!
|
|
59
|
-
!!
|
|
60
|
-
|
|
61
|
-
!!
|
|
62
|
-
/* @__PURE__ */ i(
|
|
63
|
-
!!
|
|
64
|
-
] }) : /* @__PURE__ */ i(
|
|
65
|
-
!!
|
|
66
|
-
!!
|
|
67
|
-
] }) : /* @__PURE__ */ i("div", { ref:
|
|
68
|
-
}),
|
|
69
|
-
function({ className: r, ...t },
|
|
70
|
-
return /* @__PURE__ */ i("div", { className:
|
|
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)) })
|
|
57
|
+
}), t ? /* @__PURE__ */ O("div", { ...x, children: [
|
|
58
|
+
!!g && /* @__PURE__ */ i("label", { children: g }),
|
|
59
|
+
!!F && /* @__PURE__ */ i(E, { "aria-label": D, children: F }),
|
|
60
|
+
!!h && /* @__PURE__ */ i("p", { children: h }),
|
|
61
|
+
C ? /* @__PURE__ */ O(T, { children: [
|
|
62
|
+
!!s && /* @__PURE__ */ i("span", { children: s }),
|
|
63
|
+
/* @__PURE__ */ i(v, { className: e.input, ref: c, ...m }),
|
|
64
|
+
!!d && /* @__PURE__ */ i("span", { children: d })
|
|
65
|
+
] }) : /* @__PURE__ */ i(v, { className: e.input, ref: c, ...m }),
|
|
66
|
+
!!b && /* @__PURE__ */ i("div", { className: e.validation, children: b }),
|
|
67
|
+
!!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 });
|
|
71
72
|
}
|
|
72
|
-
),
|
|
73
|
-
function(
|
|
74
|
-
return /* @__PURE__ */ i("u-datalist", {
|
|
73
|
+
), P = n(
|
|
74
|
+
function(r, t) {
|
|
75
|
+
return /* @__PURE__ */ i("u-datalist", { ref: t, ...f(r) });
|
|
75
76
|
}
|
|
76
|
-
),
|
|
77
|
-
function(
|
|
78
|
-
return /* @__PURE__ */ i("u-option", {
|
|
77
|
+
), R = n(
|
|
78
|
+
function(r, t) {
|
|
79
|
+
return /* @__PURE__ */ i("u-option", { ref: t, ...f(r) });
|
|
79
80
|
}
|
|
80
|
-
),
|
|
81
|
-
function(
|
|
82
|
-
return /* @__PURE__ */ i("u-tags", {
|
|
81
|
+
), k = n(
|
|
82
|
+
function(r, t) {
|
|
83
|
+
return /* @__PURE__ */ i("u-tags", { ref: t, ...f(r) });
|
|
83
84
|
}
|
|
84
|
-
),
|
|
85
|
-
Affixes:
|
|
86
|
-
Datalist:
|
|
87
|
-
Tags:
|
|
88
|
-
Option:
|
|
85
|
+
), ui = Object.assign(H, {
|
|
86
|
+
Affixes: T,
|
|
87
|
+
Datalist: P,
|
|
88
|
+
Tags: k,
|
|
89
|
+
Option: R
|
|
89
90
|
});
|
|
90
91
|
export {
|
|
91
|
-
|
|
92
|
+
ui as Field,
|
|
92
93
|
H as FieldComp
|
|
93
94
|
};
|
|
94
95
|
//# sourceMappingURL=field.js.map
|
package/mtds/field/field.js.map
CHANGED
|
@@ -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\";\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(
|
|
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":"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"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { onLoaded as l, onMutation as d, useId as f, attr as
|
|
3
|
-
const r =
|
|
4
|
-
function m(
|
|
5
|
-
for (const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import s from "../styles.module.css.js";
|
|
2
|
+
import { onLoaded as l, onMutation as d, useId as f, attr as e, isInputLike as c } from "../utils.js";
|
|
3
|
+
const r = s.fieldset.split(" ")[0], u = s.validation.split(" ")[0];
|
|
4
|
+
function m(a) {
|
|
5
|
+
for (const n of a)
|
|
6
|
+
if (n.isConnected) {
|
|
7
|
+
const o = [];
|
|
8
|
+
let i = null;
|
|
9
|
+
for (const t of n.getElementsByTagName("*"))
|
|
10
|
+
t.classList.contains(u) ? i = f(t) : c(t) && o.push(t);
|
|
11
|
+
for (const t of o)
|
|
12
|
+
e(t, "aria-describedby", i), e(t, "aria-invalid", `${!!i}`);
|
|
13
|
+
}
|
|
13
14
|
}
|
|
14
|
-
l(
|
|
15
|
-
d(document.documentElement, r, m)
|
|
16
|
-
|
|
15
|
+
l(
|
|
16
|
+
() => d(document.documentElement, r, m)
|
|
17
|
+
);
|
|
17
18
|
//# sourceMappingURL=fieldset-observer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldset-observer.js","sources":["../../designsystem/fieldset/fieldset-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, isInputLike, onLoaded, onMutation, useId } from \"../utils\";\n\nconst CSS_FIELDSET = styles.fieldset.split(\" \")[0];\nconst CSS_VALIDATION = styles.validation.split(\" \")[0];\n\nfunction handleMutation(fieldsets: HTMLCollectionOf<Element>) {\n\tfor (const fieldset of fieldsets) {\n\t\tconst inputs: HTMLInputElement[] = [];\n\t\tlet validationId: string | null = null;\n\n\t\tfor (const el of fieldset.getElementsByTagName(\"*\")) {\n\t\t\tif (el.classList.contains(CSS_VALIDATION)) validationId = useId(el);\n\t\t\telse if (isInputLike(el)) inputs.push(el);\n\t\t}\n\n\t\tfor (const input of inputs) {\n\t\t\tattr(input, \"aria-describedby\", validationId);\n\t\t\tattr(input, \"aria-invalid\", `${!!validationId}`);\n\t\t}\n\t}\n}\n\nonLoaded(()
|
|
1
|
+
{"version":3,"file":"fieldset-observer.js","sources":["../../designsystem/fieldset/fieldset-observer.ts"],"sourcesContent":["import styles from \"../styles.module.css\";\nimport { attr, isInputLike, onLoaded, onMutation, useId } from \"../utils\";\n\nconst CSS_FIELDSET = styles.fieldset.split(\" \")[0];\nconst CSS_VALIDATION = styles.validation.split(\" \")[0];\n\nfunction handleMutation(fieldsets: HTMLCollectionOf<Element>) {\n\tfor (const fieldset of fieldsets)\n\t\tif (fieldset.isConnected) {\n\t\t\tconst inputs: HTMLInputElement[] = [];\n\t\t\tlet validationId: string | null = null;\n\n\t\t\tfor (const el of fieldset.getElementsByTagName(\"*\")) {\n\t\t\t\tif (el.classList.contains(CSS_VALIDATION)) validationId = useId(el);\n\t\t\t\telse if (isInputLike(el)) inputs.push(el);\n\t\t\t}\n\n\t\t\tfor (const input of inputs) {\n\t\t\t\tattr(input, \"aria-describedby\", validationId);\n\t\t\t\tattr(input, \"aria-invalid\", `${!!validationId}`);\n\t\t\t}\n\t\t}\n}\n\nonLoaded(() =>\n\tonMutation(document.documentElement, CSS_FIELDSET, handleMutation),\n);\n"],"names":["CSS_FIELDSET","styles","CSS_VALIDATION","handleMutation","fieldsets","fieldset","inputs","validationId","el","useId","isInputLike","input","attr","onLoaded","onMutation"],"mappings":";;AAGA,MAAMA,IAAeC,EAAO,SAAS,MAAM,GAAG,EAAE,CAAC,GAC3CC,IAAiBD,EAAO,WAAW,MAAM,GAAG,EAAE,CAAC;AAErD,SAASE,EAAeC,GAAsC;AAC7D,aAAWC,KAAYD;AACtB,QAAIC,EAAS,aAAa;AACzB,YAAMC,IAA6B,CAAC;AACpC,UAAIC,IAA8B;AAElC,iBAAWC,KAAMH,EAAS,qBAAqB,GAAG;AACjD,QAAIG,EAAG,UAAU,SAASN,CAAc,IAAGK,IAAeE,EAAMD,CAAE,IACzDE,EAAYF,CAAE,KAAGF,EAAO,KAAKE,CAAE;AAGzC,iBAAWG,KAASL;AACd,QAAAM,EAAAD,GAAO,oBAAoBJ,CAAY,GAC5CK,EAAKD,GAAO,gBAAgB,GAAG,CAAC,CAACJ,CAAY,EAAE;AAAA,IAChD;AAEH;AAEAM;AAAA,EAAS,MACRC,EAAW,SAAS,iBAAiBd,GAAcG,CAAc;AAClE;"}
|