@kakadu/components 4.6.3 → 4.6.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 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"),p=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:p.cx("kakadu-components-2845019685",s)})}function Z({as:i,isVisible:s,label:l,shouldCloseOnOutsideClick:v=!0,shouldCloseOnEscapePress:r=!0,children:x,className:a,innerClassName:f,onClose:c,...h}){const k=e.useRef(null),R=e.useRef(null),[o,g]=e.useState(!1),[d,j]=e.useState(!1),[A,H]=e.useState(!1),[u,E]=e.useState(!1),[U,T]=e.useState(!1),N=e.useCallback(t=>{k.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),g(!1),(t=b.current)==null||t.focus()},clickOutsideDeactivates:v,escapeDeactivates:r,onPostUnpause(){j(!0)},onPause(){j(!1)},onDeactivate(){T(!1),E(!1),j(!1)}}),[v,r]),[I,O]=e.useState(s??!1),J=e.useMemo(()=>({isVisible:I,isPreparingFocus:o,isFocused:d,setInitialFocus:L,close:N}),[I,o,d,L,N]),[m,y]=e.useState("center");return e.useEffect(()=>{const t=R.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 w="center";if(B&&W){const P=C-q;w=z-_>P?"right":"left"}else W?w="right":B&&(w="left");y(P=>P===w?P:w)};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),g(!1);return}g(!0);const t=window.requestAnimationFrame(()=>{T(!0)});return()=>{window.cancelAnimationFrame(t)}},[u]),e.useEffect(()=>{if(A&&!u){const t=setTimeout(()=>{O(!1),c==null||c(k.current??void 0)},370);return()=>{clearTimeout(t)}}},[A,u,c]),I?n.jsxRuntimeExports.jsx(F.default,{reference:R,as:i??F.defaultAtomElementType,role:"dialog","aria-hidden":!u&&!d,"aria-label":l??"Popover",...h,className:p.cx("kakadu-components-3920007758",m==="left"&&"kakadu-components-611400930",m==="right"&&"kakadu-components-944244368",u&&"kakadu-components-1399012551",a),children:n.jsxRuntimeExports.jsxs("div",{className:p.cx("kakadu-components-1118152266",u&&"kakadu-components-231244945"),children:[n.jsxRuntimeExports.jsx("div",{className:p.cx("kakadu-components-1951789226",m==="left"&&"kakadu-components-1495725644",m==="right"&&"kakadu-components-4235689197")}),n.jsxRuntimeExports.jsx(K.focusTrapReactExports.FocusTrap,{active:U,focusTrapOptions:G,children:n.jsxRuntimeExports.jsxs("div",{className:p.cx("kakadu-components-2488426662",f),children:[n.jsxRuntimeExports.jsx(Q,{value:J,children:x}),n.jsxRuntimeExports.jsx("div",{className:p.cx("kakadu-components-3252390100",m==="left"&&"kakadu-components-3754561431",m==="right"&&"kakadu-components-2265262600")})]})})]})}):null}function ee(i,s){const[l,v]=e.useState(!1),[r,x]=e.useState(!1),a=e.useRef(void 0),f=e.useRef(void 0),c=e.useCallback(async()=>(f.current=void 0,v(!0),x(!0),new Promise(o=>{a.current=o})),[]),h=e.useCallback(o=>{f.current=o,x(!1)},[]),k=e.useCallback(o=>{var d;const g=o??f.current;f.current=void 0,(d=a.current)==null||d.call(a,g),a.current=void 0,v(!1),x(!1)},[]),R=e.useMemo(()=>l?n.jsxRuntimeExports.jsx(i,{...s,isVisible:r,onClose:k}):null,[l,i,s,r,k]);return e.useMemo(()=>({isVisible:r,show:c,close:h,popover:R}),[r,c,h,R])}exports.PopoverContainer=Y;exports.default=Z;exports.usePopover=ee;exports.usePopoverContext=X;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { j as s } from "../jsx-runtime-B4hRZ52C.mjs";
|
|
2
|
-
import { cx as
|
|
2
|
+
import { cx as p } from "@kuma-ui/core";
|
|
3
3
|
import { createContext as ee, useRef as P, useState as n, useCallback as R, useMemo as b, useEffect as F, useContext as te } from "react";
|
|
4
4
|
import { f as se } from "../focus-trap-react-Dr3BYLw6.mjs";
|
|
5
5
|
import K, { defaultAtomElementType as Q } from "./atom.mjs";
|
|
@@ -18,31 +18,31 @@ function fe({
|
|
|
18
18
|
className: t,
|
|
19
19
|
...l
|
|
20
20
|
}) {
|
|
21
|
-
return /* @__PURE__ */ s.jsx(K, { as: u ?? Q, ...l, className:
|
|
21
|
+
return /* @__PURE__ */ s.jsx(K, { as: u ?? Q, ...l, className: p("kakadu-components-2845019685", t) });
|
|
22
22
|
}
|
|
23
23
|
function de({
|
|
24
24
|
as: u,
|
|
25
25
|
isVisible: t,
|
|
26
26
|
label: l,
|
|
27
|
-
shouldCloseOnOutsideClick:
|
|
27
|
+
shouldCloseOnOutsideClick: v = !0,
|
|
28
28
|
shouldCloseOnEscapePress: r = !0,
|
|
29
|
-
children:
|
|
29
|
+
children: k,
|
|
30
30
|
className: a,
|
|
31
31
|
innerClassName: f,
|
|
32
32
|
onClose: c,
|
|
33
33
|
...j
|
|
34
34
|
}) {
|
|
35
|
-
const
|
|
36
|
-
|
|
35
|
+
const w = P(null), g = P(null), [o, h] = n(!1), [d, I] = n(!1), [y, Y] = n(!1), [i, T] = n(!1), [Z, E] = n(!1), z = R((e) => {
|
|
36
|
+
w.current = e, T(!1);
|
|
37
37
|
}, []), N = P(null), B = R((e) => {
|
|
38
38
|
e && (N.current = e);
|
|
39
39
|
}, []), _ = b(() => ({
|
|
40
40
|
initialFocus: () => N.current ?? void 0,
|
|
41
41
|
onPostActivate() {
|
|
42
42
|
var e;
|
|
43
|
-
I(!0),
|
|
43
|
+
I(!0), h(!1), (e = N.current) == null || e.focus();
|
|
44
44
|
},
|
|
45
|
-
clickOutsideDeactivates:
|
|
45
|
+
clickOutsideDeactivates: v,
|
|
46
46
|
escapeDeactivates: r,
|
|
47
47
|
onPostUnpause() {
|
|
48
48
|
I(!0);
|
|
@@ -53,15 +53,15 @@ function de({
|
|
|
53
53
|
onDeactivate() {
|
|
54
54
|
E(!1), T(!1), I(!1);
|
|
55
55
|
}
|
|
56
|
-
}), [
|
|
56
|
+
}), [v, r]), [L, C] = n(t ?? !1), $ = b(() => ({
|
|
57
57
|
isVisible: L,
|
|
58
58
|
isPreparingFocus: o,
|
|
59
|
-
isFocused:
|
|
59
|
+
isFocused: d,
|
|
60
60
|
setInitialFocus: B,
|
|
61
61
|
close: z
|
|
62
|
-
}), [L, o,
|
|
62
|
+
}), [L, o, d, B, z]), [m, W] = n("center");
|
|
63
63
|
return F(() => {
|
|
64
|
-
const e =
|
|
64
|
+
const e = g.current;
|
|
65
65
|
if (e) {
|
|
66
66
|
const D = () => {
|
|
67
67
|
const q = e.offsetParent, M = q instanceof HTMLElement ? q.getBoundingClientRect() : null, H = e.getBoundingClientRect();
|
|
@@ -95,10 +95,10 @@ function de({
|
|
|
95
95
|
T(!1);
|
|
96
96
|
}, [t]), F(() => {
|
|
97
97
|
if (!i) {
|
|
98
|
-
E(!1),
|
|
98
|
+
E(!1), h(!1);
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
h(!0);
|
|
102
102
|
const e = window.requestAnimationFrame(() => {
|
|
103
103
|
E(!0);
|
|
104
104
|
});
|
|
@@ -108,36 +108,36 @@ function de({
|
|
|
108
108
|
}, [i]), F(() => {
|
|
109
109
|
if (y && !i) {
|
|
110
110
|
const e = setTimeout(() => {
|
|
111
|
-
C(!1), c == null || c(
|
|
111
|
+
C(!1), c == null || c(w.current ?? void 0);
|
|
112
112
|
}, 370);
|
|
113
113
|
return () => {
|
|
114
114
|
clearTimeout(e);
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
|
-
}, [y, i, c]), L ? /* @__PURE__ */ s.jsx(K, { reference:
|
|
118
|
-
/* @__PURE__ */ s.jsx("div", { className:
|
|
119
|
-
/* @__PURE__ */ s.jsx(se.FocusTrap, { active: Z, focusTrapOptions: _, children: /* @__PURE__ */ s.jsxs("div", { className:
|
|
120
|
-
/* @__PURE__ */ s.jsx(ne, { value: $, children:
|
|
121
|
-
/* @__PURE__ */ s.jsx("div", { className:
|
|
117
|
+
}, [y, i, c]), L ? /* @__PURE__ */ s.jsx(K, { reference: g, as: u ?? Q, role: "dialog", "aria-hidden": !i && !d, "aria-label": l ?? "Popover", ...j, className: p("kakadu-components-3920007758", m === "left" && "kakadu-components-611400930", m === "right" && "kakadu-components-944244368", i && "kakadu-components-1399012551", a), children: /* @__PURE__ */ s.jsxs("div", { className: p("kakadu-components-1118152266", i && "kakadu-components-231244945"), children: [
|
|
118
|
+
/* @__PURE__ */ s.jsx("div", { className: p("kakadu-components-1951789226", m === "left" && "kakadu-components-1495725644", m === "right" && "kakadu-components-4235689197") }),
|
|
119
|
+
/* @__PURE__ */ s.jsx(se.FocusTrap, { active: Z, focusTrapOptions: _, children: /* @__PURE__ */ s.jsxs("div", { className: p("kakadu-components-2488426662", f), children: [
|
|
120
|
+
/* @__PURE__ */ s.jsx(ne, { value: $, children: k }),
|
|
121
|
+
/* @__PURE__ */ s.jsx("div", { className: p("kakadu-components-3252390100", m === "left" && "kakadu-components-3754561431", m === "right" && "kakadu-components-2265262600") })
|
|
122
122
|
] }) })
|
|
123
123
|
] }) }) : null;
|
|
124
124
|
}
|
|
125
125
|
function me(u, t) {
|
|
126
|
-
const [l,
|
|
126
|
+
const [l, v] = n(!1), [r, k] = n(!1), a = P(void 0), f = P(void 0), c = R(async () => (f.current = void 0, v(!0), k(!0), new Promise((o) => {
|
|
127
127
|
a.current = o;
|
|
128
128
|
})), []), j = R((o) => {
|
|
129
|
-
f.current = o,
|
|
130
|
-
}, []),
|
|
131
|
-
var
|
|
132
|
-
const
|
|
133
|
-
f.current = void 0, (
|
|
134
|
-
}, []),
|
|
129
|
+
f.current = o, k(!1);
|
|
130
|
+
}, []), w = R((o) => {
|
|
131
|
+
var d;
|
|
132
|
+
const h = o ?? f.current;
|
|
133
|
+
f.current = void 0, (d = a.current) == null || d.call(a, h), a.current = void 0, v(!1), k(!1);
|
|
134
|
+
}, []), g = b(() => l ? /* @__PURE__ */ s.jsx(u, { ...t, isVisible: r, onClose: w }) : null, [l, u, t, r, w]);
|
|
135
135
|
return b(() => ({
|
|
136
136
|
isVisible: r,
|
|
137
137
|
show: c,
|
|
138
138
|
close: j,
|
|
139
|
-
popover:
|
|
140
|
-
}), [r, c, j,
|
|
139
|
+
popover: g
|
|
140
|
+
}), [r, c, j, g]);
|
|
141
141
|
}
|
|
142
142
|
export {
|
|
143
143
|
fe as PopoverContainer,
|