@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.
- package/build/components/modal.d.ts +3 -2
- package/build/components/modal.js +1 -1
- package/build/components/modal.mjs +100 -93
- package/build/components/popover-menu.d.ts +1 -1
- package/build/components/popover.d.ts +2 -2
- package/build/components/popover.js +1 -1
- package/build/components/popover.mjs +81 -78
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
|
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
|
|
2
|
-
import { createContext as q, useRef as
|
|
3
|
-
import { cx as
|
|
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
|
|
8
|
-
import
|
|
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
|
|
11
|
+
const B = q({
|
|
12
12
|
isVisible: !1,
|
|
13
13
|
isInteractive: !1
|
|
14
14
|
}), {
|
|
15
15
|
Provider: X
|
|
16
|
-
} =
|
|
16
|
+
} = B;
|
|
17
17
|
function Y() {
|
|
18
|
-
return z(
|
|
18
|
+
return z(B);
|
|
19
19
|
}
|
|
20
20
|
function Z() {
|
|
21
21
|
const {
|
|
22
|
-
isInteractive:
|
|
23
|
-
close:
|
|
24
|
-
} = Y(),
|
|
25
|
-
|
|
26
|
-
}, [
|
|
27
|
-
return /* @__PURE__ */
|
|
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(
|
|
30
|
-
return /* @__PURE__ */
|
|
29
|
+
function ce(o) {
|
|
30
|
+
return /* @__PURE__ */ n.jsx(H, { gap: 2, ...o });
|
|
31
31
|
}
|
|
32
32
|
function ie({
|
|
33
|
-
as:
|
|
34
|
-
className:
|
|
35
|
-
...
|
|
33
|
+
as: o,
|
|
34
|
+
className: r,
|
|
35
|
+
...s
|
|
36
36
|
}) {
|
|
37
|
-
return /* @__PURE__ */
|
|
37
|
+
return /* @__PURE__ */ n.jsx(U, { ...s, as: o ?? V, className: E("kakadu-components-4275938488", r) });
|
|
38
38
|
}
|
|
39
39
|
function ue({
|
|
40
|
-
as:
|
|
41
|
-
...
|
|
40
|
+
as: o,
|
|
41
|
+
...r
|
|
42
42
|
}) {
|
|
43
|
-
return /* @__PURE__ */
|
|
43
|
+
return /* @__PURE__ */ n.jsx(H, { direction: "row", gap: 1, preset: "end", ...r, as: o ?? Q });
|
|
44
44
|
}
|
|
45
45
|
function le({
|
|
46
|
-
root:
|
|
47
|
-
outerDecorators:
|
|
48
|
-
innerDecorators:
|
|
49
|
-
label:
|
|
50
|
-
maxWidth:
|
|
51
|
-
className:
|
|
52
|
-
isVisible:
|
|
53
|
-
isFullWidth:
|
|
54
|
-
shouldCloseOnOutsideClick:
|
|
55
|
-
shouldCloseOnEscapePress:
|
|
56
|
-
showCloseButton:
|
|
57
|
-
onClose:
|
|
58
|
-
children:
|
|
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
|
|
61
|
-
|
|
62
|
-
}, []),
|
|
63
|
-
e && (
|
|
64
|
-
}, []), [
|
|
65
|
-
isVisible:
|
|
66
|
-
isInteractive:
|
|
67
|
-
setInitialFocus:
|
|
68
|
-
close:
|
|
69
|
-
}), [
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
73
|
+
x(!0);
|
|
76
74
|
}, 100);
|
|
77
75
|
return () => {
|
|
78
76
|
clearTimeout(e);
|
|
79
77
|
};
|
|
80
78
|
}
|
|
81
|
-
|
|
82
|
-
}, [
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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",
|
|
98
|
-
e.removeEventListener("click",
|
|
88
|
+
return e.addEventListener("click", T), () => {
|
|
89
|
+
e.removeEventListener("click", T);
|
|
99
90
|
};
|
|
100
91
|
}
|
|
101
|
-
}, [
|
|
102
|
-
if (!
|
|
92
|
+
}, [t, f]), k(() => {
|
|
93
|
+
if (!t || !m)
|
|
103
94
|
return;
|
|
104
|
-
const e = (
|
|
105
|
-
|
|
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
|
-
}, [
|
|
111
|
-
|
|
112
|
-
|
|
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 =
|
|
115
|
+
return (e = R.current) == null ? void 0 : e.focus();
|
|
116
116
|
}
|
|
117
|
-
}), [])
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
|
126
|
+
return o ? G(C, o) : C;
|
|
124
127
|
}
|
|
125
|
-
function de(
|
|
126
|
-
const [
|
|
127
|
-
|
|
128
|
-
})), []),
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
}), [
|
|
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"),
|
|
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
|
|
2
|
-
import { cx as
|
|
3
|
-
import { createContext as ee, useRef as F, useState as
|
|
4
|
-
import { f as
|
|
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:
|
|
11
|
+
Provider: se
|
|
12
12
|
} = X;
|
|
13
13
|
function le() {
|
|
14
14
|
return te(X);
|
|
15
15
|
}
|
|
16
16
|
function fe({
|
|
17
|
-
as:
|
|
17
|
+
as: u,
|
|
18
18
|
className: t,
|
|
19
|
-
...
|
|
19
|
+
...l
|
|
20
20
|
}) {
|
|
21
|
-
return /* @__PURE__ */
|
|
21
|
+
return /* @__PURE__ */ n.jsx(K, { as: u ?? Q, ...l, className: m("kakadu-components-2845019685", t) });
|
|
22
22
|
}
|
|
23
23
|
function de({
|
|
24
|
-
as:
|
|
24
|
+
as: u,
|
|
25
25
|
isVisible: t,
|
|
26
|
-
label:
|
|
27
|
-
shouldCloseOnOutsideClick:
|
|
28
|
-
shouldCloseOnEscapePress:
|
|
29
|
-
children:
|
|
30
|
-
className:
|
|
31
|
-
innerClassName:
|
|
32
|
-
onClose:
|
|
33
|
-
...
|
|
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
|
|
36
|
-
|
|
37
|
-
}, []),
|
|
38
|
-
e && (
|
|
39
|
-
}, []), _ =
|
|
40
|
-
initialFocus: () =>
|
|
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
|
-
|
|
43
|
+
I(!0), w(!1), (e = N.current) == null || e.focus();
|
|
44
44
|
},
|
|
45
|
-
clickOutsideDeactivates:
|
|
46
|
-
escapeDeactivates:
|
|
45
|
+
clickOutsideDeactivates: p,
|
|
46
|
+
escapeDeactivates: r,
|
|
47
47
|
onPostUnpause() {
|
|
48
|
-
|
|
48
|
+
I(!0);
|
|
49
49
|
},
|
|
50
50
|
onPause() {
|
|
51
|
-
|
|
51
|
+
I(!1);
|
|
52
52
|
},
|
|
53
53
|
onDeactivate() {
|
|
54
|
-
|
|
54
|
+
E(!1), T(!1), I(!1);
|
|
55
55
|
}
|
|
56
|
-
}), [
|
|
57
|
-
isVisible:
|
|
58
|
-
isPreparingFocus:
|
|
59
|
-
isFocused:
|
|
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
|
-
}), [
|
|
63
|
-
return
|
|
64
|
-
const e =
|
|
62
|
+
}), [L, o, g, B, z]), [d, W] = s("center");
|
|
63
|
+
return x(() => {
|
|
64
|
+
const e = k.current;
|
|
65
65
|
if (e) {
|
|
66
|
-
const
|
|
67
|
-
const q = e.offsetParent,
|
|
68
|
-
if (!
|
|
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
|
|
73
|
-
let
|
|
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
|
|
76
|
-
|
|
77
|
-
} else J ?
|
|
78
|
-
W((
|
|
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
|
|
81
|
-
window.removeEventListener("resize",
|
|
80
|
+
return D(), window.addEventListener("resize", D), () => {
|
|
81
|
+
window.removeEventListener("resize", D);
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
}, []),
|
|
85
|
-
t && (Y(!0),
|
|
86
|
-
}, [t]),
|
|
84
|
+
}, []), x(() => {
|
|
85
|
+
t && (Y(!0), C(!0));
|
|
86
|
+
}, [t]), x(() => {
|
|
87
87
|
if (t) {
|
|
88
88
|
const e = setTimeout(() => {
|
|
89
|
-
|
|
89
|
+
T(!0);
|
|
90
90
|
}, 100);
|
|
91
91
|
return () => {
|
|
92
92
|
clearTimeout(e);
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
}, [t]),
|
|
97
|
-
if (!
|
|
98
|
-
|
|
95
|
+
T(!1);
|
|
96
|
+
}, [t]), x(() => {
|
|
97
|
+
if (!i) {
|
|
98
|
+
E(!1), w(!1);
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
w(!0);
|
|
102
102
|
const e = window.requestAnimationFrame(() => {
|
|
103
|
-
|
|
103
|
+
E(!0);
|
|
104
104
|
});
|
|
105
105
|
return () => {
|
|
106
106
|
window.cancelAnimationFrame(e);
|
|
107
107
|
};
|
|
108
|
-
}, [
|
|
109
|
-
if (y && !
|
|
108
|
+
}, [i]), x(() => {
|
|
109
|
+
if (y && !i) {
|
|
110
110
|
const e = setTimeout(() => {
|
|
111
|
-
|
|
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,
|
|
118
|
-
/* @__PURE__ */
|
|
119
|
-
/* @__PURE__ */
|
|
120
|
-
/* @__PURE__ */
|
|
121
|
-
/* @__PURE__ */
|
|
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(
|
|
126
|
-
const [
|
|
127
|
-
|
|
128
|
-
})), []),
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
}), [
|
|
140
|
+
}), [r, c, j, k]);
|
|
138
141
|
}
|
|
139
142
|
export {
|
|
140
143
|
fe as PopoverContainer,
|