@mattilsynet/design 2.2.1 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/mtds/analytics/analytics.js +25 -30
  2. package/mtds/analytics/analytics.js.map +1 -1
  3. package/mtds/chart/chart-axis.d.ts +10 -0
  4. package/mtds/chart/chart-axis.js +21 -0
  5. package/mtds/chart/chart-axis.js.map +1 -0
  6. package/mtds/chart/chart-bars.d.ts +2 -0
  7. package/mtds/chart/chart-bars.js +24 -0
  8. package/mtds/chart/chart-bars.js.map +1 -0
  9. package/mtds/chart/chart-element.d.ts +14 -15
  10. package/mtds/chart/chart-element.js +64 -102
  11. package/mtds/chart/chart-element.js.map +1 -1
  12. package/mtds/chart/chart-lines.d.ts +8 -0
  13. package/mtds/chart/chart-lines.js +44 -0
  14. package/mtds/chart/chart-lines.js.map +1 -0
  15. package/mtds/chart/chart-pies.d.ts +4 -0
  16. package/mtds/chart/chart-pies.js +17 -0
  17. package/mtds/chart/chart-pies.js.map +1 -0
  18. package/mtds/chart/chart.css.js +310 -0
  19. package/mtds/chart/chart.css.js.map +1 -0
  20. package/mtds/chart/chart.d.ts +14 -4
  21. package/mtds/chart/chart.stories.d.ts +15 -0
  22. package/mtds/details/details.d.ts +6 -2
  23. package/mtds/details/details.js.map +1 -1
  24. package/mtds/illustrations/bucket-feed.svg +1 -0
  25. package/mtds/illustrations/index.json +20 -0
  26. package/mtds/illustrations/supplement-group.svg +1 -0
  27. package/mtds/illustrations/supplement-jar.svg +1 -0
  28. package/mtds/illustrations/supplement-tube.svg +1 -0
  29. package/mtds/index.d.ts +4 -4
  30. package/mtds/index.iife.js +157 -172
  31. package/mtds/logo/logo-observer.js +11 -11
  32. package/mtds/logo/logo-observer.js.map +1 -1
  33. package/mtds/map/map.stories.d.ts +10 -0
  34. package/mtds/package.json.js +1 -1
  35. package/mtds/popover/popover-observer.js +20 -18
  36. package/mtds/popover/popover-observer.js.map +1 -1
  37. package/mtds/styles.css +1 -1
  38. package/mtds/styles.json +41 -41
  39. package/mtds/styles.module.css.js +35 -35
  40. package/mtds/tailwind.css +1 -0
  41. package/mtds/toast/toast-helper.d.ts +12 -0
  42. package/mtds/toast/toast-helper.js +22 -8
  43. package/mtds/toast/toast-helper.js.map +1 -1
  44. package/mtds/toast/toast.d.ts +12 -0
  45. package/mtds/toast/toast.js +35 -21
  46. package/mtds/toast/toast.js.map +1 -1
  47. package/mtds/toast/toast.stories.d.ts +1 -0
  48. package/mtds/tooltip/tooltip-observer.js +15 -15
  49. package/mtds/tooltip/tooltip-observer.js.map +1 -1
  50. package/mtds/utils.d.ts +13 -0
  51. package/mtds/utils.js +65 -58
  52. package/mtds/utils.js.map +1 -1
  53. package/package.json +7 -6
  54. package/mtds/chart/chart.module.css.js +0 -325
  55. package/mtds/chart/chart.module.css.js.map +0 -1
package/mtds/styles.json CHANGED
@@ -1,43 +1,43 @@
1
1
  {
2
- "alert": "_alert_wp3o9_1 _ds-alert_nwz76_3",
3
- "app": "_app_wp3o9_1",
4
- "sticky": "_sticky_wp3o9_1",
5
- "avatar": "_avatar_wp3o9_1 _ds-avatar_nwz76_1",
6
- "badge": "_badge_wp3o9_1",
7
- "breadcrumbs": "_breadcrumbs_wp3o9_1 _ds-breadcrumbs_nwz76_5",
8
- "button": "_button_wp3o9_1 _ds-button_nwz76_1",
9
- "card": "_card_wp3o9_1",
10
- "group": "_group_wp3o9_1",
11
- "chip": "_chip_wp3o9_1 _ds-chip_nwz76_5",
12
- "details": "_details_wp3o9_1 _ds-details_nwz76_3",
13
- "dialog": "_dialog_wp3o9_1 _ds-dialog_nwz76_5",
14
- "divider": "_divider_wp3o9_1",
15
- "errorsummary": "_errorsummary_wp3o9_1 _ds-error-summary_nwz76_5",
16
- "field": "_field_wp3o9_1 _ds-field_nwz76_1",
17
- "affixes": "_affixes_wp3o9_1 _ds-field-affixes_nwz76_3",
18
- "fieldset": "_fieldset_wp3o9_1 _ds-fieldset_nwz76_3",
19
- "helptext": "_helptext_wp3o9_1 _ds-focus_nwz76_1",
20
- "input": "_input_wp3o9_1 _ds-input_nwz76_1",
21
- "grid": "_grid_wp3o9_1",
22
- "flex": "_flex_wp3o9_1",
23
- "link": "_link_wp3o9_1",
24
- "logo": "_logo_wp3o9_1",
25
- "pagination": "_pagination_wp3o9_1 _ds-pagination_nwz76_5",
26
- "popover": "_popover_wp3o9_1",
27
- "progress": "_progress_wp3o9_1",
28
- "skeleton": "_skeleton_wp3o9_1 _ds-skeleton_nwz76_5",
29
- "spinner": "_spinner_wp3o9_1",
30
- "steps": "_steps_wp3o9_1",
31
- "table": "_table_wp3o9_1 _ds-table_nwz76_5",
32
- "tabs": "_tabs_wp3o9_1 _ds-tabs_nwz76_5",
33
- "tag": "_tag_wp3o9_1 _ds-tag_nwz76_5",
34
- "toast": "_toast_wp3o9_1",
35
- "togglegroup": "_togglegroup_wp3o9_1",
36
- "heading": "_heading_wp3o9_1 _ds-heading_nwz76_1",
37
- "ingress": "_ingress_wp3o9_1",
38
- "muted": "_muted_wp3o9_1",
39
- "info": "_info_wp3o9_1",
40
- "prose": "_prose_wp3o9_1",
41
- "validation": "_validation_wp3o9_1 _ds-validation-message_nwz76_1",
42
- "body": "_body_wp3o9_168"
2
+ "alert": "_alert_gzx53_1 _ds-alert_nwz76_3",
3
+ "app": "_app_gzx53_1",
4
+ "sticky": "_sticky_gzx53_1",
5
+ "avatar": "_avatar_gzx53_1 _ds-avatar_nwz76_1",
6
+ "badge": "_badge_gzx53_1",
7
+ "breadcrumbs": "_breadcrumbs_gzx53_1 _ds-breadcrumbs_nwz76_5",
8
+ "button": "_button_gzx53_1 _ds-button_nwz76_1",
9
+ "card": "_card_gzx53_1",
10
+ "group": "_group_gzx53_1",
11
+ "chip": "_chip_gzx53_1 _ds-chip_nwz76_5",
12
+ "details": "_details_gzx53_1 _ds-details_nwz76_3",
13
+ "dialog": "_dialog_gzx53_1 _ds-dialog_nwz76_5",
14
+ "divider": "_divider_gzx53_1",
15
+ "errorsummary": "_errorsummary_gzx53_1 _ds-error-summary_nwz76_5",
16
+ "field": "_field_gzx53_1 _ds-field_nwz76_1",
17
+ "affixes": "_affixes_gzx53_1 _ds-field-affixes_nwz76_3",
18
+ "fieldset": "_fieldset_gzx53_1 _ds-fieldset_nwz76_3",
19
+ "helptext": "_helptext_gzx53_1 _ds-focus_nwz76_1",
20
+ "input": "_input_gzx53_1 _ds-input_nwz76_1",
21
+ "grid": "_grid_gzx53_1",
22
+ "flex": "_flex_gzx53_1",
23
+ "link": "_link_gzx53_1",
24
+ "logo": "_logo_gzx53_1",
25
+ "pagination": "_pagination_gzx53_1 _ds-pagination_nwz76_5",
26
+ "popover": "_popover_gzx53_1",
27
+ "progress": "_progress_gzx53_1",
28
+ "skeleton": "_skeleton_gzx53_1 _ds-skeleton_nwz76_5",
29
+ "spinner": "_spinner_gzx53_1",
30
+ "steps": "_steps_gzx53_1",
31
+ "table": "_table_gzx53_1 _ds-table_nwz76_5",
32
+ "tabs": "_tabs_gzx53_1 _ds-tabs_nwz76_5",
33
+ "tag": "_tag_gzx53_1 _ds-tag_nwz76_5",
34
+ "toast": "_toast_gzx53_1",
35
+ "togglegroup": "_togglegroup_gzx53_1",
36
+ "heading": "_heading_gzx53_1 _ds-heading_nwz76_1",
37
+ "ingress": "_ingress_gzx53_1",
38
+ "muted": "_muted_gzx53_1",
39
+ "info": "_info_gzx53_1",
40
+ "prose": "_prose_gzx53_1",
41
+ "validation": "_validation_gzx53_1 _ds-validation-message_nwz76_1",
42
+ "body": "_body_gzx53_171"
43
43
  }
