@kakadu/components 2.3.3 → 2.3.4
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.
|
@@ -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 s=require("../jsx-runtime-BB_1_6y_.js"),d=require("@kuma-ui/core"),e=require("react"),_=require("../focus-trap-react-CcpTuiJi.js"),w=require("./atom.js"),D=e.createContext({isVisible:!1}),{Provider:z}=D;function B(){return e.useContext(D)}function $({as:i,className:n,...o}){return s.jsxRuntimeExports.jsx(w.default,{as:i??w.defaultAtomElementType,...o,className:d.cx("kakadu-components-2845019685",n)})}function H({as:i,isVisible:n,label:o,shouldCloseOnOutsideClick:m=!0,shouldCloseOnEscapePress:r=!0,children:u,className:k,innerClassName:R,onClose:c,...p}){const a=e.useRef(null),x=e.useRef(null),[T,V]=e.useState(!1),[l,h]=e.useState(!1),C=e.useCallback(t=>{a.current=t,h(!1)},[]),E=e.useRef(null),M=e.useCallback(t=>{t&&(E.current=t)},[]),A=e.useMemo(()=>({initialFocus:()=>E.current??void 0,onActivate:()=>{var t;return(t=E.current)==null?void 0:t.focus()},clickOutsideDeactivates:m,escapeDeactivates:r,onDeactivate(){h(!1)}}),[m,r]),[I,S]=e.useState(n??!1),W=e.useMemo(()=>({isVisible:I,setInitialFocus:M,close:C}),[I,M,C]),[f,q]=e.useState("center");return e.useEffect(()=>{const t=x.current;if(t){const g=()=>{const N=t.offsetParent,b=N instanceof HTMLElement?N.getBoundingClientRect():null,F=t.getBoundingClientRect();if(!b){q("center");return}const P=b.left+b.width/2-F.width/2,L=P+F.width,O=P<0,y=L>window.innerWidth;let v="center";if(O&&y){const j=Math.abs(P);v=L-window.innerWidth>j?"right":"left"}else y?v="right":O&&(v="left");q(j=>j===v?j:v)};return g(),window.addEventListener("resize",g),()=>{window.removeEventListener("resize",g)}}},[]),e.useEffect(()=>{n&&(V(!0),S(!0))},[n]),e.useEffect(()=>{if(n){const t=setTimeout(()=>{h(!0)},100);return()=>{clearTimeout(t)}}h(!1)},[n]),e.useEffect(()=>{if(T&&!l){const t=setTimeout(()=>{c==null||c(a.current??void 0),S(!1)},370);return()=>{clearTimeout(t)}}},[T,l,c]),s.jsxRuntimeExports.jsx(w.default,{reference:x,as:i??w.defaultAtomElementType,role:"dialog","aria-hidden":!l,"aria-label":o??"Popover",...p,className:d.cx("kakadu-components-3920007758",f==="left"&&"kakadu-components-611400930",f==="right"&&"kakadu-components-944244368",l&&"kakadu-components-1399012551",k),children:s.jsxRuntimeExports.jsxs("div",{className:d.cx("kakadu-components-1118152266",l&&"kakadu-components-231244945"),children:[s.jsxRuntimeExports.jsx("div",{className:d.cx("kakadu-components-2899069338",f==="left"&&"kakadu-components-1495725644",f==="right"&&"kakadu-components-4235689197")}),s.jsxRuntimeExports.jsx(_.focusTrapReactExports.FocusTrap,{active:l,focusTrapOptions:A,children:s.jsxRuntimeExports.jsxs("div",{className:d.cx("kakadu-components-3905822111",R),children:[s.jsxRuntimeExports.jsx(z,{value:W,children:u}),s.jsxRuntimeExports.jsx("div",{className:d.cx("kakadu-components-3328048824",f==="left"&&"kakadu-components-3754561431",f==="right"&&"kakadu-components-2265262600")})]})})]})})}function G(i,n){const[o,m]=e.useState(!1),r=e.useRef(void 0),u=e.useRef(null),k=e.useCallback(async p=>(m(!0),u.current=p??document.activeElement,new Promise(a=>{r.current=a})),[]),R=e.useCallback(p=>{var a;if(m(!1),(a=r.current)==null||a.call(r,p),r.current=void 0,u.current){const x=u.current;x.isConnected&&x.focus(),u.current=null}},[]),c=e.useMemo(()=>s.jsxRuntimeExports.jsx(i,{...n,isVisible:o,onClose:R}),[i,n,o,R]);return e.useMemo(()=>({isVisible:o,show:k,popover:c}),[o,k,c])}exports.PopoverContainer=$;exports.default=H;exports.usePopover=G;exports.usePopoverContext=B;
|
|
@@ -1,114 +1,124 @@
|
|
|
1
1
|
import { j as n } from "../jsx-runtime-B4hRZ52C.mjs";
|
|
2
|
-
import { cx as
|
|
3
|
-
import { createContext as
|
|
4
|
-
import { f as
|
|
5
|
-
import
|
|
6
|
-
const
|
|
2
|
+
import { cx as f } from "@kuma-ui/core";
|
|
3
|
+
import { createContext as K, useRef as h, useState as v, useCallback as T, useMemo as P, useEffect as R, useContext as Q } from "react";
|
|
4
|
+
import { f as U } from "../focus-trap-react-DYXrtbDH.mjs";
|
|
5
|
+
import B, { defaultAtomElementType as H } from "./atom.mjs";
|
|
6
|
+
const S = K({
|
|
7
7
|
isVisible: !1
|
|
8
8
|
}), {
|
|
9
|
-
Provider:
|
|
10
|
-
} =
|
|
11
|
-
function
|
|
12
|
-
return S
|
|
9
|
+
Provider: X
|
|
10
|
+
} = S;
|
|
11
|
+
function ne() {
|
|
12
|
+
return Q(S);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
as:
|
|
14
|
+
function se({
|
|
15
|
+
as: i,
|
|
16
16
|
className: t,
|
|
17
17
|
...s
|
|
18
18
|
}) {
|
|
19
|
-
return /* @__PURE__ */ n.jsx(
|
|
19
|
+
return /* @__PURE__ */ n.jsx(B, { as: i ?? H, ...s, className: f("kakadu-components-2845019685", t) });
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
as:
|
|
21
|
+
function oe({
|
|
22
|
+
as: i,
|
|
23
23
|
isVisible: t,
|
|
24
24
|
label: s,
|
|
25
|
-
shouldCloseOnOutsideClick:
|
|
25
|
+
shouldCloseOnOutsideClick: d = !0,
|
|
26
26
|
shouldCloseOnEscapePress: o = !0,
|
|
27
|
-
children:
|
|
28
|
-
className:
|
|
27
|
+
children: a,
|
|
28
|
+
className: w,
|
|
29
29
|
innerClassName: x,
|
|
30
|
-
onClose:
|
|
30
|
+
onClose: r,
|
|
31
31
|
...m
|
|
32
32
|
}) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
}, []),
|
|
36
|
-
e && (
|
|
37
|
-
}, []),
|
|
38
|
-
initialFocus: () =>
|
|
33
|
+
const c = h(null), p = h(null), [F, q] = v(!1), [u, g] = v(!1), L = T((e) => {
|
|
34
|
+
c.current = e, g(!1);
|
|
35
|
+
}, []), b = h(null), D = T((e) => {
|
|
36
|
+
e && (b.current = e);
|
|
37
|
+
}, []), G = P(() => ({
|
|
38
|
+
initialFocus: () => b.current ?? void 0,
|
|
39
39
|
onActivate: () => {
|
|
40
40
|
var e;
|
|
41
|
-
return (e =
|
|
41
|
+
return (e = b.current) == null ? void 0 : e.focus();
|
|
42
42
|
},
|
|
43
|
-
clickOutsideDeactivates:
|
|
43
|
+
clickOutsideDeactivates: d,
|
|
44
44
|
escapeDeactivates: o,
|
|
45
45
|
onDeactivate() {
|
|
46
|
-
|
|
46
|
+
g(!1);
|
|
47
47
|
}
|
|
48
|
-
}), [
|
|
49
|
-
isVisible:
|
|
50
|
-
setInitialFocus:
|
|
51
|
-
close:
|
|
52
|
-
}), [
|
|
53
|
-
return
|
|
48
|
+
}), [d, o]), [O, V] = v(t ?? !1), J = P(() => ({
|
|
49
|
+
isVisible: O,
|
|
50
|
+
setInitialFocus: D,
|
|
51
|
+
close: L
|
|
52
|
+
}), [O, D, L]), [l, A] = v("center");
|
|
53
|
+
return R(() => {
|
|
54
54
|
const e = p.current;
|
|
55
55
|
if (e) {
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
56
|
+
const E = () => {
|
|
57
|
+
const C = e.offsetParent, I = C instanceof HTMLElement ? C.getBoundingClientRect() : null, M = e.getBoundingClientRect();
|
|
58
|
+
if (!I) {
|
|
59
|
+
A("center");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const N = I.left + I.width / 2 - M.width / 2, W = N + M.width, y = N < 0, z = W > window.innerWidth;
|
|
63
|
+
let k = "center";
|
|
64
|
+
if (y && z) {
|
|
65
|
+
const j = Math.abs(N);
|
|
66
|
+
k = W - window.innerWidth > j ? "right" : "left";
|
|
67
|
+
} else z ? k = "right" : y && (k = "left");
|
|
68
|
+
A((j) => j === k ? j : k);
|
|
59
69
|
};
|
|
60
|
-
return
|
|
61
|
-
window.removeEventListener("resize",
|
|
70
|
+
return E(), window.addEventListener("resize", E), () => {
|
|
71
|
+
window.removeEventListener("resize", E);
|
|
62
72
|
};
|
|
63
73
|
}
|
|
64
|
-
}, []),
|
|
65
|
-
t && (
|
|
66
|
-
}, [t]),
|
|
74
|
+
}, []), R(() => {
|
|
75
|
+
t && (q(!0), V(!0));
|
|
76
|
+
}, [t]), R(() => {
|
|
67
77
|
if (t) {
|
|
68
78
|
const e = setTimeout(() => {
|
|
69
|
-
|
|
79
|
+
g(!0);
|
|
70
80
|
}, 100);
|
|
71
81
|
return () => {
|
|
72
82
|
clearTimeout(e);
|
|
73
83
|
};
|
|
74
84
|
}
|
|
75
|
-
|
|
76
|
-
}, [t]),
|
|
77
|
-
if (
|
|
85
|
+
g(!1);
|
|
86
|
+
}, [t]), R(() => {
|
|
87
|
+
if (F && !u) {
|
|
78
88
|
const e = setTimeout(() => {
|
|
79
|
-
|
|
89
|
+
r == null || r(c.current ?? void 0), V(!1);
|
|
80
90
|
}, 370);
|
|
81
91
|
return () => {
|
|
82
92
|
clearTimeout(e);
|
|
83
93
|
};
|
|
84
94
|
}
|
|
85
|
-
}, [
|
|
86
|
-
/* @__PURE__ */ n.jsx("div", { className:
|
|
87
|
-
/* @__PURE__ */ n.jsx(
|
|
88
|
-
/* @__PURE__ */ n.jsx(
|
|
89
|
-
/* @__PURE__ */ n.jsx("div", { className:
|
|
95
|
+
}, [F, u, r]), /* @__PURE__ */ n.jsx(B, { reference: p, as: i ?? H, role: "dialog", "aria-hidden": !u, "aria-label": s ?? "Popover", ...m, className: f("kakadu-components-3920007758", l === "left" && "kakadu-components-611400930", l === "right" && "kakadu-components-944244368", u && "kakadu-components-1399012551", w), children: /* @__PURE__ */ n.jsxs("div", { className: f("kakadu-components-1118152266", u && "kakadu-components-231244945"), children: [
|
|
96
|
+
/* @__PURE__ */ n.jsx("div", { className: f("kakadu-components-2899069338", l === "left" && "kakadu-components-1495725644", l === "right" && "kakadu-components-4235689197") }),
|
|
97
|
+
/* @__PURE__ */ n.jsx(U.FocusTrap, { active: u, focusTrapOptions: G, children: /* @__PURE__ */ n.jsxs("div", { className: f("kakadu-components-3905822111", x), children: [
|
|
98
|
+
/* @__PURE__ */ n.jsx(X, { value: J, children: a }),
|
|
99
|
+
/* @__PURE__ */ n.jsx("div", { className: f("kakadu-components-3328048824", l === "left" && "kakadu-components-3754561431", l === "right" && "kakadu-components-2265262600") })
|
|
90
100
|
] }) })
|
|
91
101
|
] }) });
|
|
92
102
|
}
|
|
93
|
-
function
|
|
94
|
-
const [s,
|
|
95
|
-
o.current =
|
|
96
|
-
})), []), x =
|
|
97
|
-
var
|
|
98
|
-
if (
|
|
99
|
-
const p =
|
|
100
|
-
p.isConnected && p.focus(),
|
|
103
|
+
function re(i, t) {
|
|
104
|
+
const [s, d] = v(!1), o = h(void 0), a = h(null), w = T(async (m) => (d(!0), a.current = m ?? document.activeElement, new Promise((c) => {
|
|
105
|
+
o.current = c;
|
|
106
|
+
})), []), x = T((m) => {
|
|
107
|
+
var c;
|
|
108
|
+
if (d(!1), (c = o.current) == null || c.call(o, m), o.current = void 0, a.current) {
|
|
109
|
+
const p = a.current;
|
|
110
|
+
p.isConnected && p.focus(), a.current = null;
|
|
101
111
|
}
|
|
102
|
-
}, []),
|
|
103
|
-
return
|
|
112
|
+
}, []), r = P(() => /* @__PURE__ */ n.jsx(i, { ...t, isVisible: s, onClose: x }), [i, t, s, x]);
|
|
113
|
+
return P(() => ({
|
|
104
114
|
isVisible: s,
|
|
105
|
-
show:
|
|
106
|
-
popover:
|
|
107
|
-
}), [s,
|
|
115
|
+
show: w,
|
|
116
|
+
popover: r
|
|
117
|
+
}), [s, w, r]);
|
|
108
118
|
}
|
|
109
119
|
export {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
se as PopoverContainer,
|
|
121
|
+
oe as default,
|
|
122
|
+
re as usePopover,
|
|
123
|
+
ne as usePopoverContext
|
|
114
124
|
};
|