@kakadu/components 4.2.0 → 4.2.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.
@@ -30,10 +30,11 @@ export type ModalProperties<Data = any> = {
30
30
  readonly children?: ReactNode;
31
31
  };
32
32
  type ModalBaseProperties<ModalResult> = Omit<ModalProperties<ModalResult>, 'isVisible' | 'onClose'>;
33
- export default function Modal<Data = any>({ root, outerDecorators, innerDecorators, label, maxWidth, className, isVisible, isFullWidth, shouldCloseOnOutsideClick, shouldCloseOnEscapePress, showCloseButton, onClose, children, }: ModalProperties<Data>): import("react/jsx-runtime").JSX.Element;
33
+ export default function Modal<Data = any>({ root, outerDecorators, innerDecorators, label, maxWidth, className, isVisible, isFullWidth, shouldCloseOnOutsideClick, shouldCloseOnEscapePress, showCloseButton, onClose, children, }: ModalProperties<Data>): import("react/jsx-runtime").JSX.Element | null;
34
34
  export declare function useModal<ModalResult, ModalProperties = ModalBaseProperties<ModalResult>>(ModalComponent: ComponentType<ModalProperties>, properties?: ModalProperties): {
35
35
  isVisible: boolean;
36
36
  show: () => Promise<ModalResult | undefined>;
37
- modal: import("react/jsx-runtime").JSX.Element;
37
+ close: (result?: ModalResult) => void;
38
+ modal: import("react/jsx-runtime").JSX.Element | null;
38
39
  };
