haze-ui 1.23.0 → 1.24.1

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 (58) hide show
  1. package/dist/components/BottomSheet/BottomSheet.js +33 -16
  2. package/dist/components/ChatInput/ChatInput.js +1 -1
  3. package/dist/components/Collapsible/Collapsible.js +34 -27
  4. package/dist/components/Combobox/Combobox.js +37 -38
  5. package/dist/components/Command/Command.js +2 -2
  6. package/dist/components/ConfirmDialog/ConfirmDialog.js +60 -42
  7. package/dist/components/ContextMenu/ContextMenu.js +2 -1
  8. package/dist/components/ContextMenu/ContextMenuContent.js +33 -23
  9. package/dist/components/Datepicker/DatepickerCore.js +2 -1
  10. package/dist/components/Dialog/Dialog.js +40 -21
  11. package/dist/components/Drawer/Drawer.js +37 -18
  12. package/dist/components/DropdownMenu/DropdownMenu.js +27 -25
  13. package/dist/components/DropdownMenu/DropdownMenuContent.js +2 -2
  14. package/dist/components/Menu/Menu.js +43 -35
  15. package/dist/components/Popover/Popover.js +27 -25
  16. package/dist/components/StreamingText/StreamingText.js +11 -12
  17. package/dist/components/TagInput/TagInputCore.js +1 -1
  18. package/dist/components/Toast/Toast.js +25 -20
  19. package/dist/components/Toast/ToastContainer.js +31 -24
  20. package/dist/components/Tooltip/Tooltip.js +37 -34
  21. package/dist/css/bottom-sheet.css +1 -1
  22. package/dist/css/collapsible.css +1 -1
  23. package/dist/css/combobox.css +1 -1
  24. package/dist/css/confirm-dialog.css +1 -1
  25. package/dist/css/context-menu.css +1 -1
  26. package/dist/css/datepicker.css +1 -1
  27. package/dist/css/dialog.css +1 -1
  28. package/dist/css/drawer.css +1 -1
  29. package/dist/css/dropdown-menu.css +1 -1
  30. package/dist/css/menu.css +1 -1
  31. package/dist/css/popover.css +1 -1
  32. package/dist/css/toast.css +1 -1
  33. package/dist/css/tokens.css +1 -0
  34. package/dist/css/tool-call-card.css +1 -1
  35. package/dist/css/tooltip.css +1 -1
  36. package/dist/haze-ui.css +15 -14
  37. package/dist/tokens/index.js +2 -1
  38. package/dist/tokens/motion.js +6 -0
  39. package/dist/types/components/BottomSheet/BottomSheet.d.ts +3 -3
  40. package/dist/types/components/Collapsible/Collapsible.d.ts +1 -1
  41. package/dist/types/components/ConfirmDialog/ConfirmDialog.d.ts +3 -3
  42. package/dist/types/components/DropdownMenu/DropdownMenu.d.ts +7 -1
  43. package/dist/types/components/Popover/Popover.d.ts +7 -1
  44. package/dist/types/components/Toast/Toast.d.ts +3 -3
  45. package/dist/types/components/Tooltip/Tooltip.d.ts +4 -1
  46. package/dist/types/tokens/index.d.ts +1 -0
  47. package/dist/types/tokens/motion.d.ts +1 -0
  48. package/dist/types/utils/collision.d.ts +62 -0
  49. package/dist/types/utils/floating.d.ts +95 -19
  50. package/dist/types/utils/focus-scope.d.ts +25 -0
  51. package/dist/types/utils/focus.d.ts +23 -0
  52. package/dist/types/utils/presence.d.ts +22 -0
  53. package/dist/utils/collision.js +73 -0
  54. package/dist/utils/floating.js +193 -150
  55. package/dist/utils/focus-scope.js +63 -0
  56. package/dist/utils/focus.js +34 -0
  57. package/dist/utils/presence.js +72 -0
  58. package/package.json +17 -17
@@ -1,23 +1,40 @@
1
1
 