@@ -1,29 +1,29 @@
1
- const _ = "_alert_wp3o9_1 _ds-alert_nwz76_3", o = "_app_wp3o9_1", t = "_sticky_wp3o9_1", s = "_avatar_wp3o9_1 _ds-avatar_nwz76_1", e = "_badge_wp3o9_1", n = "_breadcrumbs_wp3o9_1 _ds-breadcrumbs_nwz76_5", a = "_button_wp3o9_1 _ds-button_nwz76_1", p = "_card_wp3o9_1", r = "_group_wp3o9_1", i = "_chip_wp3o9_1 _ds-chip_nwz76_5", d = "_details_wp3o9_1 _ds-details_nwz76_3", c = "_dialog_wp3o9_1 _ds-dialog_nwz76_5", w = "__drawer_wp3o9_1", l = "_divider_wp3o9_1", g = "_errorsummary_wp3o9_1 _ds-error-summary_nwz76_5", u = "__errorsummary_wp3o9_1", m = "_field_wp3o9_1 _ds-field_nwz76_1", b = "__datalist_wp3o9_1", f = "_affixes_wp3o9_1 _ds-field-affixes_nwz76_3", z = "_fieldset_wp3o9_1 _ds-fieldset_nwz76_3", k = "_helptext_wp3o9_1 _ds-focus_nwz76_1", h = "_input_wp3o9_1 _ds-input_nwz76_1", v = "_grid_wp3o9_1", y = "_flex_wp3o9_1", x = "_link_wp3o9_1", C = "_logo_wp3o9_1", M = "_pagination_wp3o9_1 _ds-pagination_nwz76_5", O = "_popover_wp3o9_1", S = "_progress_wp3o9_1", T = "__indeterminate_wp3o9_1", j = "_skeleton_wp3o9_1 _ds-skeleton_nwz76_5", q = "__skeleton_wp3o9_1", A = "_spinner_wp3o9_1", B = "_steps_wp3o9_1", D = "_table_wp3o9_1 _ds-table_nwz76_5", E = "__scrollShadow_wp3o9_1", F = "_tabs_wp3o9_1 _ds-tabs_nwz76_5", G = "__scrollMask_wp3o9_1", H = "_tag_wp3o9_1 _ds-tag_nwz76_5", I = "_toast_wp3o9_1", J = "__toastClose_wp3o9_1", K = "__toastOpen_wp3o9_1", L = "__toastTimeout_wp3o9_1", N = "_togglegroup_wp3o9_1", P = "__tooltip_wp3o9_1", Q = "_heading_wp3o9_1 _ds-heading_nwz76_1", R = "_ingress_wp3o9_1", U = "_muted_wp3o9_1", V = "_info_wp3o9_1", W = "_prose_wp3o9_1", X = "_validation_wp3o9_1 _ds-validation-message_nwz76_1", Y = "_body_wp3o9_168", Z = "__checked_wp3o9_1", $ = {
1
+ const _ = "_alert_gzx53_1 _ds-alert_nwz76_3", t = "_app_gzx53_1", s = "_sticky_gzx53_1", o = "_avatar_gzx53_1 _ds-avatar_nwz76_1", e = "_badge_gzx53_1", n = "_breadcrumbs_gzx53_1 _ds-breadcrumbs_nwz76_5", a = "_button_gzx53_1 _ds-button_nwz76_1", g = "_card_gzx53_1", r = "_group_gzx53_1", i = "_chip_gzx53_1 _ds-chip_nwz76_5", d = "_details_gzx53_1 _ds-details_nwz76_3", c = "_dialog_gzx53_1 _ds-dialog_nwz76_5", l = "__drawer_gzx53_1", z = "_divider_gzx53_1", x = "_errorsummary_gzx53_1 _ds-error-summary_nwz76_5", p = "__errorsummary_gzx53_1", u = "_field_gzx53_1 _ds-field_nwz76_1", m = "__datalist_gzx53_1", b = "_affixes_gzx53_1 _ds-field-affixes_nwz76_3", w = "_fieldset_gzx53_1 _ds-fieldset_nwz76_3", f = "_helptext_gzx53_1 _ds-focus_nwz76_1", k = "_input_gzx53_1 _ds-input_nwz76_1", h = "_grid_gzx53_1", v = "_flex_gzx53_1", y = "_link_gzx53_1", C = "_logo_gzx53_1", M = "_pagination_gzx53_1 _ds-pagination_nwz76_5", O = "_popover_gzx53_1", S = "_progress_gzx53_1", T = "__indeterminate_gzx53_1", j = "_skeleton_gzx53_1 _ds-skeleton_nwz76_5", q = "__skeleton_gzx53_1", A = "_spinner_gzx53_1", B = "_steps_gzx53_1", D = "_table_gzx53_1 _ds-table_nwz76_5", E = "__scrollShadow_gzx53_1", F = "_tabs_gzx53_1 _ds-tabs_nwz76_5", G = "__scrollMask_gzx53_1", H = "_tag_gzx53_1 _ds-tag_nwz76_5", I = "_toast_gzx53_1", J = "__toastClose_gzx53_1", K = "__toastOpen_gzx53_1", L = "__toastTimeout_gzx53_1", N = "_togglegroup_gzx53_1", P = "__tooltip_gzx53_1", Q = "_heading_gzx53_1 _ds-heading_nwz76_1", R = "_ingress_gzx53_1", U = "_muted_gzx53_1", V = "_info_gzx53_1", W = "_prose_gzx53_1", X = "_validation_gzx53_1 _ds-validation-message_nwz76_1", Y = "_body_gzx53_171", Z = "__checked_gzx53_1", $ = {
2
2
  alert: _,
3
- app: o,
4
- sticky: t,
5
- avatar: s,
3
+ app: t,
4
+ sticky: s,
5
+ avatar: o,
6
6
  badge: e,
7
7
  breadcrumbs: n,
8
8
  button: a,
9
- card: p,
9
+ card: g,
10
10
  group: r,
11
11
  chip: i,
12
12
  details: d,
13
13
  dialog: c,
14
- _drawer: w,
15
- divider: l,
16
- errorsummary: g,
17
- _errorsummary: u,
18
- field: m,
19
- _datalist: b,
20
- affixes: f,
21
- fieldset: z,
22
- helptext: k,
23
- input: h,
24
- grid: v,
25
- flex: y,
26
- link: x,
14
+ _drawer: l,
15
+ divider: z,
16
+ errorsummary: x,
17
+ _errorsummary: p,
18
+ field: u,
19
+ _datalist: m,
20
+ affixes: b,
21
+ fieldset: w,
22
+ helptext: f,
23
+ input: k,
24
+ grid: h,
25
+ flex: v,
26
+ link: y,
27
27
  logo: C,
28
28
  pagination: M,
29
29
  popover: O,
@@ -55,9 +55,9 @@ const _ = "_alert_wp3o9_1 _ds-alert_nwz76_3", o = "_app_wp3o9_1", t = "_sticky_w
55
55
  };
56
56
  export {
57
57
  Z as _checked,
58
- b as _datalist,
59
- w as _drawer,
60
- u as _errorsummary,
58
+ m as _datalist,
59
+ l as _drawer,
60
+ p as _errorsummary,
61
61
  T as _indeterminate,
62
62
  G as _scrollMask,
63
63
  E as _scrollShadow,
@@ -66,32 +66,32 @@ export {
66
66
  K as _toastOpen,
67
67
  L as _toastTimeout,
68
68
  P as _tooltip,
69
- f as affixes,
69
+ b as affixes,
70
70
  _ as alert,
71
- o as app,
72
- s as avatar,
71
+ t as app,
72
+ o as avatar,
73
73
  e as badge,
74
74
  Y as body,
75
75
  n as breadcrumbs,
76
76
  a as button,
77
- p as card,
77
+ g as card,
78
78
  i as chip,
79
79
  $ as default,
80
80
  d as details,
81
81
  c as dialog,
82
- l as divider,
83
- g as errorsummary,
84
- m as field,
85
- z as fieldset,
86
- y as flex,
87
- v as grid,
82
+ z as divider,
83
+ x as errorsummary,
84
+ u as field,
85
+ w as fieldset,
86
+ v as flex,
87
+ h as grid,
88
88
  r as group,
89
89
  Q as heading,
90
- k as helptext,
90
+ f as helptext,
91
91
  V as info,
92
92
  R as ingress,
93
- h as input,
94
- x as link,
93
+ k as input,
94
+ y as link,
95
95
  C as logo,
96
96
  U as muted,
97
97
  M as pagination,
@@ -101,7 +101,7 @@ export {
101
101
  j as skeleton,
102
102
  A as spinner,
103
103
  B as steps,
104
- t as sticky,
104
+ s as sticky,
105
105
  D as table,
106
106
  F as tabs,
107
107
  H as tag,
package/mtds/tailwind.css CHANGED
@@ -72,6 +72,7 @@
72
72
  --color-info-text-default: var(--mtds-color-info-text-default);
73
73
  --color-info-text-subtle: var(--mtds-color-info-text-subtle);
74
74
  --color-inverted-background-default: var(--mtds-color-inverted-background-default);
75
+ --color-inverted-background-default : var(--mtds-color-inverted-background-default );
75
76
  --color-inverted-background-tinted: var(--mtds-color-inverted-background-tinted);
76
77
  --color-inverted-base-active: var(--mtds-color-inverted-base-active);
77
78
  --color-inverted-base-contrast-default: var(--mtds-color-inverted-base-contrast-default);
@@ -9,3 +9,15 @@ export type ToastOptions = {
9
9
  id?: string;
10
10
  };
11
11
  export declare function toast(content: string, opt?: ToastOptions): string;
12
+ export declare namespace toast {
13
+ var success: (content: string, opt?: ToastOptions) => string;
14
+ var danger: (content: string, opt?: ToastOptions) => string;
15
+ var info: (content: string, opt: ToastOptions) => string;
16
+ var warning: (content: string, opt?: ToastOptions) => string;
17
+ var neutral: (content: string, opt?: ToastOptions) => string;
18
+ var promise: <T>(action: () => Promise<T>, props: ToastOptions & {
19
+ loading: string;
20
+ success: string;
21
+ error: string;
22
+ }) => Promise<T>;
23
+ }
@@ -1,14 +1,28 @@
1
- import { clsx as a } from "../external/clsx/dist/clsx.js";
1
+ import { clsx as m } from "../external/clsx/dist/clsx.js";
2
2
  import l from "../styles.module.css.js";
3
- import { attr as t } from "../utils.js";
4
- function u(o, n = {}) {
5
- const e = document.getElementById(n.id || "") || document.createElement("dialog");
6
- return t(e, "aria-busy", n.busy ? "true" : null), t(e, "class", a(l.toast, n.className)), t(e, "data-closedby", n.closedby || null), t(e, "data-color", n.color || null), t(e, "data-icon", `${n.icon ?? ""}` || null), t(e, "data-timeout", `${n.timeout ?? ""}` || null), t(e, "id", n.id || `${Date.now()}`), t(e, "open", n.open === !1 ? null : ""), e.innerHTML = o, e.addEventListener("animationend", d, { once: !0 }), document.body.appendChild(e), e.id;
3
+ import { tag as f, attr as s } from "../utils.js";
4
+ function r(e, o = {}) {
5
+ const n = document.getElementById(o.id || "") || f("dialog");
6
+ return s(n, "aria-busy", o.busy ? "true" : null), s(n, "class", m(l.toast, o.className)), s(n, "data-closedby", o.closedby || null), s(n, "data-color", o.color || null), s(n, "data-icon", `${o.icon ?? ""}` || null), s(n, "data-timeout", `${o.timeout ?? ""}` || null), s(n, "id", o.id || `${Date.now()}`), s(n, "open", o.open === !1 ? null : ""), n.innerHTML = e, n.addEventListener("animationend", y, { once: !0 }), document.body.appendChild(n), n.id;
7
7
  }
8
- function d({ animationName: o, target: n }) {
9
- o === l._toastClose && n.remove();
8
+ function y({ animationName: e, target: o }) {
9
+ e === l._toastClose && o.remove();
10
10
  }
11
+ r.success = (e, o) => r(e, { color: "success", ...o });
12
+ r.danger = (e, o) => r(e, { color: "danger", ...o });
13
+ r.info = (e, o) => r(e, { color: "info", ...o });
14
+ r.warning = (e, o) => r(e, { color: "warning", ...o });
15
+ r.neutral = (e, o) => r(e, { color: "neutral", ...o });
16
+ r.promise = async function(o, n) {
17
+ const { loading: c, success: i, error: u, ...d } = n, a = r(c, { busy: !0, ...d });
18
+ try {
19
+ const t = await o();
20
+ return r.success(i, { id: a, busy: !1 }), t;
21
+ } catch (t) {
22
+ throw r.danger(u, { id: a, busy: !1 }), t;
23
+ }
24
+ };
11
25
  export {
12
- u as toast
26
+ r as toast
13
27
  };
14
28
  //# sourceMappingURL=toast-helper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toast-helper.js","sources":["../../designsystem/toast/toast-helper.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport styles from \"../styles.module.css\";\nimport { attr } from \"../utils\";\n\nexport type ToastOptions = {\n\tclassName?: string;\n\tclosedby?: \"none\";\n\tcolor?: \"main\" | \"neutral\" | \"success\" | \"danger\" | \"info\" | \"warning\";\n\ticon?: boolean | \"none\";\n\ttimeout?: number | false;\n\tbusy?: boolean;\n\topen?: boolean;\n\tid?: string;\n};\n\nexport function toast(content: string, opt: ToastOptions = {}) {\n\tconst dialog =\n\t\tdocument.getElementById(opt.id || \"\") || document.createElement(\"dialog\");\n\n\tattr(dialog, \"aria-busy\", opt.busy ? \"true\" : null);\n\tattr(dialog, \"class\", clsx(styles.toast, opt.className));\n\tattr(dialog, \"data-closedby\", opt.closedby || null);\n\tattr(dialog, \"data-color\", opt.color || null);\n\tattr(dialog, \"data-icon\", `${opt.icon ?? \"\"}` || null);\n\tattr(dialog, \"data-timeout\", `${opt.timeout ?? \"\"}` || null);\n\tattr(dialog, \"id\", opt.id || `${Date.now()}`);\n\tattr(dialog, \"open\", opt.open === false ? null : \"\");\n\n\tdialog.innerHTML = content;\n\tdialog.addEventListener(\"animationend\", handleToastClose, { once: true });\n\tdocument.body.appendChild(dialog);\n\treturn dialog.id;\n}\n\nfunction handleToastClose({ animationName, target }: Partial<AnimationEvent>) {\n\tif (animationName === styles._toastClose)\n\t\t(target as HTMLDialogElement).remove();\n}\n"],"names":["toast","content","opt","dialog","attr","clsx","styles","handleToastClose","animationName","target"],"mappings":";;;AAeO,SAASA,EAAMC,GAAiBC,IAAoB,IAAI;AAC9D,QAAMC,IACL,SAAS,eAAeD,EAAI,MAAM,EAAE,KAAK,SAAS,cAAc,QAAQ;AAEzE,SAAAE,EAAKD,GAAQ,aAAaD,EAAI,OAAO,SAAS,IAAI,GAClDE,EAAKD,GAAQ,SAASE,EAAKC,EAAO,OAAOJ,EAAI,SAAS,CAAC,GACvDE,EAAKD,GAAQ,iBAAiBD,EAAI,YAAY,IAAI,GAClDE,EAAKD,GAAQ,cAAcD,EAAI,SAAS,IAAI,GAC5CE,EAAKD,GAAQ,aAAa,GAAGD,EAAI,QAAQ,EAAE,MAAM,IAAI,GACrDE,EAAKD,GAAQ,gBAAgB,GAAGD,EAAI,WAAW,EAAE,MAAM,IAAI,GAC3DE,EAAKD,GAAQ,MAAMD,EAAI,MAAM,GAAG,KAAK,IAAA,CAAK,EAAE,GAC5CE,EAAKD,GAAQ,QAAQD,EAAI,SAAS,KAAQ,OAAO,EAAE,GAEnDC,EAAO,YAAYF,GACnBE,EAAO,iBAAiB,gBAAgBI,GAAkB,EAAE,MAAM,IAAM,GACxE,SAAS,KAAK,YAAYJ,CAAM,GACzBA,EAAO;AACf;AAEA,SAASI,EAAiB,EAAE,eAAAC,GAAe,QAAAC,KAAmC;AAC7E,EAAID,MAAkBF,EAAO,eAC3BG,EAA6B,OAAA;AAChC;"}
1
+ {"version":3,"file":"toast-helper.js","sources":["../../designsystem/toast/toast-helper.ts"],"sourcesContent":["import clsx from \"clsx\";\nimport styles from \"../styles.module.css\";\nimport { attr, tag } from \"../utils\";\n\nexport type ToastOptions = {\n\tclassName?: string;\n\tclosedby?: \"none\";\n\tcolor?: \"main\" | \"neutral\" | \"success\" | \"danger\" | \"info\" | \"warning\";\n\ticon?: boolean | \"none\";\n\ttimeout?: number | false;\n\tbusy?: boolean;\n\topen?: boolean;\n\tid?: string;\n};\n\nexport function toast(content: string, opt: ToastOptions = {}) {\n\tconst dialog = document.getElementById(opt.id || \"\") || tag(\"dialog\");\n\n\tattr(dialog, \"aria-busy\", opt.busy ? \"true\" : null);\n\tattr(dialog, \"class\", clsx(styles.toast, opt.className));\n\tattr(dialog, \"data-closedby\", opt.closedby || null);\n\tattr(dialog, \"data-color\", opt.color || null);\n\tattr(dialog, \"data-icon\", `${opt.icon ?? \"\"}` || null);\n\tattr(dialog, \"data-timeout\", `${opt.timeout ?? \"\"}` || null);\n\tattr(dialog, \"id\", opt.id || `${Date.now()}`);\n\tattr(dialog, \"open\", opt.open === false ? null : \"\");\n\n\tdialog.innerHTML = content;\n\tdialog.addEventListener(\"animationend\", handleToastClose, { once: true });\n\tdocument.body.appendChild(dialog);\n\treturn dialog.id;\n}\n\nfunction handleToastClose({ animationName, target }: Partial<AnimationEvent>) {\n\tif (animationName === styles._toastClose)\n\t\t(target as HTMLDialogElement).remove();\n}\n\n// Expose toast.danger, toast.info, toast.success etc.\ntoast.success = (content: string, opt?: ToastOptions) =>\n\ttoast(content, { color: \"success\", ...opt });\ntoast.danger = (content: string, opt?: ToastOptions) =>\n\ttoast(content, { color: \"danger\", ...opt });\ntoast.info = (content: string, opt: ToastOptions) =>\n\ttoast(content, { color: \"info\", ...opt });\ntoast.warning = (content: string, opt?: ToastOptions) =>\n\ttoast(content, { color: \"warning\", ...opt });\ntoast.neutral = (content: string, opt?: ToastOptions) =>\n\ttoast(content, { color: \"neutral\", ...opt });\ntoast.promise = async function promise<T>(\n\taction: () => Promise<T>,\n\tprops: ToastOptions & {\n\t\tloading: string;\n\t\tsuccess: string;\n\t\terror: string;\n\t},\n): Promise<T> {\n\tconst { loading, success, error, ...opt } = props;\n\tconst id = toast(loading, { busy: true, ...opt });\n\ttry {\n\t\tconst result = await action();\n\t\ttoast.success(success, { id, busy: false });\n\t\treturn result;\n\t} catch (_error) {\n\t\ttoast.danger(error, { id, busy: false });\n\t\tthrow _error;\n\t}\n};\n"],"names":["toast","content","opt","dialog","tag","attr","clsx","styles","handleToastClose","animationName","target","action","props","loading","success","error","id","result","_error"],"mappings":";;;AAeO,SAASA,EAAMC,GAAiBC,IAAoB,IAAI;AAC9D,QAAMC,IAAS,SAAS,eAAeD,EAAI,MAAM,EAAE,KAAKE,EAAI,QAAQ;AAEpE,SAAAC,EAAKF,GAAQ,aAAaD,EAAI,OAAO,SAAS,IAAI,GAClDG,EAAKF,GAAQ,SAASG,EAAKC,EAAO,OAAOL,EAAI,SAAS,CAAC,GACvDG,EAAKF,GAAQ,iBAAiBD,EAAI,YAAY,IAAI,GAClDG,EAAKF,GAAQ,cAAcD,EAAI,SAAS,IAAI,GAC5CG,EAAKF,GAAQ,aAAa,GAAGD,EAAI,QAAQ,EAAE,MAAM,IAAI,GACrDG,EAAKF,GAAQ,gBAAgB,GAAGD,EAAI,WAAW,EAAE,MAAM,IAAI,GAC3DG,EAAKF,GAAQ,MAAMD,EAAI,MAAM,GAAG,KAAK,IAAA,CAAK,EAAE,GAC5CG,EAAKF,GAAQ,QAAQD,EAAI,SAAS,KAAQ,OAAO,EAAE,GAEnDC,EAAO,YAAYF,GACnBE,EAAO,iBAAiB,gBAAgBK,GAAkB,EAAE,MAAM,IAAM,GACxE,SAAS,KAAK,YAAYL,CAAM,GACzBA,EAAO;AACf;AAEA,SAASK,EAAiB,EAAE,eAAAC,GAAe,QAAAC,KAAmC;AAC7E,EAAID,MAAkBF,EAAO,eAC3BG,EAA6B,OAAA;AAChC;AAGAV,EAAM,UAAU,CAACC,GAAiBC,MACjCF,EAAMC,GAAS,EAAE,OAAO,WAAW,GAAGC,GAAK;AAC5CF,EAAM,SAAS,CAACC,GAAiBC,MAChCF,EAAMC,GAAS,EAAE,OAAO,UAAU,GAAGC,GAAK;AAC3CF,EAAM,OAAO,CAACC,GAAiBC,MAC9BF,EAAMC,GAAS,EAAE,OAAO,QAAQ,GAAGC,GAAK;AACzCF,EAAM,UAAU,CAACC,GAAiBC,MACjCF,EAAMC,GAAS,EAAE,OAAO,WAAW,GAAGC,GAAK;AAC5CF,EAAM,UAAU,CAACC,GAAiBC,MACjCF,EAAMC,GAAS,EAAE,OAAO,WAAW,GAAGC,GAAK;AAC5CF,EAAM,UAAU,eACfW,GACAC,GAKa;AACb,QAAM,EAAE,SAAAC,GAAS,SAAAC,GAAS,OAAAC,GAAO,GAAGb,MAAQU,GACtCI,IAAKhB,EAAMa,GAAS,EAAE,MAAM,IAAM,GAAGX,GAAK;AAChD,MAAI;AACH,UAAMe,IAAS,MAAMN,EAAA;AACrB,WAAAX,EAAM,QAAQc,GAAS,EAAE,IAAAE,GAAI,MAAM,IAAO,GACnCC;AAAA,EACR,SAASC,GAAQ;AAChB,UAAAlB,EAAM,OAAOe,GAAO,EAAE,IAAAC,GAAI,MAAM,IAAO,GACjCE;AAAA,EACP;AACD;"}
@@ -8,3 +8,15 @@ declare global {
8
8
  }
9
9
  }
10
10
  export declare function toast(content: React.ReactNode, opt?: ToastOptions): string;
11
+ export declare namespace toast {
12
+ var success: (content: React.ReactNode, opt?: ToastOptions) => string;
13
+ var danger: (content: React.ReactNode, opt?: ToastOptions) => string;
14
+ var info: (content: React.ReactNode, opt?: ToastOptions) => string;
15
+ var warning: (content: React.ReactNode, opt?: ToastOptions) => string;
16
+ var neutral: (content: React.ReactNode, opt?: ToastOptions) => string;
17
+ var promise: <T>(action: () => Promise<T>, props: ToastOptions & {
18
+ loading: React.ReactNode;
19
+ success: React.ReactNode;
20
+ error: React.ReactNode;
21
+ }) => Promise<T>;
22
+ }
@@ -1,39 +1,53 @@
1
- import { jsx as n } from "react/jsx-runtime";
2
- import { clsx as i } from "../external/clsx/dist/clsx.js";
3
- import { c } from "../_virtual/client.js";
4
- import r from "../styles.module.css.js";
5
- import { IS_BROWSER as m } from "../utils.js";
6
- if (m && !window._mtdsReactToasts) {
7
- const o = document.body.appendChild(document.createElement("div")), t = c.createRoot(o), e = /* @__PURE__ */ new Map(), d = () => t.render(Array.from(e.values() || []));
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import { clsx as u } from "../external/clsx/dist/clsx.js";
3
+ import { c as f } from "../_virtual/client.js";
4
+ import i from "../styles.module.css.js";
5
+ import { IS_BROWSER as w, tag as y } from "../utils.js";
6
+ if (w && !window._mtdsReactToasts) {
7
+ const t = f.createRoot(document.body.appendChild(y("div"))), o = /* @__PURE__ */ new Map(), e = () => t.render(Array.from(o.values() || []));
8
8
  window._mtdsReactToasts = {
9
- set: (s, a) => e.set(s, a) && d(),
10
- delete: ({ animationName: s, currentTarget: a }) => {
11
- s === r._toastClose && (e.delete(a.id), d());
9
+ set: (r, a) => o.set(r, a) && e(),
10
+ delete: ({ animationName: r, currentTarget: a }) => {
11
+ r === i._toastClose && (o.delete(a.id), e());
12
12
  }
13
13
  };
14
14
  }
15
- function R(o, t = {}) {
16
- const e = t.id || `${Date.now()}`;
15
+ function s(t, o = {}) {
16
+ const e = o.id || `${Date.now()}`;
17
17
  return window._mtdsReactToasts?.set(
18
18
  e,
19
- /* @__PURE__ */ n(
19
+ /* @__PURE__ */ m(
20
20
  "dialog",
21
21
  {
22
- "aria-busy": t.busy,
23
- className: i(r.toast, t.className),
24
- "data-closedby": t.closedby,
25
- "data-color": t.color,
26
- "data-timeout": t.timeout,
22
+ "aria-busy": o.busy,
23
+ className: u(i.toast, o.className),
24
+ "data-closedby": o.closedby,
25
+ "data-color": o.color,
26
+ "data-timeout": o.timeout,
27
27
  id: e,
28
28
  onAnimationEnd: window._mtdsReactToasts.delete,
29
- open: t.open ?? !0,
30
- children: o
29
+ open: o.open ?? !0,
30
+ children: t
31
31
  },
32
32
  e
33
33
  )
34
34
  ), e;
35
35
  }
36
+ s.success = (t, o) => s(t, { color: "success", ...o });
37
+ s.danger = (t, o) => s(t, { color: "danger", ...o });
38
+ s.info = (t, o) => s(t, { color: "info", ...o });
39
+ s.warning = (t, o) => s(t, { color: "warning", ...o });
40
+ s.neutral = (t, o) => s(t, { color: "neutral", ...o });
41
+ s.promise = async function(o, e) {
42
+ const { loading: r, success: a, error: d, ...l } = e, c = s(r, { busy: !0, ...l });
43
+ try {
44
+ const n = await o();
45
+ return s.success(a, { id: c, busy: !1 }), n;
46
+ } catch (n) {
47
+ throw s.danger(d, { id: c, busy: !1 }), n;
48
+ }
49
+ };
36
50
  export {
37
- R as toast
51
+ s as toast
38
52
  };
39
53
  //# sourceMappingURL=toast.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toast.js","sources":["../../designsystem/toast/toast.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { createRoot } from \"react-dom/client\";\nimport styles from \"../styles.module.css\";\nimport { IS_BROWSER } from \"../utils\";\nimport type { ToastOptions } from \"./toast-helper\";\n\ndeclare global {\n\tinterface Window {\n\t\t_mtdsReactToasts?: {\n\t\t\tset: (id: string, jsx: React.ReactNode) => void;\n\t\t\tdelete: (event: React.AnimationEvent<HTMLDialogElement>) => void;\n\t\t};\n\t}\n}\n\n// Ensure only a single toast master is created\nif (IS_BROWSER && !window._mtdsReactToasts) {\n\tconst node = document.body.appendChild(document.createElement(\"div\"));\n\tconst root = createRoot(node);\n\tconst toasts = new Map<string, React.ReactNode>();\n\tconst render = () => root.render(Array.from(toasts.values() || []));\n\n\twindow._mtdsReactToasts = {\n\t\tset: (id, jsx) => toasts.set(id, jsx) && render(),\n\t\tdelete: ({ animationName, currentTarget }) => {\n\t\t\tif (animationName !== styles._toastClose) return;\n\t\t\ttoasts.delete(currentTarget.id);\n\t\t\trender();\n\t\t},\n\t};\n}\n\nexport function toast(content: React.ReactNode, opt: ToastOptions = {}) {\n\tconst id = opt.id || `${Date.now()}`;\n\twindow._mtdsReactToasts?.set(\n\t\tid,\n\t\t<dialog\n\t\t\taria-busy={opt.busy}\n\t\t\tclassName={clsx(styles.toast, opt.className)}\n\t\t\tdata-closedby={opt.closedby}\n\t\t\tdata-color={opt.color}\n\t\t\tdata-timeout={opt.timeout}\n\t\t\tid={id}\n\t\t\tkey={id}\n\t\t\tonAnimationEnd={window._mtdsReactToasts.delete}\n\t\t\topen={opt.open ?? true}\n\t\t>\n\t\t\t{content}\n\t\t</dialog>,\n\t);\n\n\treturn id;\n}\n"],"names":["IS_BROWSER","node","root","createRoot","toasts","render","id","jsx","animationName","currentTarget","styles","toast","content","opt","clsx"],"mappings":";;;;;AAgBA,IAAIA,KAAc,CAAC,OAAO,kBAAkB;AAC3C,QAAMC,IAAO,SAAS,KAAK,YAAY,SAAS,cAAc,KAAK,CAAC,GAC9DC,IAAOC,EAAAA,WAAWF,CAAI,GACtBG,wBAAa,IAAA,GACbC,IAAS,MAAMH,EAAK,OAAO,MAAM,KAAKE,EAAO,YAAY,CAAA,CAAE,CAAC;AAElE,SAAO,mBAAmB;AAAA,IACzB,KAAK,CAACE,GAAIC,MAAQH,EAAO,IAAIE,GAAIC,CAAG,KAAKF,EAAA;AAAA,IACzC,QAAQ,CAAC,EAAE,eAAAG,GAAe,eAAAC,QAAoB;AAC7C,MAAID,MAAkBE,EAAO,gBAC7BN,EAAO,OAAOK,EAAc,EAAE,GAC9BJ,EAAA;AAAA,IACD;AAAA,EAAA;AAEF;AAEO,SAASM,EAAMC,GAA0BC,IAAoB,IAAI;AACvE,QAAMP,IAAKO,EAAI,MAAM,GAAG,KAAK,KAAK;AAClC,gBAAO,kBAAkB;AAAA,IACxBP;AAAA,IACA,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACA,aAAWM,EAAI;AAAA,QACf,WAAWC,EAAKJ,EAAO,OAAOG,EAAI,SAAS;AAAA,QAC3C,iBAAeA,EAAI;AAAA,QACnB,cAAYA,EAAI;AAAA,QAChB,gBAAcA,EAAI;AAAA,QAClB,IAAAP;AAAA,QAEA,gBAAgB,OAAO,iBAAiB;AAAA,QACxC,MAAMO,EAAI,QAAQ;AAAA,QAEjB,UAAAD;AAAA,MAAA;AAAA,MAJIN;AAAA,IAAA;AAAA,EAKN,GAGMA;AACR;"}
1
+ {"version":3,"file":"toast.js","sources":["../../designsystem/toast/toast.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { createRoot } from \"react-dom/client\";\nimport styles from \"../styles.module.css\";\nimport { IS_BROWSER, tag } from \"../utils\";\nimport type { ToastOptions } from \"./toast-helper\";\n\ndeclare global {\n\tinterface Window {\n\t\t_mtdsReactToasts?: {\n\t\t\tset: (id: string, jsx: React.ReactNode) => void;\n\t\t\tdelete: (event: React.AnimationEvent<HTMLDialogElement>) => void;\n\t\t};\n\t}\n}\n\n// Ensure only a single toast master is created\nif (IS_BROWSER && !window._mtdsReactToasts) {\n\tconst root = createRoot(document.body.appendChild(tag(\"div\")));\n\tconst toasts = new Map<string, React.ReactNode>();\n\tconst render = () => root.render(Array.from(toasts.values() || []));\n\n\t// Expose methods to add/remove toasts from the root container\n\twindow._mtdsReactToasts = {\n\t\tset: (id, jsx) => toasts.set(id, jsx) && render(),\n\t\tdelete: ({ animationName, currentTarget }) => {\n\t\t\tif (animationName !== styles._toastClose) return;\n\t\t\ttoasts.delete(currentTarget.id);\n\t\t\trender();\n\t\t},\n\t};\n}\n\nexport function toast(content: React.ReactNode, opt: ToastOptions = {}) {\n\tconst id = opt.id || `${Date.now()}`;\n\twindow._mtdsReactToasts?.set(\n\t\tid,\n\t\t<dialog\n\t\t\taria-busy={opt.busy}\n\t\t\tclassName={clsx(styles.toast, opt.className)}\n\t\t\tdata-closedby={opt.closedby}\n\t\t\tdata-color={opt.color}\n\t\t\tdata-timeout={opt.timeout}\n\t\t\tid={id}\n\t\t\tkey={id}\n\t\t\tonAnimationEnd={window._mtdsReactToasts.delete}\n\t\t\topen={opt.open ?? true}\n\t\t>\n\t\t\t{content}\n\t\t</dialog>,\n\t);\n\n\treturn id;\n}\n\n// Expose toast.danger, toast.info, toast.success etc.\ntoast.success = (content: React.ReactNode, opt?: ToastOptions) =>\n\ttoast(content, { color: \"success\", ...opt });\ntoast.danger = (content: React.ReactNode, opt?: ToastOptions) =>\n\ttoast(content, { color: \"danger\", ...opt });\ntoast.info = (content: React.ReactNode, opt?: ToastOptions) =>\n\ttoast(content, { color: \"info\", ...opt });\ntoast.warning = (content: React.ReactNode, opt?: ToastOptions) =>\n\ttoast(content, { color: \"warning\", ...opt });\ntoast.neutral = (content: React.ReactNode, opt?: ToastOptions) =>\n\ttoast(content, { color: \"neutral\", ...opt });\ntoast.promise = async function promise<T>(\n\taction: () => Promise<T>,\n\tprops: ToastOptions & {\n\t\tloading: React.ReactNode;\n\t\tsuccess: React.ReactNode;\n\t\terror: React.ReactNode;\n\t},\n): Promise<T> {\n\tconst { loading, success, error, ...opt } = props;\n\tconst id = toast(loading, { busy: true, ...opt });\n\ttry {\n\t\tconst result = await action();\n\t\ttoast.success(success, { id, busy: false });\n\t\treturn result;\n\t} catch (_error) {\n\t\ttoast.danger(error, { id, busy: false });\n\t\tthrow _error;\n\t}\n};\n"],"names":["IS_BROWSER","root","createRoot","tag","toasts","render","id","jsx","animationName","currentTarget","styles","toast","content","opt","clsx","action","props","loading","success","error","result","_error"],"mappings":";;;;;AAgBA,IAAIA,KAAc,CAAC,OAAO,kBAAkB;AAC3C,QAAMC,IAAOC,EAAAA,WAAW,SAAS,KAAK,YAAYC,EAAI,KAAK,CAAC,CAAC,GACvDC,wBAAa,IAAA,GACbC,IAAS,MAAMJ,EAAK,OAAO,MAAM,KAAKG,EAAO,YAAY,CAAA,CAAE,CAAC;AAGlE,SAAO,mBAAmB;AAAA,IACzB,KAAK,CAACE,GAAIC,MAAQH,EAAO,IAAIE,GAAIC,CAAG,KAAKF,EAAA;AAAA,IACzC,QAAQ,CAAC,EAAE,eAAAG,GAAe,eAAAC,QAAoB;AAC7C,MAAID,MAAkBE,EAAO,gBAC7BN,EAAO,OAAOK,EAAc,EAAE,GAC9BJ,EAAA;AAAA,IACD;AAAA,EAAA;AAEF;AAEO,SAASM,EAAMC,GAA0BC,IAAoB,IAAI;AACvE,QAAMP,IAAKO,EAAI,MAAM,GAAG,KAAK,KAAK;AAClC,gBAAO,kBAAkB;AAAA,IACxBP;AAAA,IACA,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACA,aAAWM,EAAI;AAAA,QACf,WAAWC,EAAKJ,EAAO,OAAOG,EAAI,SAAS;AAAA,QAC3C,iBAAeA,EAAI;AAAA,QACnB,cAAYA,EAAI;AAAA,QAChB,gBAAcA,EAAI;AAAA,QAClB,IAAAP;AAAA,QAEA,gBAAgB,OAAO,iBAAiB;AAAA,QACxC,MAAMO,EAAI,QAAQ;AAAA,QAEjB,UAAAD;AAAA,MAAA;AAAA,MAJIN;AAAA,IAAA;AAAA,EAKN,GAGMA;AACR;AAGAK,EAAM,UAAU,CAACC,GAA0BC,MAC1CF,EAAMC,GAAS,EAAE,OAAO,WAAW,GAAGC,GAAK;AAC5CF,EAAM,SAAS,CAACC,GAA0BC,MACzCF,EAAMC,GAAS,EAAE,OAAO,UAAU,GAAGC,GAAK;AAC3CF,EAAM,OAAO,CAACC,GAA0BC,MACvCF,EAAMC,GAAS,EAAE,OAAO,QAAQ,GAAGC,GAAK;AACzCF,EAAM,UAAU,CAACC,GAA0BC,MAC1CF,EAAMC,GAAS,EAAE,OAAO,WAAW,GAAGC,GAAK;AAC5CF,EAAM,UAAU,CAACC,GAA0BC,MAC1CF,EAAMC,GAAS,EAAE,OAAO,WAAW,GAAGC,GAAK;AAC5CF,EAAM,UAAU,eACfI,GACAC,GAKa;AACb,QAAM,EAAE,SAAAC,GAAS,SAAAC,GAAS,OAAAC,GAAO,GAAGN,MAAQG,GACtCV,IAAKK,EAAMM,GAAS,EAAE,MAAM,IAAM,GAAGJ,GAAK;AAChD,MAAI;AACH,UAAMO,IAAS,MAAML,EAAA;AACrB,WAAAJ,EAAM,QAAQO,GAAS,EAAE,IAAAZ,GAAI,MAAM,IAAO,GACnCc;AAAA,EACR,SAASC,GAAQ;AAChB,UAAAV,EAAM,OAAOQ,GAAO,EAAE,IAAAb,GAAI,MAAM,IAAO,GACjCe;AAAA,EACP;AACD;"}
@@ -14,6 +14,7 @@ export declare const Default: Story;
14
14
  export declare const React: Story;
15
15
  export declare const Colors: Story;
16
16
  export declare const WithLoading: Story;
17
+ export declare const WithPromise: Story;
17
18
  export declare const WithNoTimeout: Story;
18
19
  export declare const WithCustomClose: Story;
19
20
  export declare const HTML: Story;
@@ -1,35 +1,35 @@
1
- import { flip as L, shift as h } from "../external/@floating-ui/dom/dist/floating-ui.dom.js";
1
+ import { flip as I, shift as h } from "../external/@floating-ui/dom/dist/floating-ui.dom.js";
2
2
  import w from "../styles.module.css.js";
3
- import { IS_BROWSER as C, onLoaded as I, on as s, QUICK_EVENT as r, attr as a, anchorPosition as m } from "../utils.js";
4
- const u = "aria-describedby", p = "Escape", d = "aria-labelledby", O = "--mtds-tooltip-position", y = 300, o = C ? document.getElementById("mtds-tooltip") || Object.assign(document.createElement("div"), {
3
+ import { IS_BROWSER as C, tag as O, onLoaded as y, on as s, QUICK_EVENT as r, attr as a, anchorPosition as u } from "../utils.js";
4
+ const m = "aria-describedby", p = "Escape", d = "aria-labelledby", A = "--mtds-tooltip-position", P = 300, T = "mtds-tooltip", o = C ? document.getElementById(T) || O("div", {
5
5
  className: w._tooltip,
6
- id: "mtds-tooltip",
6
+ id: T,
7
7
  popover: "manual"
8
8
  }) : null;
9
- let e = null, f = Number.NEGATIVE_INFINITY, T = 0;
9
+ let e = null, E = Number.NEGATIVE_INFINITY, f = 0;
10
10
  function c({ target: i, type: t, key: n }) {
11
11
  if (t === "keydown" && n !== p) return;
12
- const l = f + y - Date.now();
13
- clearTimeout(T), T = setTimeout(
14
- A,
12
+ const l = E + P - Date.now();
13
+ clearTimeout(f), f = setTimeout(
14
+ S,
15
15
  Math.max(l, 0),
16
16
  n === p ? null : i
17
17
  );
18
18
  }
19
- function A(i) {
20
- if (f = Date.now(), !o || i === o) return;
19
+ function S(i) {
20
+ if (E = Date.now(), !o || i === o) return;
21
21
  o?.isConnected || document.body.append(o);
22
22
  let t = i?.closest?.("[data-tooltip]") || null;
23
23
  if (t === e) return;
24
- const n = t && a(t, "data-tooltip") || "", l = t && a(t, "data-tooltip-position") || window.getComputedStyle(t || document.body).getPropertyValue(O)?.trim() || "top";
24
+ const n = t && a(t, "data-tooltip") || "", l = t && a(t, "data-tooltip-position") || window.getComputedStyle(t || document.body).getPropertyValue(A)?.trim() || "top";
25
25
  (!n || n === "false" || n === "true" || l === "none") && (t = null), t && (o.textContent = n);
26
- const E = e && a(e, d) === o?.id, b = (t instanceof HTMLElement ? t.innerText : t?.textContent)?.trim() || t?.hasAttribute(d) || t?.hasAttribute("aria-label");
27
- e?.removeAttribute(E ? d : u), m(o, !1), e = t, e && a(e, b ? u : d, o?.id), e?.isConnected && o.hidePopover(), o.togglePopover(!!t), m(o, t || !1, {
26
+ const b = e && a(e, d) === o?.id, L = (t instanceof HTMLElement ? t.innerText : t?.textContent)?.trim() || t?.hasAttribute(d) || t?.hasAttribute("aria-label");
27
+ e?.removeAttribute(b ? d : m), u(o, !1), e = t, e && a(e, L ? m : d, o?.id), e?.isConnected && o.hidePopover(), o.togglePopover(!!t), u(o, t || !1, {
28
28
  placement: l,
29
- middleware: [L(), h({ padding: 10 })]
29
+ middleware: [I(), h({ padding: 10 })]
30
30
  });
31
31
  }
32
- I(() => {
32
+ y(() => {
33
33
  s(document, "blur,focus,mouseout,mouseover", c, r), s(window, "keydown", c, r), s(window, "blur", c, r);
34
34
  });
35
35
  //# sourceMappingURL=tooltip-observer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-observer.js","sources":["../../designsystem/tooltip/tooltip-observer.ts"],"sourcesContent":["import { flip, type Placement, shift } from \"@floating-ui/dom\";\nimport styles from \"../styles.module.css\";\nimport {\n\tanchorPosition,\n\tattr,\n\tIS_BROWSER,\n\ton,\n\tonLoaded,\n\tQUICK_EVENT,\n} from \"../utils\";\n\nconst DESCRIBEDBY = \"aria-describedby\";\nconst ESC = \"Escape\";\nconst LABELLEDBY = \"aria-labelledby\";\nconst POSITION_CSS_PROPERTY = \"--mtds-tooltip-position\";\nconst THROTTLE_DELAY = 300;\nconst TOOLTIP = IS_BROWSER\n\t? document.getElementById(\"mtds-tooltip\") ||\n\t\tObject.assign(document.createElement(\"div\"), {\n\t\t\tclassName: styles._tooltip,\n\t\t\tid: \"mtds-tooltip\",\n\t\t\tpopover: \"manual\",\n\t\t})\n\t: null; // Create a dummy element to avoid null checks\n\nlet ANCHOR: Element | null = null;\nlet LAST_CALL = Number.NEGATIVE_INFINITY;\nlet THROTTLE: number | ReturnType<typeof setTimeout> = 0;\n\nfunction handleTooltipMove({ target, type, key }: Event & { key?: string }) {\n\tif (type === \"keydown\" && key !== ESC) return; // Allow ESC dismiss to follow https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/\n\tconst wait = LAST_CALL + THROTTLE_DELAY - Date.now();\n\tclearTimeout(THROTTLE);\n\tTHROTTLE = setTimeout(\n\t\thandleTooltipMoveThrottled,\n\t\tMath.max(wait, 0),\n\t\tkey === ESC ? null : target,\n\t);\n}\n\n// Using a throttled function to avoid performance issues\nfunction handleTooltipMoveThrottled(target: Element | null) {\n\tLAST_CALL = Date.now();\n\n\t// Build and append tooltip if not existing\n\tif (!TOOLTIP || target === TOOLTIP) return; // Allow tooltip to be hovered, following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus\n\tif (!TOOLTIP?.isConnected) document.body.append(TOOLTIP); // Ensure connected\n\tlet anchor = target?.closest?.<Element>(\"[data-tooltip]\") || null;\n\n\t// No need to update\n\tif (anchor === ANCHOR) return;\n\n\tconst content = (anchor && attr(anchor, \"data-tooltip\")) || \"\";\n\tconst position =\n\t\t(anchor && attr(anchor, \"data-tooltip-position\")) ||\n\t\twindow\n\t\t\t.getComputedStyle(anchor || document.body)\n\t\t\t.getPropertyValue(POSITION_CSS_PROPERTY)\n\t\t\t?.trim() ||\n\t\t\"top\";\n\n\tconst isHidden =\n\t\t!content ||\n\t\tcontent === \"false\" ||\n\t\tcontent === \"true\" ||\n\t\tposition === \"none\";\n\n\tif (isHidden) anchor = null; // Do not show tooltip if boolish value\n\tif (anchor) TOOLTIP.textContent = content; // Only update content if new anchor\n\n\tconst hadLabel = ANCHOR && attr(ANCHOR, LABELLEDBY) === TOOLTIP?.id;\n\tconst hasLabel =\n\t\t(anchor instanceof HTMLElement\n\t\t\t? anchor.innerText\n\t\t\t: anchor?.textContent\n\t\t)?.trim() ||\n\t\tanchor?.hasAttribute(LABELLEDBY) ||\n\t\tanchor?.hasAttribute(\"aria-label\");\n\n\tANCHOR?.removeAttribute(hadLabel ? LABELLEDBY : DESCRIBEDBY); // Unlink previous anchor\n\tanchorPosition(TOOLTIP, false); // Reset anchor position\n\n\tANCHOR = anchor; // Store new anchor - might be null if no new anchor\n\tif (ANCHOR) attr(ANCHOR, hasLabel ? DESCRIBEDBY : LABELLEDBY, TOOLTIP?.id); // Use tooltip as description if allready has label\n\tif (ANCHOR?.isConnected) TOOLTIP.hidePopover(); // Hide tooltip so it can be placed on top-layer on next show\n\tTOOLTIP.togglePopover(!!anchor);\n\tanchorPosition(TOOLTIP, anchor || false, {\n\t\tplacement: position as Placement,\n\t\tmiddleware: [flip(), shift({ padding: 10 })],\n\t});\n}\n\nonLoaded(() => {\n\ton(document, \"blur,focus,mouseout,mouseover\", handleTooltipMove, QUICK_EVENT);\n\ton(window, \"keydown\", handleTooltipMove, QUICK_EVENT);\n\ton(window, \"blur\", handleTooltipMove, QUICK_EVENT);\n});\n"],"names":["DESCRIBEDBY","ESC","LABELLEDBY","POSITION_CSS_PROPERTY","THROTTLE_DELAY","TOOLTIP","IS_BROWSER","styles","ANCHOR","LAST_CALL","THROTTLE","handleTooltipMove","target","type","key","wait","handleTooltipMoveThrottled","anchor","content","attr","position","hadLabel","hasLabel","anchorPosition","flip","shift","onLoaded","on","QUICK_EVENT"],"mappings":";;;AAWA,MAAMA,IAAc,oBACdC,IAAM,UACNC,IAAa,mBACbC,IAAwB,2BACxBC,IAAiB,KACjBC,IAAUC,IACb,SAAS,eAAe,cAAc,KACvC,OAAO,OAAO,SAAS,cAAc,KAAK,GAAG;AAAA,EAC5C,WAAWC,EAAO;AAAA,EAClB,IAAI;AAAA,EACJ,SAAS;AACV,CAAC,IACA;AAEH,IAAIC,IAAyB,MACzBC,IAAY,OAAO,mBACnBC,IAAmD;AAEvD,SAASC,EAAkB,EAAE,QAAAC,GAAQ,MAAAC,GAAM,KAAAC,KAAiC;AAC3E,MAAID,MAAS,aAAaC,MAAQb,EAAK;AACvC,QAAMc,IAAON,IAAYL,IAAiB,KAAK,IAAA;AAC/C,eAAaM,CAAQ,GACrBA,IAAW;AAAA,IACVM;AAAA,IACA,KAAK,IAAID,GAAM,CAAC;AAAA,IAChBD,MAAQb,IAAM,OAAOW;AAAA,EAAA;AAEvB;AAGA,SAASI,EAA2BJ,GAAwB;AAI3D,MAHAH,IAAY,KAAK,IAAA,GAGb,CAACJ,KAAWO,MAAWP,EAAS;AACpC,EAAKA,GAAS,eAAa,SAAS,KAAK,OAAOA,CAAO;AACvD,MAAIY,IAASL,GAAQ,UAAmB,gBAAgB,KAAK;AAG7D,MAAIK,MAAWT,EAAQ;AAEvB,QAAMU,IAAWD,KAAUE,EAAKF,GAAQ,cAAc,KAAM,IACtDG,IACJH,KAAUE,EAAKF,GAAQ,uBAAuB,KAC/C,OACE,iBAAiBA,KAAU,SAAS,IAAI,EACxC,iBAAiBd,CAAqB,GACrC,UACH;AAQD,GALC,CAACe,KACDA,MAAY,WACZA,MAAY,UACZE,MAAa,YAEAH,IAAS,OACnBA,QAAgB,cAAcC;AAElC,QAAMG,IAAWb,KAAUW,EAAKX,GAAQN,CAAU,MAAMG,GAAS,IAC3DiB,KACJL,aAAkB,cAChBA,EAAO,YACPA,GAAQ,cACR,KAAA,KACHA,GAAQ,aAAaf,CAAU,KAC/Be,GAAQ,aAAa,YAAY;AAElC,EAAAT,GAAQ,gBAAgBa,IAAWnB,IAAaF,CAAW,GAC3DuB,EAAelB,GAAS,EAAK,GAE7BG,IAASS,GACLT,KAAQW,EAAKX,GAAQc,IAAWtB,IAAcE,GAAYG,GAAS,EAAE,GACrEG,GAAQ,eAAaH,EAAQ,YAAA,GACjCA,EAAQ,cAAc,CAAC,CAACY,CAAM,GAC9BM,EAAelB,GAASY,KAAU,IAAO;AAAA,IACxC,WAAWG;AAAA,IACX,YAAY,CAACI,EAAA,GAAQC,EAAM,EAAE,SAAS,IAAI,CAAC;AAAA,EAAA,CAC3C;AACF;AAEAC,EAAS,MAAM;AACd,EAAAC,EAAG,UAAU,iCAAiChB,GAAmBiB,CAAW,GAC5ED,EAAG,QAAQ,WAAWhB,GAAmBiB,CAAW,GACpDD,EAAG,QAAQ,QAAQhB,GAAmBiB,CAAW;AAClD,CAAC;"}
1
+ {"version":3,"file":"tooltip-observer.js","sources":["../../designsystem/tooltip/tooltip-observer.ts"],"sourcesContent":["import { flip, type Placement, shift } from \"@floating-ui/dom\";\nimport styles from \"../styles.module.css\";\nimport {\n\tanchorPosition,\n\tattr,\n\tIS_BROWSER,\n\ton,\n\tonLoaded,\n\tQUICK_EVENT,\n\ttag,\n} from \"../utils\";\n\nconst DESCRIBEDBY = \"aria-describedby\";\nconst ESC = \"Escape\";\nconst LABELLEDBY = \"aria-labelledby\";\nconst POSITION_CSS_PROPERTY = \"--mtds-tooltip-position\";\nconst THROTTLE_DELAY = 300;\nconst TOOLTIP_ID = \"mtds-tooltip\";\nconst TOOLTIP = IS_BROWSER\n\t? document.getElementById(TOOLTIP_ID) ||\n\t\ttag(\"div\", {\n\t\t\tclassName: styles._tooltip,\n\t\t\tid: TOOLTIP_ID,\n\t\t\tpopover: \"manual\",\n\t\t})\n\t: null;\n\nlet ANCHOR: Element | null = null;\nlet LAST_CALL = Number.NEGATIVE_INFINITY;\nlet THROTTLE: number | ReturnType<typeof setTimeout> = 0;\n\nfunction handleTooltipMove({ target, type, key }: Event & { key?: string }) {\n\tif (type === \"keydown\" && key !== ESC) return; // Allow ESC dismiss to follow https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/\n\tconst wait = LAST_CALL + THROTTLE_DELAY - Date.now();\n\tclearTimeout(THROTTLE);\n\tTHROTTLE = setTimeout(\n\t\thandleTooltipMoveThrottled,\n\t\tMath.max(wait, 0),\n\t\tkey === ESC ? null : target,\n\t);\n}\n\n// Using a throttled function to avoid performance issues\nfunction handleTooltipMoveThrottled(target: Element | null) {\n\tLAST_CALL = Date.now();\n\n\t// Build and append tooltip if not existing\n\tif (!TOOLTIP || target === TOOLTIP) return; // Allow tooltip to be hovered, following https://www.w3.org/TR/WCAG21/#content-on-hover-or-focus\n\tif (!TOOLTIP?.isConnected) document.body.append(TOOLTIP); // Ensure connected\n\tlet anchor = target?.closest?.<Element>(\"[data-tooltip]\") || null;\n\n\t// No need to update\n\tif (anchor === ANCHOR) return;\n\n\tconst content = (anchor && attr(anchor, \"data-tooltip\")) || \"\";\n\tconst position =\n\t\t(anchor && attr(anchor, \"data-tooltip-position\")) ||\n\t\twindow\n\t\t\t.getComputedStyle(anchor || document.body)\n\t\t\t.getPropertyValue(POSITION_CSS_PROPERTY)\n\t\t\t?.trim() ||\n\t\t\"top\";\n\n\tconst isHidden =\n\t\t!content ||\n\t\tcontent === \"false\" ||\n\t\tcontent === \"true\" ||\n\t\tposition === \"none\";\n\n\tif (isHidden) anchor = null; // Do not show tooltip if boolish value\n\tif (anchor) TOOLTIP.textContent = content; // Only update content if new anchor\n\n\tconst hadLabel = ANCHOR && attr(ANCHOR, LABELLEDBY) === TOOLTIP?.id;\n\tconst hasLabel =\n\t\t(anchor instanceof HTMLElement\n\t\t\t? anchor.innerText\n\t\t\t: anchor?.textContent\n\t\t)?.trim() ||\n\t\tanchor?.hasAttribute(LABELLEDBY) ||\n\t\tanchor?.hasAttribute(\"aria-label\");\n\n\tANCHOR?.removeAttribute(hadLabel ? LABELLEDBY : DESCRIBEDBY); // Unlink previous anchor\n\tanchorPosition(TOOLTIP, false); // Reset anchor position\n\n\tANCHOR = anchor; // Store new anchor - might be null if no new anchor\n\tif (ANCHOR) attr(ANCHOR, hasLabel ? DESCRIBEDBY : LABELLEDBY, TOOLTIP?.id); // Use tooltip as description if allready has label\n\tif (ANCHOR?.isConnected) TOOLTIP.hidePopover(); // Hide tooltip so it can be placed on top-layer on next show\n\tTOOLTIP.togglePopover(!!anchor);\n\tanchorPosition(TOOLTIP, anchor || false, {\n\t\tplacement: position as Placement,\n\t\tmiddleware: [flip(), shift({ padding: 10 })],\n\t});\n}\n\nonLoaded(() => {\n\ton(document, \"blur,focus,mouseout,mouseover\", handleTooltipMove, QUICK_EVENT);\n\ton(window, \"keydown\", handleTooltipMove, QUICK_EVENT);\n\ton(window, \"blur\", handleTooltipMove, QUICK_EVENT);\n});\n"],"names":["DESCRIBEDBY","ESC","LABELLEDBY","POSITION_CSS_PROPERTY","THROTTLE_DELAY","TOOLTIP_ID","TOOLTIP","IS_BROWSER","tag","styles","ANCHOR","LAST_CALL","THROTTLE","handleTooltipMove","target","type","key","wait","handleTooltipMoveThrottled","anchor","content","attr","position","hadLabel","hasLabel","anchorPosition","flip","shift","onLoaded","on","QUICK_EVENT"],"mappings":";;;AAYA,MAAMA,IAAc,oBACdC,IAAM,UACNC,IAAa,mBACbC,IAAwB,2BACxBC,IAAiB,KACjBC,IAAa,gBACbC,IAAUC,IACb,SAAS,eAAeF,CAAU,KACnCG,EAAI,OAAO;AAAA,EACV,WAAWC,EAAO;AAAA,EAClB,IAAIJ;AAAA,EACJ,SAAS;AACV,CAAC,IACA;AAEH,IAAIK,IAAyB,MACzBC,IAAY,OAAO,mBACnBC,IAAmD;AAEvD,SAASC,EAAkB,EAAE,QAAAC,GAAQ,MAAAC,GAAM,KAAAC,KAAiC;AAC3E,MAAID,MAAS,aAAaC,MAAQf,EAAK;AACvC,QAAMgB,IAAON,IAAYP,IAAiB,KAAK,IAAA;AAC/C,eAAaQ,CAAQ,GACrBA,IAAW;AAAA,IACVM;AAAA,IACA,KAAK,IAAID,GAAM,CAAC;AAAA,IAChBD,MAAQf,IAAM,OAAOa;AAAA,EAAA;AAEvB;AAGA,SAASI,EAA2BJ,GAAwB;AAI3D,MAHAH,IAAY,KAAK,IAAA,GAGb,CAACL,KAAWQ,MAAWR,EAAS;AACpC,EAAKA,GAAS,eAAa,SAAS,KAAK,OAAOA,CAAO;AACvD,MAAIa,IAASL,GAAQ,UAAmB,gBAAgB,KAAK;AAG7D,MAAIK,MAAWT,EAAQ;AAEvB,QAAMU,IAAWD,KAAUE,EAAKF,GAAQ,cAAc,KAAM,IACtDG,IACJH,KAAUE,EAAKF,GAAQ,uBAAuB,KAC/C,OACE,iBAAiBA,KAAU,SAAS,IAAI,EACxC,iBAAiBhB,CAAqB,GACrC,UACH;AAQD,GALC,CAACiB,KACDA,MAAY,WACZA,MAAY,UACZE,MAAa,YAEAH,IAAS,OACnBA,QAAgB,cAAcC;AAElC,QAAMG,IAAWb,KAAUW,EAAKX,GAAQR,CAAU,MAAMI,GAAS,IAC3DkB,KACJL,aAAkB,cAChBA,EAAO,YACPA,GAAQ,cACR,KAAA,KACHA,GAAQ,aAAajB,CAAU,KAC/BiB,GAAQ,aAAa,YAAY;AAElC,EAAAT,GAAQ,gBAAgBa,IAAWrB,IAAaF,CAAW,GAC3DyB,EAAenB,GAAS,EAAK,GAE7BI,IAASS,GACLT,KAAQW,EAAKX,GAAQc,IAAWxB,IAAcE,GAAYI,GAAS,EAAE,GACrEI,GAAQ,eAAaJ,EAAQ,YAAA,GACjCA,EAAQ,cAAc,CAAC,CAACa,CAAM,GAC9BM,EAAenB,GAASa,KAAU,IAAO;AAAA,IACxC,WAAWG;AAAA,IACX,YAAY,CAACI,EAAA,GAAQC,EAAM,EAAE,SAAS,IAAI,CAAC;AAAA,EAAA,CAC3C;AACF;AAEAC,EAAS,MAAM;AACd,EAAAC,EAAG,UAAU,iCAAiChB,GAAmBiB,CAAW,GAC5ED,EAAG,QAAQ,WAAWhB,GAAmBiB,CAAW,GACpDD,EAAG,QAAQ,QAAQhB,GAAmBiB,CAAW;AAClD,CAAC;"}
package/mtds/utils.d.ts CHANGED
@@ -52,3 +52,16 @@ export declare const isInputLike: (el: unknown) => el is HTMLInputElement;
52
52
  export declare const toCustomElementProps: ({ className, hidden, open, ...rest }: Record<string, unknown>, klass?: string) => {
53
53
  [x: string]: unknown;
54
54
  };
55
+ /**
56
+ * tag
57
+ * @description creates element and assigns properties
58
+ * @param tagName The tagname of element to create
59
+ * @param attrs Optional attributes to add to the element
60
+ * @param text Optional text content to add to the element
61
+ * @return HTMLElement with props
62
+ */
63
+ export declare const tag: <TagName extends keyof HTMLElementTagNameMap>(tagName: TagName, attrs?: Record<string, string | null>, text?: string | null) => HTMLElementTagNameMap[TagName];
64
+ export declare const MTDSElement: {
65
+ new (): HTMLElement;
66
+ prototype: HTMLElement;
67
+ };