39
40
  export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),k=require("@kuma-ui/core"),P=require("react-dom"),$=require("../focus-trap-react-B7f3iC5h.js"),B=require("./text-button.js"),T=require("./decorators.js"),I=require("./flex.js"),D=require("./atom.js"),C=require("./text.js"),y=e.createContext({isVisible:!1,isInteractive:!1}),{Provider:z}=y;function _(){return e.useContext(y)}function G(){const{isInteractive:n,close:o}=_(),r=e.useCallback(()=>{o==null||o()},[o]);return s.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2566044647",children:s.jsxRuntimeExports.jsx(B.default,{iconLeft:"times",label:"Close",disabled:!n,onClick:r})})}function J(n){return s.jsxRuntimeExports.jsx(I.default,{gap:2,...n})}function K({as:n,className:o,...r}){return s.jsxRuntimeExports.jsx(C.Heading,{...r,as:n??C.defaultHeadingElementType,className:k.cx("kakadu-components-4275938488",o)})}function Q({as:n,...o}){return s.jsxRuntimeExports.jsx(I.default,{direction:"row",gap:1,preset:"end",...o,as:n??D.defaultAtomElementType})}function U({root:n,outerDecorators:o=[],innerDecorators:r=[],label:f,maxWidth:c,className:m,isVisible:a,isFullWidth:l=!1,shouldCloseOnOutsideClick:i=!0,shouldCloseOnEscapePress:d=!0,showCloseButton:L=!0,onClose:p,children:N}){const v=e.useRef(null),R=e.useRef(null),[M,S]=e.useState(!1),[u,x]=e.useState(!1),b=e.useCallback(t=>{v.current=t,x(!1)},[]),E=e.useRef(null),g=e.useCallback(t=>{t&&(E.current=t)},[]),[h,q]=e.useState(a??!1),A=e.useMemo(()=>({isVisible:h,isInteractive:u,setInitialFocus:g,close:b}),[h,u,g,b]);e.useEffect(()=>{a&&(S(!0),q(!0))},[a]),e.useEffect(()=>{if(a){const t=setTimeout(()=>{x(!0)},100);return()=>{clearTimeout(t)}}x(!1)},[a]),e.useEffect(()=>{if(M&&!u){const t=setTimeout(()=>{p==null||p(v.current??void 0),q(!1)},370);return()=>{clearTimeout(t)}}},[M,u,p]),e.useEffect(()=>{const t=R.current;if(a&&i&&t){const j=H=>{t===H.target&&x(!1)};return t.addEventListener("click",j),()=>{t.removeEventListener("click",j)}}},[a,i]),e.useEffect(()=>{if(!a||!d)return;const t=j=>{j.key==="Escape"&&x(!1)};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[a,d]);const F=e.useMemo(()=>({initialFocus:()=>E.current??void 0,onActivate:()=>{var t;return(t=E.current)==null?void 0:t.focus()}}),[]),w=s.jsxRuntimeExports.jsx(T.default,{decorators:o,children:s.jsxRuntimeExports.jsx("div",{"aria-hidden":!u,style:{"--max-width":c?`${c}px`:void 0},className:k.cx("kakadu-components-4119461136",u&&"kakadu-components-2522346797",m),children:s.jsxRuntimeExports.jsx(T.default,{decorators:r,children:s.jsxRuntimeExports.jsx($.focusTrapReactExports.FocusTrap,{active:u,focusTrapOptions:F,children:s.jsxRuntimeExports.jsx("div",{ref:R,className:"kakadu-components-4011815997",children:s.jsxRuntimeExports.jsx("div",{role:"dialog","aria-modal":"true","aria-label":f??"Modal",className:k.cx("kakadu-components-3324483532",l&&"kakadu-components-3799971070",u&&"kakadu-components-968755580"),children:s.jsxRuntimeExports.jsxs(z,{value:A,children:[L?s.jsxRuntimeExports.jsx(G,{}):null,s.jsxRuntimeExports.jsx("div",{className:k.cx("kakadu-components-633990035",l&&"kakadu-components-171969824"),children:N})]})})})})})})});return n?P.createPortal(w,n):w}function V(n,o){const[r,f]=e.useState(!1),c=e.useRef(void 0),m=e.useCallback(async()=>(f(!0),new Promise(i=>{c.current=i})),[]),a=e.useCallback(i=>{var d;f(!1),(d=c.current)==null||d.call(c,i),c.current=void 0},[]),l=e.useMemo(()=>s.jsxRuntimeExports.jsx(n,{...o,isVisible:r,onClose:a}),[n,o,r,a]);return e.useMemo(()=>({isVisible:r,show:m,modal:l}),[r,m,l])}exports.ModalActions=Q;exports.ModalContent=J;exports.ModalHeading=K;exports.default=U;exports.useModal=V;exports.useModalContext=_;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),M=require("@kuma-ui/core"),P=require("react-dom"),$=require("../focus-trap-react-B7f3iC5h.js"),B=require("./text-button.js"),T=require("./decorators.js"),S=require("./flex.js"),D=require("./atom.js"),y=require("./text.js"),_=e.createContext({isVisible:!1,isInteractive:!1}),{Provider:z}=_;function L(){return e.useContext(_)}function G(){const{isInteractive:o,close:r}=L(),a=e.useCallback(()=>{r==null||r()},[r]);return n.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2566044647",children:n.jsxRuntimeExports.jsx(B.default,{iconLeft:"times",label:"Close",disabled:!o,onClick:a})})}function J(o){return n.jsxRuntimeExports.jsx(S.default,{gap:2,...o})}function K({as:o,className:r,...a}){return n.jsxRuntimeExports.jsx(y.Heading,{...a,as:o??y.defaultHeadingElementType,className:M.cx("kakadu-components-4275938488",r)})}function Q({as:o,...r}){return n.jsxRuntimeExports.jsx(S.default,{direction:"row",gap:1,preset:"end",...r,as:o??D.defaultAtomElementType})}function U({root:o,outerDecorators:r=[],innerDecorators:a=[],label:j,maxWidth:c,className:k,isVisible:s,isFullWidth:i=!1,shouldCloseOnOutsideClick:f=!0,shouldCloseOnEscapePress:x=!0,showCloseButton:v=!0,onClose:l,children:d}){const R=e.useRef(null),m=e.useRef(null),[h,N]=e.useState(!1),[u,p]=e.useState(!1),q=e.useCallback(t=>{R.current=t,p(!1)},[]),b=e.useRef(null),w=e.useCallback(t=>{t&&(b.current=t)},[]),[g,C]=e.useState(s??!1),A=e.useMemo(()=>({isVisible:g,isInteractive:u,setInitialFocus:w,close:q}),[g,u,w,q]);e.useEffect(()=>{if(s){const t=setTimeout(()=>{p(!0)},100);return()=>{clearTimeout(t)}}p(!1)},[s]),e.useEffect(()=>{s&&(N(!0),C(!0))},[s]),e.useEffect(()=>{const t=m.current;if(s&&f&&t){const E=H=>{t===H.target&&p(!1)};return t.addEventListener("click",E),()=>{t.removeEventListener("click",E)}}},[s,f]),e.useEffect(()=>{if(!s||!x)return;const t=E=>{E.key==="Escape"&&p(!1)};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[s,x]),e.useEffect(()=>{if(h&&!u){const t=setTimeout(()=>{C(!1),l==null||l(R.current??void 0)},370);return()=>{clearTimeout(t)}}},[h,u,l]);const F=e.useMemo(()=>({initialFocus:()=>b.current??void 0,onActivate:()=>{var t;return(t=b.current)==null?void 0:t.focus()}}),[]);if(!g)return null;const I=n.jsxRuntimeExports.jsx(T.default,{decorators:r,children:n.jsxRuntimeExports.jsx("div",{"aria-hidden":!u,style:{"--max-width":c?`${c}px`:void 0},className:M.cx("kakadu-components-4119461136",u&&"kakadu-components-2522346797",k),children:n.jsxRuntimeExports.jsx(T.default,{decorators:a,children:n.jsxRuntimeExports.jsx($.focusTrapReactExports.FocusTrap,{active:u,focusTrapOptions:F,children:n.jsxRuntimeExports.jsx("div",{ref:m,className:"kakadu-components-4011815997",children:n.jsxRuntimeExports.jsx("div",{role:"dialog","aria-modal":"true","aria-label":j??"Modal",className:M.cx("kakadu-components-3324483532",i&&"kakadu-components-3799971070",u&&"kakadu-components-968755580"),children:n.jsxRuntimeExports.jsxs(z,{value:A,children:[v?n.jsxRuntimeExports.jsx(G,{}):null,n.jsxRuntimeExports.jsx("div",{className:M.cx("kakadu-components-633990035",i&&"kakadu-components-171969824"),children:d})]})})})})})})});return o?P.createPortal(I,o):I}function V(o,r){const[a,j]=e.useState(!1),[c,k]=e.useState(!1),s=e.useRef(void 0),i=e.useRef(void 0),f=e.useCallback(async()=>(i.current=void 0,j(!0),k(!0),new Promise(d=>{s.current=d})),[]),x=e.useCallback(d=>{i.current=d,k(!1)},[]),v=e.useCallback(d=>{var m;const R=d??i.current;i.current=void 0,(m=s.current)==null||m.call(s,R),s.current=void 0,j(!1)},[]),l=e.useMemo(()=>a?n.jsxRuntimeExports.jsx(o,{...r,isVisible:c,onClose:v}):null,[a,o,r,c,v]);return e.useMemo(()=>({isVisible:c,show:f,close:x,modal:l}),[c,f,x,l])}exports.ModalActions=Q;exports.ModalContent=J;exports.ModalHeading=K;exports.default=U;exports.useModal=V;exports.useModalContext=L;
@@ -1,139 +1,146 @@
1
- import { j as t } from "../jsx-runtime-B4hRZ52C.mjs";
2
- import { createContext as q, useRef as j, useState as h, useCallback as f, useMemo as I, useEffect as m, useContext as z } from "react";
3
- import { cx as w } from "@kuma-ui/core";
1
+ import { j as n } from "../jsx-runtime-B4hRZ52C.mjs";
2
+ import { createContext as q, useRef as v, useState as j, useCallback as d, useMemo as g, useEffect as k, useContext as z } from "react";
3
+ import { cx as E } from "@kuma-ui/core";
4
4
  import { createPortal as G } from "react-dom";
5
5
  import { f as J } from "../focus-trap-react-Dr3BYLw6.mjs";
6
6
  import K from "./text-button.mjs";
7
- import F from "./decorators.mjs";
8
- import C from "./flex.mjs";
7
+ import A from "./decorators.mjs";
8
+ import H from "./flex.mjs";
9
9
  import { defaultAtomElementType as Q } from "./atom.mjs";
10
10
  import { Heading as U, defaultHeadingElementType as V } from "./text.mjs";
11
- const A = q({
11
+ const B = q({
12
12
  isVisible: !1,
13
13
  isInteractive: !1
14
14
  }), {
15
15
  Provider: X
16
- } = A;
16
+ } = B;
17
17
  function Y() {
18
- return z(A);
18
+ return z(B);
19
19
  }
20
20
  function Z() {
21
21
  const {
22
- isInteractive: n,
23
- close: o
24
- } = Y(), r = f(() => {
25
- o == null || o();
26
- }, [o]);
27
- return /* @__PURE__ */ t.jsx("div", { className: "kakadu-components-2566044647", children: /* @__PURE__ */ t.jsx(K, { iconLeft: "times", label: "Close", disabled: !n, onClick: r }) });
22
+ isInteractive: o,
23
+ close: r
24
+ } = Y(), s = d(() => {
25
+ r == null || r();
26
+ }, [r]);
27
+ return /* @__PURE__ */ n.jsx("div", { className: "kakadu-components-2566044647", children: /* @__PURE__ */ n.jsx(K, { iconLeft: "times", label: "Close", disabled: !o, onClick: s }) });
28
28
  }
29
- function ce(n) {
30
- return /* @__PURE__ */ t.jsx(C, { gap: 2, ...n });
29
+ function ce(o) {
30
+ return /* @__PURE__ */ n.jsx(H, { gap: 2, ...o });
31
31
  }
32
32
  function ie({
33
- as: n,
34
- className: o,
35
- ...r
33
+ as: o,
34
+ className: r,
35
+ ...s
36
36
  }) {
37
- return /* @__PURE__ */ t.jsx(U, { ...r, as: n ?? V, className: w("kakadu-components-4275938488", o) });
37
+ return /* @__PURE__ */ n.jsx(U, { ...s, as: o ?? V, className: E("kakadu-components-4275938488", r) });
38
38
  }
39
39
  function ue({
40
- as: n,
41
- ...o
40
+ as: o,
41
+ ...r
42
42
  }) {
43
- return /* @__PURE__ */ t.jsx(C, { direction: "row", gap: 1, preset: "end", ...o, as: n ?? Q });
43
+ return /* @__PURE__ */ n.jsx(H, { direction: "row", gap: 1, preset: "end", ...r, as: o ?? Q });
44
44
  }
45
45
  function le({
46
- root: n,
47
- outerDecorators: o = [],
48
- innerDecorators: r = [],
49
- label: p,
50
- maxWidth: a,
51
- className: x,
52
- isVisible: s,
53
- isFullWidth: u = !1,
54
- shouldCloseOnOutsideClick: i = !0,
55
- shouldCloseOnEscapePress: l = !0,
56
- showCloseButton: H = !0,
57
- onClose: k,
58
- children: B
46
+ root: o,
47
+ outerDecorators: r = [],
48
+ innerDecorators: s = [],
49
+ label: h,
50
+ maxWidth: c,
51
+ className: w,
52
+ isVisible: t,
53
+ isFullWidth: i = !1,
54
+ shouldCloseOnOutsideClick: f = !0,
55
+ shouldCloseOnEscapePress: m = !0,
56
+ showCloseButton: I = !0,
57
+ onClose: u,
58
+ children: l
59
59
  }) {
60
- const E = j(null), M = j(null), [g, P] = h(!1), [c, d] = h(!1), y = f((e) => {
61
- E.current = e, d(!1);
62
- }, []), T = j(null), L = f((e) => {
63
- e && (T.current = e);
64
- }, []), [N, R] = h(s ?? !1), D = I(() => ({
65
- isVisible: N,
66
- isInteractive: c,
67
- setInitialFocus: L,
68
- close: y
69
- }), [N, c, L, y]);
70
- m(() => {
71
- s && (P(!0), R(!0));
72
- }, [s]), m(() => {
73
- if (s) {
60
+ const M = v(null), p = v(null), [L, P] = j(!1), [a, x] = j(!1), N = d((e) => {
61
+ M.current = e, x(!1);
62
+ }, []), R = v(null), b = d((e) => {
63
+ e && (R.current = e);
64
+ }, []), [y, F] = j(t ?? !1), D = g(() => ({
65
+ isVisible: y,
66
+ isInteractive: a,
67
+ setInitialFocus: b,
68
+ close: N
69
+ }), [y, a, b, N]);
70
+ k(() => {
71
+ if (t) {
74
72
  const e = setTimeout(() => {
75
- d(!0);
73
+ x(!0);
76
74
  }, 100);
77
75
  return () => {
78
76
  clearTimeout(e);
79
77
  };
80
78
  }
81
- d(!1);
82
- }, [s]), m(() => {
83
- if (g && !c) {
84
- const e = setTimeout(() => {
85
- k == null || k(E.current ?? void 0), R(!1);
86
- }, 370);
87
- return () => {
88
- clearTimeout(e);
89
- };
90
- }
91
- }, [g, c, k]), m(() => {
92
- const e = M.current;
93
- if (s && i && e) {
94
- const v = ($) => {
95
- e === $.target && d(!1);
79
+ x(!1);
80
+ }, [t]), k(() => {
81
+ t && (P(!0), F(!0));
82
+ }, [t]), k(() => {
83
+ const e = p.current;
84
+ if (t && f && e) {
85
+ const T = ($) => {
86
+ e === $.target && x(!1);
96
87
  };
97
- return e.addEventListener("click", v), () => {
98
- e.removeEventListener("click", v);
88
+ return e.addEventListener("click", T), () => {
89
+ e.removeEventListener("click", T);
99
90
  };
100
91
  }
101
- }, [s, i]), m(() => {
102
- if (!s || !l)
92
+ }, [t, f]), k(() => {
93
+ if (!t || !m)
103
94
  return;
104
- const e = (v) => {
105
- v.key === "Escape" && d(!1);
95
+ const e = (T) => {
96
+ T.key === "Escape" && x(!1);
106
97
  };
107
98
  return window.addEventListener("keydown", e), () => {
108
99
  window.removeEventListener("keydown", e);
109
100
  };
110
- }, [s, l]);
111
- const S = I(() => ({
112
- initialFocus: () => T.current ?? void 0,
101
+ }, [t, m]), k(() => {
102
+ if (L && !a) {
103
+ const e = setTimeout(() => {
104
+ F(!1), u == null || u(M.current ?? void 0);
105
+ }, 370);
106
+ return () => {
107
+ clearTimeout(e);
108
+ };
109
+ }
110
+ }, [L, a, u]);
111
+ const S = g(() => ({
112
+ initialFocus: () => R.current ?? void 0,
113
113
  onActivate: () => {
114
114
  var e;
115
- return (e = T.current) == null ? void 0 : e.focus();
115
+ return (e = R.current) == null ? void 0 : e.focus();
116
116
  }
117
- }), []), b = /* @__PURE__ */ t.jsx(F, { decorators: o, children: /* @__PURE__ */ t.jsx("div", { "aria-hidden": !c, style: {
118
- "--max-width": a ? `${a}px` : void 0
119
- }, className: w("kakadu-components-4119461136", c && "kakadu-components-2522346797", x), children: /* @__PURE__ */ t.jsx(F, { decorators: r, children: /* @__PURE__ */ t.jsx(J.FocusTrap, { active: c, focusTrapOptions: S, children: /* @__PURE__ */ t.jsx("div", { ref: M, className: "kakadu-components-4011815997", children: /* @__PURE__ */ t.jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": p ?? "Modal", className: w("kakadu-components-3324483532", u && "kakadu-components-3799971070", c && "kakadu-components-968755580"), children: /* @__PURE__ */ t.jsxs(X, { value: D, children: [
120
- H ? /* @__PURE__ */ t.jsx(Z, {}) : null,
121
- /* @__PURE__ */ t.jsx("div", { className: w("kakadu-components-633990035", u && "kakadu-components-171969824"), children: B })
117
+ }), []);
118
+ if (!y)
119
+ return null;
120
+ const C = /* @__PURE__ */ n.jsx(A, { decorators: r, children: /* @__PURE__ */ n.jsx("div", { "aria-hidden": !a, style: {
121
+ "--max-width": c ? `${c}px` : void 0
122
+ }, className: E("kakadu-components-4119461136", a && "kakadu-components-2522346797", w), children: /* @__PURE__ */ n.jsx(A, { decorators: s, children: /* @__PURE__ */ n.jsx(J.FocusTrap, { active: a, focusTrapOptions: S, children: /* @__PURE__ */ n.jsx("div", { ref: p, className: "kakadu-components-4011815997", children: /* @__PURE__ */ n.jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": h ?? "Modal", className: E("kakadu-components-3324483532", i && "kakadu-components-3799971070", a && "kakadu-components-968755580"), children: /* @__PURE__ */ n.jsxs(X, { value: D, children: [
123
+ I ? /* @__PURE__ */ n.jsx(Z, {}) : null,
124
+ /* @__PURE__ */ n.jsx("div", { className: E("kakadu-components-633990035", i && "kakadu-components-171969824"), children: l })
122
125
  ] }) }) }) }) }) }) });
123
- return n ? G(b, n) : b;
126
+ return o ? G(C, o) : C;
124
127
  }
125
- function de(n, o) {
126
- const [r, p] = h(!1), a = j(void 0), x = f(async () => (p(!0), new Promise((i) => {
127
- a.current = i;
128
- })), []), s = f((i) => {
129
- var l;
130
- p(!1), (l = a.current) == null || l.call(a, i), a.current = void 0;
131
- }, []), u = I(() => /* @__PURE__ */ t.jsx(n, { ...o, isVisible: r, onClose: s }), [n, o, r, s]);
132
- return I(() => ({
133
- isVisible: r,
134
- show: x,
128
+ function de(o, r) {
129
+ const [s, h] = j(!1), [c, w] = j(!1), t = v(void 0), i = v(void 0), f = d(async () => (i.current = void 0, h(!0), w(!0), new Promise((l) => {
130
+ t.current = l;
131
+ })), []), m = d((l) => {
132
+ i.current = l, w(!1);
133
+ }, []), I = d((l) => {
134
+ var p;
135
+ const M = l ?? i.current;
136
+ i.current = void 0, (p = t.current) == null || p.call(t, M), t.current = void 0, h(!1);
137
+ }, []), u = g(() => s ? /* @__PURE__ */ n.jsx(o, { ...r, isVisible: c, onClose: I }) : null, [s, o, r, c, I]);
138
+ return g(() => ({
139
+ isVisible: c,
140
+ show: f,
141
+ close: m,
135
142
  modal: u
136
- }), [r, x, u]);
143
+ }), [c, f, m, u]);
137
144
  }
138
145
  export {
139
146
  ue as ModalActions,
@@ -27,7 +27,7 @@ export declare function usePopoverMenu(items: PopoverMenuItemProperties[]): {
27
27
  isVisible: boolean;
28
28
  show: () => Promise<void | undefined>;
29
29
  close: (result?: void | undefined) => void;
30
- popoverMenu: import("react/jsx-runtime").JSX.Element;
30
+ popoverMenu: import("react/jsx-runtime").JSX.Element | null;
31
31
  };
32
32
  export type PopoverMenuProperties = {
33
33
  readonly menu: ReactNode;
@@ -20,11 +20,11 @@ export type PopoverProperties<Data = any, Type extends AtomElementType = Default
20
20
  readonly onClose?: (data?: Data) => void;
21
21
  };
22
22
  type PopoverBaseProperties<PopoverResult> = Omit<PopoverProperties<PopoverResult>, 'isVisible' | 'onClose'>;
23
- export default function Popover<Data = any, Type extends AtomElementType = DefaultAtomElementType>({ as, isVisible, label, shouldCloseOnOutsideClick, shouldCloseOnEscapePress, children, className, innerClassName, onClose, ...properties }: PopoverProperties<Data, Type>): import("react/jsx-runtime").JSX.Element;
23
+ export default function Popover<Data = any, Type extends AtomElementType = DefaultAtomElementType>({ as, isVisible, label, shouldCloseOnOutsideClick, shouldCloseOnEscapePress, children, className, innerClassName, onClose, ...properties }: PopoverProperties<Data, Type>): import("react/jsx-runtime").JSX.Element | null;
24
24
  export declare function usePopover<PopoverResult, PopoverProperties = PopoverBaseProperties<PopoverResult>>(PopoverComponent: ComponentType<PopoverProperties>, properties?: PopoverProperties): {
25
25
  isVisible: boolean;
26
26
  show: () => Promise<PopoverResult | undefined>;
27
27
  close: (result?: PopoverResult) => void;
28
- popover: import("react/jsx-runtime").JSX.Element;
28
+ popover: import("react/jsx-runtime").JSX.Element | null;
29
29
  };
30
30
  export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),f=require("@kuma-ui/core"),e=require("react"),K=require("../focus-trap-react-B7f3iC5h.js"),R=require("./atom.js"),$=e.createContext({isVisible:!1,isPreparingFocus:!1,isFocused:!1}),{Provider:Q}=$;function X(){return e.useContext($)}function Y({as:i,className:s,...o}){return n.jsxRuntimeExports.jsx(R.default,{as:i??R.defaultAtomElementType,...o,className:f.cx("kakadu-components-2845019685",s)})}function Z({as:i,isVisible:s,label:o,shouldCloseOnOutsideClick:d=!0,shouldCloseOnEscapePress:a=!0,children:p,className:u,innerClassName:x,onClose:r,...v}){const I=e.useRef(null),S=e.useRef(null),[q,h]=e.useState(!1),[A,k]=e.useState(!1),[C,H]=e.useState(!1),[c,g]=e.useState(!1),[U,j]=e.useState(!1),M=e.useCallback(t=>{I.current=t,g(!1)},[]),E=e.useRef(null),N=e.useCallback(t=>{t&&(E.current=t)},[]),G=e.useMemo(()=>({initialFocus:()=>E.current??void 0,onPostActivate(){var t;k(!0),h(!1),(t=E.current)==null||t.focus()},clickOutsideDeactivates:d,escapeDeactivates:a,onPostUnpause(){k(!0)},onPause(){k(!1)},onDeactivate(){j(!1),g(!1),k(!1)}}),[d,a]),[L,O]=e.useState(s??!1),J=e.useMemo(()=>({isVisible:L,isPreparingFocus:q,isFocused:A,setInitialFocus:N,close:M}),[L,q,A,N,M]),[l,y]=e.useState("center");return e.useEffect(()=>{const t=S.current;if(t){const P=()=>{const D=t.offsetParent,F=D instanceof HTMLElement?D.getBoundingClientRect():null,V=t.getBoundingClientRect();if(!F){y("center");return}const T=16,_=window.innerWidth-T,b=F.left+F.width/2-V.width/2,z=b+V.width,B=b<T,W=z>_;let m="center";if(B&&W){const w=T-b;m=z-_>w?"right":"left"}else W?m="right":B&&(m="left");y(w=>w===m?w:m)};return P(),window.addEventListener("resize",P),()=>{window.removeEventListener("resize",P)}}},[]),e.useEffect(()=>{s&&(H(!0),O(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{g(!0)},100);return()=>{clearTimeout(t)}}g(!1)},[s]),e.useEffect(()=>{if(!c){j(!1),h(!1);return}h(!0);const t=window.requestAnimationFrame(()=>{j(!0)});return()=>{window.cancelAnimationFrame(t)}},[c]),e.useEffect(()=>{if(C&&!c){const t=setTimeout(()=>{r==null||r(I.current??void 0),O(!1)},370);return()=>{clearTimeout(t)}}},[C,c,r]),n.jsxRuntimeExports.jsx(R.default,{reference:S,as:i??R.defaultAtomElementType,role:"dialog","aria-hidden":!c,"aria-label":o??"Popover",...v,className:f.cx("kakadu-components-3920007758",l==="left"&&"kakadu-components-611400930",l==="right"&&"kakadu-components-944244368",c&&"kakadu-components-1399012551",u),children:n.jsxRuntimeExports.jsxs("div",{className:f.cx("kakadu-components-1118152266",c&&"kakadu-components-231244945"),children:[n.jsxRuntimeExports.jsx("div",{className:f.cx("kakadu-components-1951789226",l==="left"&&"kakadu-components-1495725644",l==="right"&&"kakadu-components-4235689197")}),n.jsxRuntimeExports.jsx(K.focusTrapReactExports.FocusTrap,{active:U,focusTrapOptions:G,children:n.jsxRuntimeExports.jsxs("div",{className:f.cx("kakadu-components-2488426662",x),children:[n.jsxRuntimeExports.jsx(Q,{value:J,children:p}),n.jsxRuntimeExports.jsx("div",{className:f.cx("kakadu-components-3252390100",l==="left"&&"kakadu-components-3754561431",l==="right"&&"kakadu-components-2265262600")})]})})]})})}function ee(i,s){const[o,d]=e.useState(!1),a=e.useRef(void 0),p=e.useCallback(async()=>(d(!0),new Promise(r=>{a.current=r})),[]),u=e.useCallback(r=>{var v;d(!1),(v=a.current)==null||v.call(a,r),a.current=void 0},[]),x=e.useMemo(()=>n.jsxRuntimeExports.jsx(i,{...s,isVisible:o,onClose:u}),[i,s,o,u]);return e.useMemo(()=>({isVisible:o,show:p,close:u,popover:x}),[o,p,u,x])}exports.PopoverContainer=Y;exports.default=Z;exports.usePopover=ee;exports.usePopoverContext=X;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),m=require("@kuma-ui/core"),e=require("react"),K=require("../focus-trap-react-B7f3iC5h.js"),F=require("./atom.js"),$=e.createContext({isVisible:!1,isPreparingFocus:!1,isFocused:!1}),{Provider:Q}=$;function X(){return e.useContext($)}function Y({as:i,className:s,...l}){return n.jsxRuntimeExports.jsx(F.default,{as:i??F.defaultAtomElementType,...l,className:m.cx("kakadu-components-2845019685",s)})}function Z({as:i,isVisible:s,label:l,shouldCloseOnOutsideClick:p=!0,shouldCloseOnEscapePress:r=!0,children:w,className:c,innerClassName:f,onClose:a,...h}){const v=e.useRef(null),x=e.useRef(null),[o,k]=e.useState(!1),[R,j]=e.useState(!1),[A,H]=e.useState(!1),[u,E]=e.useState(!1),[U,T]=e.useState(!1),N=e.useCallback(t=>{v.current=t,E(!1)},[]),b=e.useRef(null),L=e.useCallback(t=>{t&&(b.current=t)},[]),G=e.useMemo(()=>({initialFocus:()=>b.current??void 0,onPostActivate(){var t;j(!0),k(!1),(t=b.current)==null||t.focus()},clickOutsideDeactivates:p,escapeDeactivates:r,onPostUnpause(){j(!0)},onPause(){j(!1)},onDeactivate(){T(!1),E(!1),j(!1)}}),[p,r]),[I,O]=e.useState(s??!1),J=e.useMemo(()=>({isVisible:I,isPreparingFocus:o,isFocused:R,setInitialFocus:L,close:N}),[I,o,R,L,N]),[d,y]=e.useState("center");return e.useEffect(()=>{const t=x.current;if(t){const S=()=>{const D=t.offsetParent,M=D instanceof HTMLElement?D.getBoundingClientRect():null,V=t.getBoundingClientRect();if(!M){y("center");return}const C=16,_=window.innerWidth-C,q=M.left+M.width/2-V.width/2,z=q+V.width,B=q<C,W=z>_;let g="center";if(B&&W){const P=C-q;g=z-_>P?"right":"left"}else W?g="right":B&&(g="left");y(P=>P===g?P:g)};return S(),window.addEventListener("resize",S),()=>{window.removeEventListener("resize",S)}}},[]),e.useEffect(()=>{s&&(H(!0),O(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{E(!0)},100);return()=>{clearTimeout(t)}}E(!1)},[s]),e.useEffect(()=>{if(!u){T(!1),k(!1);return}k(!0);const t=window.requestAnimationFrame(()=>{T(!0)});return()=>{window.cancelAnimationFrame(t)}},[u]),e.useEffect(()=>{if(A&&!u){const t=setTimeout(()=>{O(!1),a==null||a(v.current??void 0)},370);return()=>{clearTimeout(t)}}},[A,u,a]),I?n.jsxRuntimeExports.jsx(F.default,{reference:x,as:i??F.defaultAtomElementType,role:"dialog","aria-hidden":!u,"aria-label":l??"Popover",...h,className:m.cx("kakadu-components-3920007758",d==="left"&&"kakadu-components-611400930",d==="right"&&"kakadu-components-944244368",u&&"kakadu-components-1399012551",c),children:n.jsxRuntimeExports.jsxs("div",{className:m.cx("kakadu-components-1118152266",u&&"kakadu-components-231244945"),children:[n.jsxRuntimeExports.jsx("div",{className:m.cx("kakadu-components-1951789226",d==="left"&&"kakadu-components-1495725644",d==="right"&&"kakadu-components-4235689197")}),n.jsxRuntimeExports.jsx(K.focusTrapReactExports.FocusTrap,{active:U,focusTrapOptions:G,children:n.jsxRuntimeExports.jsxs("div",{className:m.cx("kakadu-components-2488426662",f),children:[n.jsxRuntimeExports.jsx(Q,{value:J,children:w}),n.jsxRuntimeExports.jsx("div",{className:m.cx("kakadu-components-3252390100",d==="left"&&"kakadu-components-3754561431",d==="right"&&"kakadu-components-2265262600")})]})})]})}):null}function ee(i,s){const[l,p]=e.useState(!1),[r,w]=e.useState(!1),c=e.useRef(void 0),f=e.useRef(void 0),a=e.useCallback(async()=>(f.current=void 0,p(!0),w(!0),new Promise(o=>{c.current=o})),[]),h=e.useCallback(o=>{f.current=o,w(!1)},[]),v=e.useCallback(o=>{var R;const k=o??f.current;f.current=void 0,(R=c.current)==null||R.call(c,k),c.current=void 0,p(!1)},[]),x=e.useMemo(()=>l?n.jsxRuntimeExports.jsx(i,{...s,isVisible:r,onClose:v}):null,[l,i,s,r,v]);return e.useMemo(()=>({isVisible:r,show:a,close:h,popover:x}),[r,a,h,x])}exports.PopoverContainer=Y;exports.default=Z;exports.usePopover=ee;exports.usePopoverContext=X;
@@ -1,140 +1,143 @@
1
- import { j as s } from "../jsx-runtime-B4hRZ52C.mjs";
2
- import { cx as f } from "@kuma-ui/core";
3
- import { createContext as ee, useRef as F, useState as r, useCallback as P, useMemo as j, useEffect as p, useContext as te } from "react";
4
- import { f as se } from "../focus-trap-react-Dr3BYLw6.mjs";
1
+ import { j as n } from "../jsx-runtime-B4hRZ52C.mjs";
2
+ import { cx as m } from "@kuma-ui/core";
3
+ import { createContext as ee, useRef as F, useState as s, useCallback as P, useMemo as b, useEffect as x, useContext as te } from "react";
4
+ import { f as ne } from "../focus-trap-react-Dr3BYLw6.mjs";
5
5
  import K, { defaultAtomElementType as Q } from "./atom.mjs";
6
6
  const X = ee({
7
7
  isVisible: !1,
8
8
  isPreparingFocus: !1,
9
9
  isFocused: !1
10
10
  }), {
11
- Provider: ne
11
+ Provider: se
12
12
  } = X;
13
13
  function le() {
14
14
  return te(X);
15
15
  }
16
16
  function fe({
17
- as: i,
17
+ as: u,
18
18
  className: t,
19
- ...n
19
+ ...l
20
20
  }) {
21
- return /* @__PURE__ */ s.jsx(K, { as: i ?? Q, ...n, className: f("kakadu-components-2845019685", t) });
21
+ return /* @__PURE__ */ n.jsx(K, { as: u ?? Q, ...l, className: m("kakadu-components-2845019685", t) });
22
22
  }
23
23
  function de({
24
- as: i,
24
+ as: u,
25
25
  isVisible: t,
26
- label: n,
27
- shouldCloseOnOutsideClick: d = !0,
28
- shouldCloseOnEscapePress: o = !0,
29
- children: v,
30
- className: u,
31
- innerClassName: k,
32
- onClose: a,
33
- ...w
26
+ label: l,
27
+ shouldCloseOnOutsideClick: p = !0,
28
+ shouldCloseOnEscapePress: r = !0,
29
+ children: R,
30
+ className: a,
31
+ innerClassName: f,
32
+ onClose: c,
33
+ ...j
34
34
  }) {
35
- const L = F(null), D = F(null), [O, T] = r(!1), [V, g] = r(!1), [y, Y] = r(!1), [c, h] = r(!1), [Z, I] = r(!1), z = P((e) => {
36
- L.current = e, h(!1);
37
- }, []), R = F(null), B = P((e) => {
38
- e && (R.current = e);
39
- }, []), _ = j(() => ({
40
- initialFocus: () => R.current ?? void 0,
35
+ const v = F(null), k = F(null), [o, w] = s(!1), [g, I] = s(!1), [y, Y] = s(!1), [i, T] = s(!1), [Z, E] = s(!1), z = P((e) => {
36
+ v.current = e, T(!1);
37
+ }, []), N = F(null), B = P((e) => {
38
+ e && (N.current = e);
39
+ }, []), _ = b(() => ({
40
+ initialFocus: () => N.current ?? void 0,
41
41
  onPostActivate() {
42
42
  var e;
43
- g(!0), T(!1), (e = R.current) == null || e.focus();
43
+ I(!0), w(!1), (e = N.current) == null || e.focus();
44
44
  },
45
- clickOutsideDeactivates: d,
46
- escapeDeactivates: o,
45
+ clickOutsideDeactivates: p,
46
+ escapeDeactivates: r,
47
47
  onPostUnpause() {
48
- g(!0);
48
+ I(!0);
49
49
  },
50
50
  onPause() {
51
- g(!1);
51
+ I(!1);
52
52
  },
53
53
  onDeactivate() {
54
- I(!1), h(!1), g(!1);
54
+ E(!1), T(!1), I(!1);
55
55
  }
56
- }), [d, o]), [C, M] = r(t ?? !1), $ = j(() => ({
57
- isVisible: C,
58
- isPreparingFocus: O,
59
- isFocused: V,
56
+ }), [p, r]), [L, C] = s(t ?? !1), $ = b(() => ({
57
+ isVisible: L,
58
+ isPreparingFocus: o,
59
+ isFocused: g,
60
60
  setInitialFocus: B,
61
61
  close: z
62
- }), [C, O, V, B, z]), [l, W] = r("center");
63
- return p(() => {
64
- const e = D.current;
62
+ }), [L, o, g, B, z]), [d, W] = s("center");
63
+ return x(() => {
64
+ const e = k.current;
65
65
  if (e) {
66
- const A = () => {
67
- const q = e.offsetParent, b = q instanceof HTMLElement ? q.getBoundingClientRect() : null, H = e.getBoundingClientRect();
68
- if (!b) {
66
+ const D = () => {
67
+ const q = e.offsetParent, M = q instanceof HTMLElement ? q.getBoundingClientRect() : null, H = e.getBoundingClientRect();
68
+ if (!M) {
69
69
  W("center");
70
70
  return;
71
71
  }
72
- const E = 16, S = window.innerWidth - E, N = b.left + b.width / 2 - H.width / 2, U = N + H.width, G = N < E, J = U > S;
73
- let m = "center";
72
+ const O = 16, S = window.innerWidth - O, V = M.left + M.width / 2 - H.width / 2, U = V + H.width, G = V < O, J = U > S;
73
+ let h = "center";
74
74
  if (G && J) {
75
- const x = E - N;
76
- m = U - S > x ? "right" : "left";
77
- } else J ? m = "right" : G && (m = "left");
78
- W((x) => x === m ? x : m);
75
+ const A = O - V;
76
+ h = U - S > A ? "right" : "left";
77
+ } else J ? h = "right" : G && (h = "left");
78
+ W((A) => A === h ? A : h);
79
79
  };
80
- return A(), window.addEventListener("resize", A), () => {
81
- window.removeEventListener("resize", A);
80
+ return D(), window.addEventListener("resize", D), () => {
81
+ window.removeEventListener("resize", D);
82
82
  };
83
83
  }
84
- }, []), p(() => {
85
- t && (Y(!0), M(!0));
86
- }, [t]), p(() => {
84
+ }, []), x(() => {
85
+ t && (Y(!0), C(!0));
86
+ }, [t]), x(() => {
87
87
  if (t) {
88
88
  const e = setTimeout(() => {
89
- h(!0);
89
+ T(!0);
90
90
  }, 100);
91
91
  return () => {
92
92
  clearTimeout(e);
93
93
  };
94
94
  }
95
- h(!1);
96
- }, [t]), p(() => {
97
- if (!c) {
98
- I(!1), T(!1);
95
+ T(!1);
96
+ }, [t]), x(() => {
97
+ if (!i) {
98
+ E(!1), w(!1);
99
99
  return;
100
100
  }
101
- T(!0);
101
+ w(!0);
102
102
  const e = window.requestAnimationFrame(() => {
103
- I(!0);
103
+ E(!0);
104
104
  });
105
105
  return () => {
106
106
  window.cancelAnimationFrame(e);
107
107
  };
108
- }, [c]), p(() => {
109
- if (y && !c) {
108
+ }, [i]), x(() => {
109
+ if (y && !i) {
110
110
  const e = setTimeout(() => {
111
- a == null || a(L.current ?? void 0), M(!1);
111
+ C(!1), c == null || c(v.current ?? void 0);
112
112
  }, 370);
113
113
  return () => {
114
114
  clearTimeout(e);
115
115
  };
116
116
  }
117
- }, [y, c, a]), /* @__PURE__ */ s.jsx(K, { reference: D, as: i ?? Q, role: "dialog", "aria-hidden": !c, "aria-label": n ?? "Popover", ...w, className: f("kakadu-components-3920007758", l === "left" && "kakadu-components-611400930", l === "right" && "kakadu-components-944244368", c && "kakadu-components-1399012551", u), children: /* @__PURE__ */ s.jsxs("div", { className: f("kakadu-components-1118152266", c && "kakadu-components-231244945"), children: [
118
- /* @__PURE__ */ s.jsx("div", { className: f("kakadu-components-1951789226", l === "left" && "kakadu-components-1495725644", l === "right" && "kakadu-components-4235689197") }),
119
- /* @__PURE__ */ s.jsx(se.FocusTrap, { active: Z, focusTrapOptions: _, children: /* @__PURE__ */ s.jsxs("div", { className: f("kakadu-components-2488426662", k), children: [
120
- /* @__PURE__ */ s.jsx(ne, { value: $, children: v }),
121
- /* @__PURE__ */ s.jsx("div", { className: f("kakadu-components-3252390100", l === "left" && "kakadu-components-3754561431", l === "right" && "kakadu-components-2265262600") })
117
+ }, [y, i, c]), L ? /* @__PURE__ */ n.jsx(K, { reference: k, as: u ?? Q, role: "dialog", "aria-hidden": !i, "aria-label": l ?? "Popover", ...j, className: m("kakadu-components-3920007758", d === "left" && "kakadu-components-611400930", d === "right" && "kakadu-components-944244368", i && "kakadu-components-1399012551", a), children: /* @__PURE__ */ n.jsxs("div", { className: m("kakadu-components-1118152266", i && "kakadu-components-231244945"), children: [
118
+ /* @__PURE__ */ n.jsx("div", { className: m("kakadu-components-1951789226", d === "left" && "kakadu-components-1495725644", d === "right" && "kakadu-components-4235689197") }),
119
+ /* @__PURE__ */ n.jsx(ne.FocusTrap, { active: Z, focusTrapOptions: _, children: /* @__PURE__ */ n.jsxs("div", { className: m("kakadu-components-2488426662", f), children: [
120
+ /* @__PURE__ */ n.jsx(se, { value: $, children: R }),
121
+ /* @__PURE__ */ n.jsx("div", { className: m("kakadu-components-3252390100", d === "left" && "kakadu-components-3754561431", d === "right" && "kakadu-components-2265262600") })
122
122
  ] }) })
123
- ] }) });
123
+ ] }) }) : null;
124
124
  }
125
- function me(i, t) {
126
- const [n, d] = r(!1), o = F(void 0), v = P(async () => (d(!0), new Promise((a) => {
127
- o.current = a;
128
- })), []), u = P((a) => {
129
- var w;
130
- d(!1), (w = o.current) == null || w.call(o, a), o.current = void 0;
131
- }, []), k = j(() => /* @__PURE__ */ s.jsx(i, { ...t, isVisible: n, onClose: u }), [i, t, n, u]);
132
- return j(() => ({
133
- isVisible: n,
134
- show: v,
135
- close: u,
125
+ function me(u, t) {
126
+ const [l, p] = s(!1), [r, R] = s(!1), a = F(void 0), f = F(void 0), c = P(async () => (f.current = void 0, p(!0), R(!0), new Promise((o) => {
127
+ a.current = o;
128
+ })), []), j = P((o) => {
129
+ f.current = o, R(!1);
130
+ }, []), v = P((o) => {
131
+ var g;
132
+ const w = o ?? f.current;
133
+ f.current = void 0, (g = a.current) == null || g.call(a, w), a.current = void 0, p(!1);
134
+ }, []), k = b(() => l ? /* @__PURE__ */ n.jsx(u, { ...t, isVisible: r, onClose: v }) : null, [l, u, t, r, v]);
135
+ return b(() => ({
136
+ isVisible: r,
137
+ show: c,
138
+ close: j,
136
139
  popover: k
137
- }), [n, v, u, k]);
140
+ }), [r, c, j, k]);
138
141
  }
139
142
  export {
140
143
  fe as PopoverContainer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakadu/components",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "Kakadu components library",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",