2
2
  import { classnames as e } from "../../utils/classnames.js";
3
+ import { useFocusScope as t } from "../../utils/focus-scope.js";
4
+ import { Presence as n } from "../../utils/presence.js";
3
5
  /* empty css */
4
- import { jsx as t, jsxs as n } from "react/jsx-runtime";
5
- import { useControl as r } from "react-use-control";
6
+ import { jsx as r, jsxs as i } from "react/jsx-runtime";
7
+ import { useControl as a } from "react-use-control";
6
8
  //#region src/lib/components/BottomSheet/BottomSheet.tsx
7
- var i = "haze-BottomSheet__overlay", a = "haze-BottomSheet__sheet", o = "haze-BottomSheet__handle";
8
- function s({ open: s, onClose: c, children: l, className: u }) {
9
- let [d, f] = r(s, !1);
10
- return d ? /* @__PURE__ */ t("div", {
11
- onClick: () => {
12
- f(!1), c?.();
13
- },
14
- className: e([i, u]),
15
- children: n("div", {
16
- onClick: (e) => e.stopPropagation(),
17
- className: e([a]),
18
- children: [/* @__PURE__ */ t("div", { className: e([o]) }), l]
9
+ var o = "haze-BottomSheet__overlay", s = "haze-BottomSheet__sheet", c = "haze-BottomSheet__handle";
10
+ function l({ open: l, onClose: u, children: d, className: f, ...p }) {
11
+ let [m, h] = a(l, !1), g = t({
12
+ enabled: m,
13
+ trapped: !0
14
+ }), _ = () => {
15
+ h(!1), u?.();
16
+ };
17
+ return /* @__PURE__ */ r(n, {
18
+ present: m,
19
+ children: r("div", {
20
+ onClick: () => {
21
+ m && _();
22
+ },
23
+ onKeyDown: (e) => {
24
+ e.key === "Escape" && m && _();
25
+ },
26
+ className: e([o, f]),
27
+ children: /* @__PURE__ */ i("div", {
28
+ ref: g,
29
+ role: "dialog",
30
+ "aria-modal": "true",
31
+ ...p,
32
+ onClick: (e) => e.stopPropagation(),
33
+ className: e([s]),
34
+ children: [/* @__PURE__ */ r("div", { className: e([c]) }), d]
35
+ })
19
36
  })
20
- }) : null;
37
+ });
21
38
  }
22
39
  //#endregion
23
- export { s as default };
40
+ export { l as default };
@@ -9,7 +9,7 @@ var o = "haze-ChatInput__wrapper", s = "haze-ChatInput__textarea", c = "haze-Cha
9
9
  function l({ value: l, onSend: u, placeholder: d = "Type a message...", disabled: f, maxLength: p, className: m }) {
10
10
  let [h, g] = a(l, ""), _ = i(null), v = r(() => {
11
11
  let e = h.trim();
12
- !e || f || (u?.(e), g(""), _.current && (_.current.style.height = "auto"));
12
+ e && !f && (u?.(e), g(""), _.current && (_.current.style.height = "auto"));
13
13
  }, [
14
14
  h,
15
15
  f,
@@ -1,47 +1,54 @@
1
1
 
2
2
  import { classnames as e } from "../../utils/classnames.js";
3
+ import { Presence as t } from "../../utils/presence.js";
3
4
  /* empty css */
4
- import { jsx as t } from "react/jsx-runtime";
5
- import { createContext as n, useContext as r } from "react";
6
- import { useControl as i } from "react-use-control";
5
+ import { jsx as n } from "react/jsx-runtime";
6
+ import { createContext as r, useContext as i } from "react";
7
+ import { useControl as a } from "react-use-control";
7
8
  //#region src/lib/components/Collapsible/Collapsible.tsx
8
- var a = n(void 0);
9
- function o() {
10
- let e = r(a);
9
+ var o = r(void 0);
10
+ function s() {
11
+ let e = i(o);
11
12
  if (!e) throw Error("Collapsible sub-components must be used within <Collapsible>");
12
13
  return e;
13
14
  }
14
- var s = "haze-Collapsible__base";
15
- function c({ open: n, defaultOpen: r = !1, children: o, className: c }) {
16
- let [l, u] = i(n, r);
17
- return /* @__PURE__ */ t(a.Provider, {
15
+ var c = "haze-Collapsible__base";
16
+ function l({ open: t, defaultOpen: r = !1, children: i, className: s }) {
17
+ let [l, u] = a(t, r);
18
+ return /* @__PURE__ */ n(o.Provider, {
18
19
  value: {
19
20
  open: l,
20
21
  toggle: () => u((e) => !e)
21
22
  },
22
- children: t("div", {
23
- className: e([s, c]),
24
- children: o
23
+ children: n("div", {
24
+ className: e([c, s]),
25
+ children: i
25
26
  })
26
27
  });
27
28
  }
28
- var l = "haze-Collapsible__triggerStyle";
29
- function u({ children: n, className: r }) {
30
- let { toggle: i } = o();
31
- return /* @__PURE__ */ t("button", {
29
+ var u = "haze-Collapsible__triggerStyle";
30
+ function d({ children: t, className: r }) {
31
+ let { toggle: i } = s();
32
+ return /* @__PURE__ */ n("button", {
32
33
  type: "button",
33
34
  onClick: i,
34
- className: e([l, r]),
35
- children: n
35
+ className: e([u, r]),
36
+ children: t
36
37
  });
37
38
  }
38
- var d = "haze-Collapsible__contentStyle";
39
- function f({ children: n, className: r }) {
40
- let { open: i } = o();
41
- return i ? /* @__PURE__ */ t("div", {
42
- className: e([d, r]),
43
- children: n
44
- }) : null;
39
+ var f = "haze-Collapsible__contentOuter", p = "haze-Collapsible__contentInner";
40
+ function m({ children: r, className: i }) {
41
+ let { open: a } = s();
42
+ return /* @__PURE__ */ n(t, {
43
+ present: a,
44
+ children: n("div", {
45
+ className: e([f, i]),
46
+ children: /* @__PURE__ */ n("div", {
47
+ className: e(p),
48
+ children: r
49
+ })
50
+ })
51
+ });
45
52
  }
46
53
  //#endregion
47
- export { c as Collapsible, f as CollapsibleContent, u as CollapsibleTrigger };
54
+ export { l as Collapsible, m as CollapsibleContent, d as CollapsibleTrigger };
@@ -4,61 +4,60 @@ import { FloatingPanel as t, useFloating as n } from "../../utils/floating.js";
4
4
  import r from "./ComboboxOption.js";
5
5
  /* empty css */
6
6
  import { jsx as i, jsxs as a } from "react/jsx-runtime";
7
- import { useEffect as o, useId as s, useRef as c, useState as l } from "react";
8
- import { useControl as u } from "react-use-control";
7
+ import { useId as o, useRef as s, useState as c } from "react";
8
+ import { useControl as l } from "react-use-control";
9
9
  //#region src/lib/components/Combobox/Combobox.tsx
10
- var d = "haze-Combobox__wrapper", f = "haze-Combobox__input", p = "haze-Combobox__listbox";
11
- function m({ value: m, open: h, options: g, placeholder: _, className: v }) {
12
- let [y, b] = u(m, ""), [x, S] = l(""), [C, w] = u(h, !1), [T, E] = l(-1), D = s(), O = c(null), k = c(null), A = n({
13
- open: C,
14
- setOpen: w,
15
- triggerRef: O,
16
- panelRef: k
17
- }), j = g.filter((e) => e.label.toLowerCase().includes(x.toLowerCase()));
18
- o(() => {
19
- E(-1);
20
- }, [x]);
21
- let M = (e) => {
22
- b(e);
23
- let t = g.find((t) => t.value === e)?.label ?? e;
24
- S(t), w(!1), O.current?.focus();
10
+ var u = "haze-Combobox__wrapper", d = "haze-Combobox__input", f = "haze-Combobox__listbox";
11
+ function p({ value: p, open: m, options: h, placeholder: g, className: _ }) {
12
+ let [v, y] = l(p, ""), [b, x] = c(""), [S, C] = l(m, !1), [w, T] = c(-1), [E, D] = c(b), O = o(), k = s(null), A = s(null), j = n({
13
+ open: S,
14
+ setOpen: C,
15
+ triggerRef: k,
16
+ panelRef: A,
17
+ animated: !0
18
+ }), M = h.filter((e) => e.label.toLowerCase().includes(b.toLowerCase()));
19
+ b !== E && (D(b), T(-1));
20
+ let N = (e) => {
21
+ y(e);
22
+ let t = h.find((t) => t.value === e)?.label ?? e;
23
+ x(t), C(!1), k.current?.focus();
25
24
  };
26
25
  return /* @__PURE__ */ a("div", {
27
- className: e([d, v]),
26
+ className: e([u, _]),
28
27
  children: [/* @__PURE__ */ i("input", {
29
- ref: O,
28
+ ref: k,
30
29
  role: "combobox",
31
- style: A.triggerStyle,
32
- "aria-expanded": C,
33
- "aria-controls": D,
30
+ style: j.triggerStyle,
31
+ "aria-expanded": S,
32
+ "aria-controls": O,
34
33
  "aria-autocomplete": "list",
35
- className: f,
36
- value: x,
37
- placeholder: _,
34
+ className: d,
35
+ value: b,
36
+ placeholder: g,
38
37
  onChange: (e) => {
39
- S(e.target.value), w(!0);
38
+ x(e.target.value), C(!0);
40
39
  },
41
- onFocus: () => w(!0),
42
- onClick: () => w(!0),
40
+ onFocus: () => C(!0),
41
+ onClick: () => C(!0),
43
42
  onKeyDown: (e) => {
44
- e.key === "ArrowDown" ? (e.preventDefault(), E((e) => Math.min(e + 1, j.length - 1))) : e.key === "ArrowUp" ? (e.preventDefault(), E((e) => Math.max(e - 1, 0))) : e.key === "Enter" && T >= 0 && j[T] ? (e.preventDefault(), M(j[T].value)) : e.key === "Escape" && w(!1);
43
+ e.key === "ArrowDown" ? (e.preventDefault(), T((e) => Math.min(e + 1, M.length - 1))) : e.key === "ArrowUp" ? (e.preventDefault(), T((e) => Math.max(e - 1, 0))) : e.key === "Enter" && w >= 0 && M[w] ? (e.preventDefault(), N(M[w].value)) : e.key === "Escape" && C(!1);
45
44
  }
46
45
  }), /* @__PURE__ */ i(t, {
47
- ref: k,
48
- behavior: A,
46
+ ref: A,
47
+ behavior: j,
49
48
  placement: "bottom-span",
50
- id: D,
49
+ id: O,
51
50
  role: "listbox",
52
- visualClass: p,
53
- children: j.map((e, t) => /* @__PURE__ */ i(r, {
51
+ visualClass: f,
52
+ children: M.map((e, t) => /* @__PURE__ */ i(r, {
54
53
  value: e.value,
55
- highlighted: t === T,
56
- selected: e.value === y,
57
- onSelect: M,
54
+ highlighted: t === w,
55
+ selected: e.value === v,
56
+ onSelect: N,
58
57
  children: e.label
59
58
  }, e.value))
60
59
  })]
61
60
  });
62
61
  }
63
62
  //#endregion
64
- export { m as default };
63
+ export { p as default };
@@ -79,7 +79,7 @@ function y({ children: t, className: a }) {
79
79
  var b = "haze-Command__itemStyle";
80
80
  function x({ children: t, className: n, onSelect: r }) {
81
81
  let { query: a } = p();
82
- return !a || (typeof t == "string" ? t : "").toLowerCase().includes(a.toLowerCase()) ? /* @__PURE__ */ i("div", {
82
+ return a && !(typeof t == "string" ? t : "").toLowerCase().includes(a.toLowerCase()) ? null : /* @__PURE__ */ i("div", {
83
83
  role: "option",
84
84
  tabIndex: -1,
85
85
  onClick: r,
@@ -88,7 +88,7 @@ function x({ children: t, className: n, onSelect: r }) {
88
88
  },
89
89
  className: e([b, n]),
90
90
  children: t
91
- }) : null;
91
+ });
92
92
  }
93
93
  //#endregion
94
94
  export { _ as CommandInput, x as CommandItem, y as CommandList, h as default };
@@ -1,52 +1,70 @@
1
1
 
2
2
  import { classnames as e } from "../../utils/classnames.js";
3
+ import { useFocusScope as t } from "../../utils/focus-scope.js";
4
+ import { Presence as n } from "../../utils/presence.js";
3
5
  /* empty css */
4
- import { jsx as t, jsxs as n } from "react/jsx-runtime";
5
- import { useControl as r } from "react-use-control";
6
+ import { jsx as r, jsxs as i } from "react/jsx-runtime";
7
+ import { useId as a } from "react";
8
+ import { useControl as o } from "react-use-control";
6
9
  //#region src/lib/components/ConfirmDialog/ConfirmDialog.tsx
7
- var i = "haze-ConfirmDialog__overlay", a = "haze-ConfirmDialog__dialog", o = "haze-ConfirmDialog__header", s = "haze-ConfirmDialog__body", c = "haze-ConfirmDialog__footer", l = "haze-ConfirmDialog__btn", u = "haze-ConfirmDialog__cancelBtn", d = "haze-ConfirmDialog__confirmBtn", f = "haze-ConfirmDialog__dangerBtn";
8
- function p({ open: p, onClose: m, onConfirm: h, onCancel: g, title: _, children: v, confirmText: y = "Confirm", cancelText: b = "Cancel", variant: x = "default", className: S }) {
9
- let [C, w] = r(p, !1);
10
- if (!C) return null;
11
- let T = () => {
12
- w(!1), m?.();
10
+ var s = "haze-ConfirmDialog__overlay", c = "haze-ConfirmDialog__dialog", l = "haze-ConfirmDialog__header", u = "haze-ConfirmDialog__body", d = "haze-ConfirmDialog__footer", f = "haze-ConfirmDialog__btn", p = "haze-ConfirmDialog__cancelBtn", m = "haze-ConfirmDialog__confirmBtn", h = "haze-ConfirmDialog__dangerBtn";
11
+ function g({ open: g, onClose: _, onConfirm: v, onCancel: y, title: b, children: x, confirmText: S = "Confirm", cancelText: C = "Cancel", variant: w = "default", className: T, ...E }) {
12
+ let [D, O] = o(g, !1), k = t({
13
+ enabled: D,
14
+ trapped: !0
15
+ }), A = `haze-confirm-title-${a()}`, j = () => {
16
+ O(!1), _?.();
17
+ }, M = () => {
18
+ y?.(), j();
19
+ }, N = () => {
20
+ v?.(), j();
13
21
  };
14
- return /* @__PURE__ */ t("div", {
15
- onClick: T,
16
- className: e([i, S]),
17
- children: n("div", {
18
- onClick: (e) => e.stopPropagation(),
19
- className: e([a]),
20
- children: [
21
- _ && /* @__PURE__ */ t("div", {
22
- className: e([o]),
23
- children: _
24
- }),
25
- /* @__PURE__ */ t("div", {
26
- className: e([s]),
27
- children: v
28
- }),
29
- /* @__PURE__ */ n("div", {
30
- className: e([c]),
31
- children: [/* @__PURE__ */ t("button", {
32
- type: "button",
33
- onClick: () => {
34
- g?.(), T();
35
- },
36
- className: e([l, u]),
22
+ return /* @__PURE__ */ r(n, {
23
+ present: D,
24
+ children: r("div", {
25
+ onClick: () => {
26
+ D && j();
27
+ },
28
+ onKeyDown: (e) => {
29
+ e.key === "Escape" && D && j();
30
+ },
31
+ className: e([s, T]),
32
+ children: /* @__PURE__ */ i("div", {
33
+ ref: k,
34
+ role: "dialog",
35
+ "aria-modal": "true",
36
+ "aria-labelledby": b === void 0 ? void 0 : A,
37
+ ...E,
38
+ onClick: (e) => e.stopPropagation(),
39
+ className: e([c]),
40
+ children: [
41
+ b && /* @__PURE__ */ r("div", {
42
+ id: A,
43
+ className: e([l]),
37
44
  children: b
38
- }), /* @__PURE__ */ t("button", {
39
- type: "button",
40
- onClick: () => {
41
- h?.(), T();
42
- },
43
- className: e([l, x === "danger" ? f : d]),
44
- children: y
45
- })]
46
- })
47
- ]
45
+ }),
46
+ /* @__PURE__ */ r("div", {
47
+ className: e([u]),
48
+ children: x
49
+ }),
50
+ /* @__PURE__ */ i("div", {
51
+ className: e([d]),
52
+ children: [/* @__PURE__ */ r("button", {
53
+ type: "button",
54
+ onClick: M,
55
+ className: e([f, p]),
56
+ children: C
57
+ }), /* @__PURE__ */ r("button", {
58
+ type: "button",
59
+ onClick: N,
60
+ className: e([f, w === "danger" ? h : m]),
61
+ children: S
62
+ })]
63
+ })
64
+ ]
65
+ })
48
66
  })
49
67
  });
50
68
  }
51
69
  //#endregion
52
- export { p as default };
70
+ export { g as default };
@@ -22,7 +22,8 @@ function l({ open: l, onOpenChange: u, children: d, className: f }) {
22
22
  open: p,
23
23
  setOpen: x,
24
24
  triggerRef: y,
25
- panelRef: b
25
+ panelRef: b,
26
+ animated: !0
26
27
  });
27
28
  return /* @__PURE__ */ r(n, {
28
29
  value: {
@@ -1,32 +1,42 @@
1
1
 
2
- import { FloatingPanel as e } from "../../utils/floating.js";
3
- import { useMenuKeyboard as t, useRovingTabindex as n } from "../../utils/menuKeyboard.js";
4
- import { useContextMenuContext as r } from "./ContextMenuContext.js";
2
+ import { useFocusScope as e } from "../../utils/focus-scope.js";
3
+ import { FloatingPanel as t } from "../../utils/floating.js";
4
+ import { useMenuKeyboard as n, useRovingTabindex as r } from "../../utils/menuKeyboard.js";
5
+ import { useContextMenuContext as i } from "./ContextMenuContext.js";
5
6
  /* empty css */
6
- import { jsx as i } from "react/jsx-runtime";
7
+ import { jsx as a } from "react/jsx-runtime";
8
+ import { useCallback as o } from "react";
7
9
  //#region src/lib/components/ContextMenu/ContextMenuContent.tsx
8
- var a = "haze-ContextMenuContent__content";
9
- function o({ children: o, className: s }) {
10
- let { open: c, setOpen: l, x: u, y: d, contentRef: f, floating: p } = r(), m = t({
11
- menuRef: f,
12
- onClose: () => l(!1)
10
+ var s = "haze-ContextMenuContent__content";
11
+ function c({ children: c, className: l }) {
12
+ let { open: u, setOpen: d, x: f, y: p, contentRef: m, floating: h } = i(), g = n({
13
+ menuRef: m,
14
+ onClose: () => d(!1)
13
15
  });
14
- return n({
15
- menuRef: f,
16
- active: c
17
- }), c ? /* @__PURE__ */ i(e, {
18
- ref: f,
19
- behavior: p,
16
+ r({
17
+ menuRef: m,
18
+ active: u
19
+ });
20
+ let _ = e({
21
+ enabled: u && h.shown,
22
+ autoFocus: !0,
23
+ returnFocus: !0
24
+ }), v = o((e) => {
25
+ m.current = e, _(e);
26
+ }, [m, _]);
27
+ return !u && h.exited ? null : /* @__PURE__ */ a(t, {
28
+ ref: v,
29
+ behavior: h,
20
30
  role: "menu",
21
- visualClass: a,
22
- className: s,
31
+ visualClass: s,
32
+ className: l,
23
33
  style: {
24
- left: u,
25
- top: d
34
+ left: f,
35
+ top: p
26
36
  },
27
- onKeyDown: m,
28
- children: o
29
- }) : null;
37
+ onKeyDown: g,
38
+ children: c
39
+ });
30
40
  }
31
41
  //#endregion
32
- export { o as default };
42
+ export { c as default };
@@ -12,7 +12,8 @@ function f({ value: f, onChange: p, open: m, onOpenChange: h, min: g, max: _, pl
12
12
  open: m,
13
13
  setOpen: C,
14
14
  triggerRef: b,
15
- panelRef: x
15
+ panelRef: x,
16
+ animated: !0
16
17
  });
17
18
  return /* @__PURE__ */ a("div", {
18
19
  className: e([l, y]),
@@ -1,32 +1,51 @@
1
1
 
2
2
  import { classnames as e } from "../../utils/classnames.js";
3
+ import { useFocusScope as t } from "../../utils/focus-scope.js";
4
+ import { whenExitSettles as n } from "../../utils/presence.js";
3
5
  /* empty css */
4
- import { jsx as t, jsxs as n } from "react/jsx-runtime";
5
- import { useEffect as r, useId as i, useRef as a } from "react";
6
- import { useControl as o } from "react-use-control";
6
+ import { jsx as r, jsxs as i } from "react/jsx-runtime";
7
+ import { useCallback as a, useEffect as o, useId as s, useRef as c } from "react";
8
+ import { useControl as l } from "react-use-control";
7
9
  //#region src/lib/components/Dialog/Dialog.tsx
8
- var s = "haze-Dialog__overlay", c = "haze-Dialog__titleText";
9
- function l({ open: l, onClose: u, title: d, className: f, children: p }) {
10
- let [m, h] = o(l, !1), g = a(null), _ = a(null), v = `haze-dialog-title-${i()}`;
11
- return r(() => {
12
- let e = g.current;
13
- e && (m && !e.open ? (_.current = document.activeElement instanceof HTMLElement ? document.activeElement : null, e.showModal()) : !m && e.open && e.close());
14
- }, [m]), /* @__PURE__ */ n("dialog", {
15
- ref: g,
16
- "aria-labelledby": d === void 0 ? void 0 : v,
10
+ var u = "haze-Dialog__overlay", d = "haze-Dialog__titleText";
11
+ function f({ open: f, onClose: p, title: m, className: h, children: g }) {
12
+ let [_, v] = l(f, !1), y = c(null), b = t({
13
+ enabled: _,
14
+ trapped: !1
15
+ }), x = `haze-dialog-title-${s()}`, S = a((e) => {
16
+ y.current = e, b(e);
17
+ }, [b]);
18
+ return o(() => {
19
+ let e = y.current;
20
+ if (e) {
21
+ if (_ && !e.open) e.showModal();
22
+ else if (!_ && e.open) {
23
+ let t = n(e), r = () => {
24
+ e.getAttribute("data-state") === "closed" && e.close();
25
+ };
26
+ t ? t.then(r) : r();
27
+ }
28
+ }
29
+ }, [_]), /* @__PURE__ */ i("dialog", {
30
+ ref: S,
31
+ "data-state": _ ? "open" : "closed",
32
+ "aria-labelledby": m === void 0 ? void 0 : x,
17
33
  onClose: () => {
18
- h(!1), _.current?.focus(), _.current = null, u?.();
34
+ v(!1), p?.();
35
+ },
36
+ onCancel: (e) => {
37
+ e.preventDefault(), v(!1);
19
38
  },
20
39
  onClick: (e) => {
21
- e.target === g.current && h(!1);
40
+ e.target === y.current && v(!1);
22
41
  },
23
- className: e([s, f]),
24
- children: [d !== void 0 && /* @__PURE__ */ t("h2", {
25
- id: v,
26
- className: e([c]),
27
- children: d
28
- }), p]
42
+ className: e([u, h]),
43
+ children: [m !== void 0 && /* @__PURE__ */ r("h2", {
44
+ id: x,
45
+ className: e([d]),
46
+ children: m
47
+ }), g]
29
48
  });
30
49
  }
31
50
  //#endregion
32
- export { l as default };
51
+ export { f as default };
@@ -1,36 +1,55 @@
1
1
 
2
2
  import { classnames as e } from "../../utils/classnames.js";
3
+ import { useFocusScope as t } from "../../utils/focus-scope.js";
4
+ import { whenExitSettles as n } from "../../utils/presence.js";
3
5
  /* empty css */
4
- import { jsx as t } from "react/jsx-runtime";
5
- import { useEffect as n, useRef as r } from "react";
6
- import { useControl as i } from "react-use-control";
6
+ import { jsx as r } from "react/jsx-runtime";
7
+ import { useCallback as i, useEffect as a, useRef as o } from "react";
8
+ import { useControl as s } from "react-use-control";
7
9
  //#region src/lib/components/Drawer/Drawer.tsx
8
- var a = "haze-Drawer__overlay", o = {
10
+ var c = "haze-Drawer__overlay", l = {
9
11
  left: "haze-Drawer__left",
10
12
  right: "haze-Drawer__right",
11
13
  top: "haze-Drawer__top",
12
14
  bottom: "haze-Drawer__bottom"
13
15
  };
14
- function s({ open: s, placement: c = "right", onClose: l, className: u, children: d }) {
15
- let [f, p] = i(s, !1), m = r(null);
16
- return n(() => {
17
- let e = m.current;
18
- e && (f && !e.open ? e.showModal() : !f && e.open && e.close());
19
- }, [f]), /* @__PURE__ */ t("dialog", {
20
- ref: m,
16
+ function u({ open: u, placement: d = "right", onClose: f, className: p, children: m }) {
17
+ let [h, g] = s(u, !1), _ = o(null), v = t({
18
+ enabled: h,
19
+ trapped: !1
20
+ }), y = i((e) => {
21
+ _.current = e, v(e);
22
+ }, [v]);
23
+ return a(() => {
24
+ let e = _.current;
25
+ if (e) {
26
+ if (h && !e.open) e.showModal();
27
+ else if (!h && e.open) {
28
+ let t = n(e), r = () => {
29
+ e.getAttribute("data-state") === "closed" && e.close();
30
+ };
31
+ t ? t.then(r) : r();
32
+ }
33
+ }
34
+ }, [h]), /* @__PURE__ */ r("dialog", {
35
+ ref: y,
36
+ "data-state": h ? "open" : "closed",
21
37
  onClose: () => {
22
- p(!1), l?.();
38
+ g(!1), f?.();
39
+ },
40
+ onCancel: (e) => {
41
+ e.preventDefault(), g(!1);
23
42
  },
24
43
  onClick: (e) => {
25
- e.target === m.current && (p(!1), l?.());
44
+ e.target === _.current && g(!1);
26
45
  },
27
46
  className: e([
28
- a,
29
- o[c],
30
- u
47
+ c,
48
+ l[d],
49
+ p
31
50
  ]),
32
- children: d
51
+ children: m
33
52
  });
34
53
  }
35
54
  //#endregion
36
- export { s as default };
55
+ export { u as default };