@kakadu/components 3.1.3 → 3.1.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,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type MouseEvent, type ReactNode, type Ref } from 'react';
|
|
2
2
|
import { type IconType } from '../icons/icon';
|
|
3
3
|
import { type DecoratorType } from './decorators';
|
|
4
4
|
type PopoverMenuItemElementType = HTMLButtonElement | HTMLAnchorElement;
|
|
@@ -18,7 +18,6 @@ export type PopoverMenuItemProperties = {
|
|
|
18
18
|
readonly decorators?: DecoratorType[];
|
|
19
19
|
readonly className?: string;
|
|
20
20
|
readonly onClick?: (event: MouseEvent<PopoverMenuItemElementType>) => void;
|
|
21
|
-
readonly onFocus?: (event: FocusEvent<PopoverMenuItemElementType>) => void;
|
|
22
21
|
readonly onMouseEnter?: (event: MouseEvent<PopoverMenuItemElementType>) => void;
|
|
23
22
|
};
|
|
24
23
|
export declare function usePopoverMenu(items: PopoverMenuItemProperties[]): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("../jsx-runtime-BB_1_6y_.js"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("../jsx-runtime-BB_1_6y_.js"),M=require("@kuma-ui/core"),a=require("react"),b=require("../theme.js"),k=require("../icons/icon.js"),j=require("./popover.js"),q=require("./atom.js"),g=require("./text.js"),R=require("./hover-gradient.js"),P=require("./click-ripples.js"),I=require("./separator.js"),N=require("./decorators.js"),v=new Set;function h(){const[e,n]=a.useState(!1),s=a.useCallback(o=>{n(o);for(const i of v)i(o)},[]);return a.useEffect(()=>{const o=i=>{n(i)};return v.add(o),()=>{v.delete(o)}},[]),a.useMemo(()=>({isKeyboardNavigating:e,setIsKeyboardNavigating:s}),[e,s])}function S({label:e,iconLeft:n,iconRight:s,href:o,shouldCloseOnClick:i=!0,decorators:f=[],submenu:p,className:u,onClick:r,...l}){const{isFocused:c,close:x}=j.usePopoverContext(),{isKeyboardNavigating:d}=h(),m=a.useCallback(w=>{c&&(r==null||r(w),p?p.show():i&&(x==null||x()))},[c,r,i,x,p]),E=a.useMemo(()=>t.jsxRuntimeExports.jsxs(q.default,{as:o?"a":"button",...l,type:o?void 0:"button",role:"menuitem",href:o,className:M.cx(b.buttonResetStyles,"kakadu-components-3114599304",d?"kakadu-components-4096376656":"kakadu-components-2554182777",u),onClick:m,children:[t.jsxRuntimeExports.jsxs(g.Span,{className:"kakadu-components-1109353535",children:[n?t.jsxRuntimeExports.jsx(k.default,{width:12,height:12,type:n}):null,t.jsxRuntimeExports.jsx("span",{className:"kakadu-components-913703148",children:e}),s?t.jsxRuntimeExports.jsx(k.default,{width:12,height:12,type:s}):null]}),d?null:t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(R.default,{size:150,className:R.normalBlendStyles}),t.jsxRuntimeExports.jsx(P.default,{size:100})]})]}),[d,l,o,u,m,n,e,s]);return t.jsxRuntimeExports.jsx(N.default,{decorators:f,children:p?t.jsxRuntimeExports.jsx(y,{menu:p.popoverMenu,className:"kakadu-components-1861176543",children:E}):E})}function _(e){if("type"in e){if(e.type==="separator")return t.jsxRuntimeExports.jsx(I.default,{});if(e.type==="group")return t.jsxRuntimeExports.jsx(g.Span,{className:"kakadu-components-1499037363",children:e.label})}return t.jsxRuntimeExports.jsx(S,{...e})}function K({items:e}){const{isFocused:n}=j.usePopoverContext(),[s,o]=a.useState([]),{setIsKeyboardNavigating:i}=h(),f=a.useCallback(u=>{u&&o(r=>[...r,u])},[]),p=a.useCallback(u=>{n&&(u.currentTarget.focus(),i(!1))},[n,i]);return a.useEffect(()=>{if(!n)return;const u=r=>{const l=s.length;if(l===0)return;let c;const x=document.activeElement,d=x?s.indexOf(x):0;switch(r.key){case"ArrowDown":{c=(d+1)%l;break}case"ArrowUp":{c=(d-1+l)%l;break}case"Home":{c=0;break}case"End":{c=l-1;break}}if(c!==void 0){r.preventDefault(),r.stopPropagation();const m=s[c];m&&(m.focus(),i(!0))}};return window.addEventListener("keydown",u,{capture:!0}),()=>{window.removeEventListener("keydown",u,{capture:!0})}},[n,s,i]),t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:e.map((u,r)=>t.jsxRuntimeExports.jsx(_,{...u,reference:f,onMouseEnter:p},r))})}function C({items:e,...n}){return t.jsxRuntimeExports.jsx(j.default,{...n,as:"nav",role:"menu",innerClassName:"kakadu-components-3600436535",children:t.jsxRuntimeExports.jsx(K,{items:e})})}function F(e){const n=a.useMemo(()=>({items:e}),[e]),{show:s,popover:o}=j.usePopover(C,n);return a.useMemo(()=>({show:s,popoverMenu:o}),[s,o])}function y({menu:e,className:n,children:s}){return t.jsxRuntimeExports.jsxs(j.PopoverContainer,{className:n,children:[s,e]})}exports.default=y;exports.usePopoverMenu=F;
|
|
@@ -1,122 +1,118 @@
|
|
|
1
1
|
import { j as n } from "../jsx-runtime-B4hRZ52C.mjs";
|
|
2
2
|
import { cx as b } from "@kuma-ui/core";
|
|
3
|
-
import { useMemo as
|
|
4
|
-
import { buttonResetStyles as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
3
|
+
import { useMemo as f, useState as h, useCallback as v, useEffect as y } from "react";
|
|
4
|
+
import { buttonResetStyles as E } from "../theme.mjs";
|
|
5
|
+
import g from "../icons/icon.mjs";
|
|
6
|
+
import M, { PopoverContainer as S, usePopover as K, usePopoverContext as w } from "./popover.mjs";
|
|
7
|
+
import F from "./atom.mjs";
|
|
8
8
|
import { Span as I } from "./text.mjs";
|
|
9
9
|
import A, { normalBlendStyles as D } from "./hover-gradient.mjs";
|
|
10
10
|
import H from "./click-ripples.mjs";
|
|
11
11
|
import z from "./separator.mjs";
|
|
12
|
-
import
|
|
13
|
-
const
|
|
12
|
+
import L from "./decorators.mjs";
|
|
13
|
+
const k = /* @__PURE__ */ new Set();
|
|
14
14
|
function N() {
|
|
15
|
-
const [e, t] = h(!1), o =
|
|
15
|
+
const [e, t] = h(!1), o = v((r) => {
|
|
16
16
|
t(r);
|
|
17
|
-
for (const i of
|
|
17
|
+
for (const i of k)
|
|
18
18
|
i(r);
|
|
19
19
|
}, []);
|
|
20
20
|
return y(() => {
|
|
21
21
|
const r = (i) => {
|
|
22
22
|
t(i);
|
|
23
23
|
};
|
|
24
|
-
return
|
|
25
|
-
|
|
24
|
+
return k.add(r), () => {
|
|
25
|
+
k.delete(r);
|
|
26
26
|
};
|
|
27
|
-
}, []),
|
|
27
|
+
}, []), f(() => ({
|
|
28
28
|
isKeyboardNavigating: e,
|
|
29
29
|
setIsKeyboardNavigating: o
|
|
30
30
|
}), [e, o]);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function R({
|
|
33
33
|
label: e,
|
|
34
34
|
iconLeft: t,
|
|
35
35
|
iconRight: o,
|
|
36
36
|
href: r,
|
|
37
37
|
shouldCloseOnClick: i = !0,
|
|
38
|
-
decorators:
|
|
39
|
-
submenu:
|
|
40
|
-
className:
|
|
41
|
-
onClick:
|
|
42
|
-
...
|
|
38
|
+
decorators: x = [],
|
|
39
|
+
submenu: m,
|
|
40
|
+
className: a,
|
|
41
|
+
onClick: s,
|
|
42
|
+
...u
|
|
43
43
|
}) {
|
|
44
44
|
const {
|
|
45
|
-
isFocused:
|
|
46
|
-
close:
|
|
45
|
+
isFocused: c,
|
|
46
|
+
close: d
|
|
47
47
|
} = w(), {
|
|
48
|
-
isKeyboardNavigating:
|
|
49
|
-
} = N(),
|
|
50
|
-
|
|
51
|
-
}, [
|
|
48
|
+
isKeyboardNavigating: p
|
|
49
|
+
} = N(), l = v((P) => {
|
|
50
|
+
c && (s == null || s(P), m ? m.show() : i && (d == null || d()));
|
|
51
|
+
}, [c, s, i, d, m]), j = f(() => /* @__PURE__ */ n.jsxs(F, { as: r ? "a" : "button", ...u, type: r ? void 0 : "button", role: "menuitem", href: r, className: b(E, "kakadu-components-3114599304", p ? "kakadu-components-4096376656" : "kakadu-components-2554182777", a), onClick: l, children: [
|
|
52
52
|
/* @__PURE__ */ n.jsxs(I, { className: "kakadu-components-1109353535", children: [
|
|
53
|
-
t ? /* @__PURE__ */ n.jsx(
|
|
53
|
+
t ? /* @__PURE__ */ n.jsx(g, { width: 12, height: 12, type: t }) : null,
|
|
54
54
|
/* @__PURE__ */ n.jsx("span", { className: "kakadu-components-913703148", children: e }),
|
|
55
|
-
o ? /* @__PURE__ */ n.jsx(
|
|
55
|
+
o ? /* @__PURE__ */ n.jsx(g, { width: 12, height: 12, type: o }) : null
|
|
56
56
|
] }),
|
|
57
|
-
|
|
57
|
+
p ? null : /* @__PURE__ */ n.jsxs(n.Fragment, { children: [
|
|
58
58
|
/* @__PURE__ */ n.jsx(A, { size: 150, className: D }),
|
|
59
59
|
/* @__PURE__ */ n.jsx(H, { size: 100 })
|
|
60
60
|
] })
|
|
61
|
-
] }), [
|
|
62
|
-
return /* @__PURE__ */ n.jsx(
|
|
61
|
+
] }), [p, u, r, a, l, t, e, o]);
|
|
62
|
+
return /* @__PURE__ */ n.jsx(L, { decorators: x, children: m ? /* @__PURE__ */ n.jsx(T, { menu: m.popoverMenu, className: "kakadu-components-1861176543", children: j }) : j });
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function B(e) {
|
|
65
65
|
if ("type" in e) {
|
|
66
66
|
if (e.type === "separator")
|
|
67
67
|
return /* @__PURE__ */ n.jsx(z, {});
|
|
68
68
|
if (e.type === "group")
|
|
69
69
|
return /* @__PURE__ */ n.jsx(I, { className: "kakadu-components-1499037363", children: e.label });
|
|
70
70
|
}
|
|
71
|
-
return /* @__PURE__ */ n.jsx(
|
|
71
|
+
return /* @__PURE__ */ n.jsx(R, { ...e });
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function C({
|
|
74
74
|
items: e
|
|
75
75
|
}) {
|
|
76
76
|
const {
|
|
77
77
|
isFocused: t
|
|
78
|
-
} = w(), [o, r] = h(
|
|
79
|
-
setIsKeyboardNavigating:
|
|
80
|
-
} = N(),
|
|
81
|
-
a &&
|
|
82
|
-
}, []),
|
|
83
|
-
t && (a.currentTarget.focus(),
|
|
84
|
-
}, [t, c]), x = l((a) => {
|
|
85
|
-
if (t) {
|
|
86
|
-
const s = a.target;
|
|
87
|
-
r(i.indexOf(s));
|
|
88
|
-
}
|
|
78
|
+
} = w(), [o, r] = h([]), {
|
|
79
|
+
setIsKeyboardNavigating: i
|
|
80
|
+
} = N(), x = v((a) => {
|
|
81
|
+
a && r((s) => [...s, a]);
|
|
82
|
+
}, []), m = v((a) => {
|
|
83
|
+
t && (a.currentTarget.focus(), i(!1));
|
|
89
84
|
}, [t, i]);
|
|
90
85
|
return y(() => {
|
|
91
86
|
if (!t)
|
|
92
87
|
return;
|
|
93
88
|
const a = (s) => {
|
|
94
|
-
const u =
|
|
89
|
+
const u = o.length;
|
|
95
90
|
if (u === 0)
|
|
96
91
|
return;
|
|
97
|
-
let
|
|
92
|
+
let c;
|
|
93
|
+
const d = document.activeElement, p = d ? o.indexOf(d) : 0;
|
|
98
94
|
switch (s.key) {
|
|
99
95
|
case "ArrowDown": {
|
|
100
|
-
|
|
96
|
+
c = (p + 1) % u;
|
|
101
97
|
break;
|
|
102
98
|
}
|
|
103
99
|
case "ArrowUp": {
|
|
104
|
-
|
|
100
|
+
c = (p - 1 + u) % u;
|
|
105
101
|
break;
|
|
106
102
|
}
|
|
107
103
|
case "Home": {
|
|
108
|
-
|
|
104
|
+
c = 0;
|
|
109
105
|
break;
|
|
110
106
|
}
|
|
111
107
|
case "End": {
|
|
112
|
-
|
|
108
|
+
c = u - 1;
|
|
113
109
|
break;
|
|
114
110
|
}
|
|
115
111
|
}
|
|
116
|
-
if (
|
|
112
|
+
if (c !== void 0) {
|
|
117
113
|
s.preventDefault(), s.stopPropagation();
|
|
118
|
-
const
|
|
119
|
-
|
|
114
|
+
const l = o[c];
|
|
115
|
+
l && (l.focus(), i(!0));
|
|
120
116
|
}
|
|
121
117
|
};
|
|
122
118
|
return window.addEventListener("keydown", a, {
|
|
@@ -126,13 +122,12 @@ function B({
|
|
|
126
122
|
capture: !0
|
|
127
123
|
});
|
|
128
124
|
};
|
|
129
|
-
}, [t,
|
|
130
|
-
|
|
125
|
+
}, [t, o, i]), /* @__PURE__ */ n.jsx(n.Fragment, { children: e.map((a, s) => /* @__PURE__ */ n.jsx(
|
|
126
|
+
B,
|
|
131
127
|
{
|
|
132
128
|
...a,
|
|
133
|
-
reference:
|
|
134
|
-
|
|
135
|
-
onMouseEnter: d
|
|
129
|
+
reference: x,
|
|
130
|
+
onMouseEnter: m
|
|
136
131
|
},
|
|
137
132
|
s
|
|
138
133
|
)) });
|
|
@@ -141,16 +136,16 @@ function G({
|
|
|
141
136
|
items: e,
|
|
142
137
|
...t
|
|
143
138
|
}) {
|
|
144
|
-
return /* @__PURE__ */ n.jsx(
|
|
139
|
+
return /* @__PURE__ */ n.jsx(M, { ...t, as: "nav", role: "menu", innerClassName: "kakadu-components-3600436535", children: /* @__PURE__ */ n.jsx(C, { items: e }) });
|
|
145
140
|
}
|
|
146
141
|
function ee(e) {
|
|
147
|
-
const t =
|
|
142
|
+
const t = f(() => ({
|
|
148
143
|
items: e
|
|
149
144
|
}), [e]), {
|
|
150
145
|
show: o,
|
|
151
146
|
popover: r
|
|
152
|
-
} =
|
|
153
|
-
return
|
|
147
|
+
} = K(G, t);
|
|
148
|
+
return f(() => ({
|
|
154
149
|
show: o,
|
|
155
150
|
popoverMenu: r
|
|
156
151
|
}), [o, r]);
|