@kakadu/components 3.15.3 → 3.15.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.
|
@@ -23,6 +23,7 @@ export type PopoverMenuItemProperties = {
|
|
|
23
23
|
readonly onMouseEnter?: (event: MouseEvent<PopoverMenuItemElementType>) => void;
|
|
24
24
|
};
|
|
25
25
|
export declare function usePopoverMenu(items: PopoverMenuItemProperties[]): {
|
|
26
|
+
isVisible: boolean;
|
|
26
27
|
show: () => Promise<void | undefined>;
|
|
27
28
|
close: (result?: void | undefined) => void;
|
|
28
29
|
popoverMenu: import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../jsx-runtime-BB_1_6y_.js"),_=require("@kuma-ui/core"),i=require("react"),N=require("../theme.js"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../jsx-runtime-BB_1_6y_.js"),_=require("@kuma-ui/core"),i=require("react"),N=require("../theme.js"),b=require("../icons/icon.js"),v=require("./popover.js"),C=require("./atom.js"),P=require("./text.js"),w=require("./hover-gradient.js"),F=require("./click-ripples.js"),K=require("./separator.js"),z=require("./decorators.js"),M=require("./spinner.js"),A=require("./skeleton.js"),D=require("./aria-text.js"),k=new Set;function q(){const[t,s]=i.useState(!1),r=i.useCallback(u=>{s(u);for(const n of k)n(u)},[]);return i.useEffect(()=>{const u=n=>{s(n)};return k.add(u),()=>{k.delete(u)}},[]),i.useMemo(()=>({isKeyboardNavigating:t,setIsKeyboardNavigating:r}),[t,r])}const T="kakadu-components-949294122";function V({isLoading:t,label:s,iconLeft:r,iconRight:u,href:n,shouldCloseOnClick:d=!0,decorators:E=[],submenu:o,className:c,onClick:p,...m}){const{isVisible:x,isPreparingFocus:j,isFocused:a,close:l}=v.usePopoverContext(),{isKeyboardNavigating:f}=q(),R=i.useRef(!0),h=i.useCallback(()=>{R.current=a},[a]),y=i.useCallback(S=>{!f&&!R.current||a&&(p==null||p(S),o?o.show():d&&(l==null||l()))},[f,a,p,o,d,l]),g=i.useMemo(()=>e.jsxRuntimeExports.jsxs(C.default,{as:n&&!t?"a":"button",...m,type:n&&!t?void 0:"button",role:"menuitem",href:n,inert:!x&&!j||t,disabled:n?void 0:!x&&!j||t,className:_.cx(N.buttonResetStyles,"kakadu-components-1772835671",a&&"kakadu-components-3160069815",f?"kakadu-components-2254977234":a&&"kakadu-components-278139688",c),onClick:y,onPointerDownCapture:h,children:[e.jsxRuntimeExports.jsx(P.Span,{className:"kakadu-components-1109353535",children:t?e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(D.default,{children:s}),r?e.jsxRuntimeExports.jsx(M.default,{size:12}):null,e.jsxRuntimeExports.jsx(A.SkeletonInstance,{height:"1em",width:"100%"}),u?e.jsxRuntimeExports.jsx(M.default,{size:12}):null]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[r?e.jsxRuntimeExports.jsx(b.default,{width:12,height:12,type:r}):null,e.jsxRuntimeExports.jsx("span",{className:"kakadu-components-4055589237",children:s}),u?e.jsxRuntimeExports.jsx(b.default,{width:12,height:12,type:u}):null]})}),f||t?null:e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(F.default,{isActive:a,size:100}),e.jsxRuntimeExports.jsx(w.default,{isActive:a,size:150,className:w.normalBlendStyles})]})]}),[n,t,m,x,j,f,c,y,h,r,s,u,a]);return e.jsxRuntimeExports.jsx(z.default,{decorators:E,children:o?e.jsxRuntimeExports.jsx(I,{menu:o.popoverMenu,className:"kakadu-components-1861176543",children:g}):g})}function H(t){if("type"in t){if(t.type==="separator")return e.jsxRuntimeExports.jsx(K.default,{});if(t.type==="group")return e.jsxRuntimeExports.jsx(P.Span,{className:"kakadu-components-1499037363",children:t.label})}return e.jsxRuntimeExports.jsx(V,{...t})}function $({items:t}){const{isFocused:s}=v.usePopoverContext(),[r,u]=i.useState([]),{setIsKeyboardNavigating:n}=q(),d=i.useCallback(o=>{o&&u(c=>c.includes(o)?c:[...c,o])},[]),E=i.useCallback(o=>{s&&(o.currentTarget.focus(),n(!1))},[s,n]);return i.useEffect(()=>{if(!s)return;const o=c=>{const p=r.filter(l=>l.isConnected),m=p.length;if(m===0)return;let x;const j=document.activeElement;let a=j?p.indexOf(j):-1;switch(a===-1&&(a=0),c.key){case"ArrowDown":{x=(a+1)%m;break}case"ArrowUp":{x=(a-1+m)%m;break}case"Home":{x=0;break}case"End":{x=m-1;break}case"Tab":{n(!0);return}}if(x!==void 0){c.preventDefault(),c.stopPropagation();const l=p[x];l&&(l.focus(),n(!0))}};return window.addEventListener("keydown",o,{capture:!0}),()=>{window.removeEventListener("keydown",o,{capture:!0})}},[s,r,n]),e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:t.map((o,c)=>e.jsxRuntimeExports.jsx(H,{...o,reference:d,onMouseEnter:E},c))})}function B({items:t,...s}){return e.jsxRuntimeExports.jsx(v.default,{...s,as:"nav",role:"menu",innerClassName:"kakadu-components-3600436535",children:e.jsxRuntimeExports.jsx($,{items:t})})}function G(t){const s=i.useMemo(()=>({items:t}),[t]),{isVisible:r,show:u,close:n,popover:d}=v.usePopover(B,s);return i.useMemo(()=>({isVisible:r,show:u,close:n,popoverMenu:d}),[r,u,n,d])}function I({menu:t,className:s,children:r}){return e.jsxRuntimeExports.jsxs(v.PopoverContainer,{className:s,children:[r,t]})}exports.dangerPopoverMenuItemStyles=T;exports.default=I;exports.usePopoverMenu=G;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { j as e } from "../jsx-runtime-B4hRZ52C.mjs";
|
|
2
2
|
import { cx as K } from "@kuma-ui/core";
|
|
3
|
-
import { useMemo as k, useState as N, useCallback as
|
|
3
|
+
import { useMemo as k, useState as N, useCallback as v, useEffect as M, useRef as C } from "react";
|
|
4
4
|
import { buttonResetStyles as D } from "../theme.mjs";
|
|
5
5
|
import P from "../icons/icon.mjs";
|
|
6
6
|
import z, { PopoverContainer as H, usePopover as T, usePopoverContext as S } from "./popover.mjs";
|
|
7
|
-
import
|
|
7
|
+
import V from "./atom.mjs";
|
|
8
8
|
import { Span as E } from "./text.mjs";
|
|
9
|
-
import
|
|
9
|
+
import R, { normalBlendStyles as B } from "./hover-gradient.mjs";
|
|
10
10
|
import G from "./click-ripples.mjs";
|
|
11
11
|
import U from "./separator.mjs";
|
|
12
12
|
import q from "./decorators.mjs";
|
|
@@ -15,7 +15,7 @@ import { SkeletonInstance as J } from "./skeleton.mjs";
|
|
|
15
15
|
import O from "./aria-text.mjs";
|
|
16
16
|
const h = /* @__PURE__ */ new Set();
|
|
17
17
|
function F() {
|
|
18
|
-
const [n, r] = N(!1), s =
|
|
18
|
+
const [n, r] = N(!1), s = v((a) => {
|
|
19
19
|
r(a);
|
|
20
20
|
for (const t of h)
|
|
21
21
|
t(a);
|
|
@@ -39,7 +39,7 @@ function Q({
|
|
|
39
39
|
iconLeft: s,
|
|
40
40
|
iconRight: a,
|
|
41
41
|
href: t,
|
|
42
|
-
shouldCloseOnClick:
|
|
42
|
+
shouldCloseOnClick: d = !0,
|
|
43
43
|
decorators: j = [],
|
|
44
44
|
submenu: o,
|
|
45
45
|
className: c,
|
|
@@ -48,16 +48,16 @@ function Q({
|
|
|
48
48
|
}) {
|
|
49
49
|
const {
|
|
50
50
|
isVisible: u,
|
|
51
|
-
isPreparingFocus:
|
|
51
|
+
isPreparingFocus: f,
|
|
52
52
|
isFocused: i,
|
|
53
53
|
close: m
|
|
54
54
|
} = S(), {
|
|
55
|
-
isKeyboardNavigating:
|
|
56
|
-
} = F(), w = C(!0), y =
|
|
55
|
+
isKeyboardNavigating: x
|
|
56
|
+
} = F(), w = C(!0), y = v(() => {
|
|
57
57
|
w.current = i;
|
|
58
|
-
}, [i]), g =
|
|
59
|
-
!
|
|
60
|
-
}, [
|
|
58
|
+
}, [i]), g = v((A) => {
|
|
59
|
+
!x && !w.current || i && (l == null || l(A), o ? o.show() : d && (m == null || m()));
|
|
60
|
+
}, [x, i, l, o, d, m]), I = k(() => /* @__PURE__ */ e.jsxs(V, { as: t && !n ? "a" : "button", ...p, type: t && !n ? void 0 : "button", role: "menuitem", href: t, inert: !u && !f || n, disabled: t ? void 0 : !u && !f || n, className: K(D, "kakadu-components-1772835671", i && "kakadu-components-3160069815", x ? "kakadu-components-2254977234" : i && "kakadu-components-278139688", c), onClick: g, onPointerDownCapture: y, children: [
|
|
61
61
|
/* @__PURE__ */ e.jsx(E, { className: "kakadu-components-1109353535", children: n ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
|
|
62
62
|
/* @__PURE__ */ e.jsx(O, { children: r }),
|
|
63
63
|
s ? /* @__PURE__ */ e.jsx(b, { size: 12 }) : null,
|
|
@@ -68,11 +68,11 @@ function Q({
|
|
|
68
68
|
/* @__PURE__ */ e.jsx("span", { className: "kakadu-components-4055589237", children: r }),
|
|
69
69
|
a ? /* @__PURE__ */ e.jsx(P, { width: 12, height: 12, type: a }) : null
|
|
70
70
|
] }) }),
|
|
71
|
-
|
|
71
|
+
x || n ? null : /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
|
|
72
72
|
/* @__PURE__ */ e.jsx(G, { isActive: i, size: 100 }),
|
|
73
|
-
/* @__PURE__ */ e.jsx(
|
|
73
|
+
/* @__PURE__ */ e.jsx(R, { isActive: i, size: 150, className: B })
|
|
74
74
|
] })
|
|
75
|
-
] }), [t, n, p, u,
|
|
75
|
+
] }), [t, n, p, u, f, x, c, g, y, s, r, a, i]);
|
|
76
76
|
return /* @__PURE__ */ e.jsx(q, { decorators: j, children: o ? /* @__PURE__ */ e.jsx(Z, { menu: o.popoverMenu, className: "kakadu-components-1861176543", children: I }) : I });
|
|
77
77
|
}
|
|
78
78
|
function W(n) {
|
|
@@ -91,9 +91,9 @@ function X({
|
|
|
91
91
|
isFocused: r
|
|
92
92
|
} = S(), [s, a] = N([]), {
|
|
93
93
|
setIsKeyboardNavigating: t
|
|
94
|
-
} = F(),
|
|
94
|
+
} = F(), d = v((o) => {
|
|
95
95
|
o && a((c) => c.includes(o) ? c : [...c, o]);
|
|
96
|
-
}, []), j =
|
|
96
|
+
}, []), j = v((o) => {
|
|
97
97
|
r && (o.currentTarget.focus(), t(!1));
|
|
98
98
|
}, [r, t]);
|
|
99
99
|
return M(() => {
|
|
@@ -104,8 +104,8 @@ function X({
|
|
|
104
104
|
if (p === 0)
|
|
105
105
|
return;
|
|
106
106
|
let u;
|
|
107
|
-
const
|
|
108
|
-
let i =
|
|
107
|
+
const f = document.activeElement;
|
|
108
|
+
let i = f ? l.indexOf(f) : -1;
|
|
109
109
|
switch (i === -1 && (i = 0), c.key) {
|
|
110
110
|
case "ArrowDown": {
|
|
111
111
|
u = (i + 1) % p;
|
|
@@ -145,7 +145,7 @@ function X({
|
|
|
145
145
|
W,
|
|
146
146
|
{
|
|
147
147
|
...o,
|
|
148
|
-
reference:
|
|
148
|
+
reference: d,
|
|
149
149
|
onMouseEnter: j
|
|
150
150
|
},
|
|
151
151
|
c
|
|
@@ -161,15 +161,17 @@ function de(n) {
|
|
|
161
161
|
const r = k(() => ({
|
|
162
162
|
items: n
|
|
163
163
|
}), [n]), {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
isVisible: s,
|
|
165
|
+
show: a,
|
|
166
|
+
close: t,
|
|
167
|
+
popover: d
|
|
167
168
|
} = T(Y, r);
|
|
168
169
|
return k(() => ({
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
isVisible: s,
|
|
171
|
+
show: a,
|
|
172
|
+
close: t,
|
|
173
|
+
popoverMenu: d
|
|
174
|
+
}), [s, a, t, d]);
|
|
173
175
|
}
|
|
174
176
|
function Z({
|
|
175
177
|
menu: n,
|