@kakadu/components 2.4.3 → 3.1.0
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/decorators.d.ts +8 -0
- package/build/components/decorators.js +1 -0
- package/build/components/decorators.mjs +13 -0
- package/build/components/modal.d.ts +1 -3
- package/build/components/modal.js +1 -1
- package/build/components/modal.mjs +65 -70
- package/build/components/popover-menu.d.ts +20 -5
- package/build/components/popover-menu.js +1 -1
- package/build/components/popover-menu.mjs +128 -54
- package/build/components/popover.d.ts +1 -0
- package/build/components/popover.js +1 -1
- package/build/components/popover.mjs +79 -70
- package/build/components.css +1 -1
- package/build/hooks/use-fetch.d.ts +6 -1
- package/build/hooks/use-fetch.js +1 -1
- package/build/hooks/use-fetch.mjs +89 -71
- package/build/index.d.ts +2 -0
- package/build/index.js +1 -1
- package/build/index.mjs +202 -199
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ComponentType, type ReactNode } from 'react';
|
|
2
|
+
export type DecoratorType = ComponentType<{
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
}>;
|
|
5
|
+
export default function Decorators({ decorators, children, }: {
|
|
6
|
+
readonly decorators: DecoratorType[];
|
|
7
|
+
readonly children: ReactNode;
|
|
8
|
+
}): ReactNode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../jsx-runtime-BB_1_6y_.js");function n({decorators:e,children:t}){return e.length===0?t:e.reduceRight((u,r)=>i.jsxRuntimeExports.jsx(r,{children:u}),t)}exports.default=n;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ComponentType, type ReactNode } from 'react';
|
|
2
|
+
import { type DecoratorType } from './decorators';
|
|
2
3
|
type InitialFocusElement = HTMLElement | null;
|
|
3
4
|
type ModalProviderProperties<Data = any> = {
|
|
4
5
|
isVisible: boolean;
|
|
@@ -6,9 +7,6 @@ type ModalProviderProperties<Data = any> = {
|
|
|
6
7
|
close?: (data?: Data) => void;
|
|
7
8
|
};
|
|
8
9
|
export declare function useModalContext<Data = any>(): ModalProviderProperties<Data>;
|
|
9
|
-
export type DecoratorType = ComponentType<{
|
|
10
|
-
children: ReactNode;
|
|
11
|
-
}>;
|
|
12
10
|
export type ModalProperties<Data = any> = {
|
|
13
11
|
readonly root?: HTMLElement | ShadowRoot;
|
|
14
12
|
readonly outerDecorators?: DecoratorType[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),E=require("@kuma-ui/core"),P=require("react-dom"),$=require("../focus-trap-react-CcpTuiJi.js"),B=require("../icons/icon.js"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),E=require("@kuma-ui/core"),P=require("react-dom"),$=require("../focus-trap-react-CcpTuiJi.js"),B=require("../icons/icon.js"),A=require("./text-button.js"),I=require("./decorators.js"),y=e.createContext({isVisible:!1}),{Provider:D}=y;function N(){return e.useContext(y)}function z(){const{close:o}=N(),u=e.useCallback(()=>{o==null||o()},[o]);return s.jsxRuntimeExports.jsxs(s.jsxRuntimeExports.Fragment,{children:[s.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2543813221"}),s.jsxRuntimeExports.jsx("div",{className:"kakadu-components-840864829",children:s.jsxRuntimeExports.jsx(A.default,{iconLeft:B.IconType.times,label:"Close",className:"kakadu-components-3855719072",onClick:u})})]})}function G({root:o,outerDecorators:u=[],innerDecorators:a=[],label:k,maxWidth:r,className:i,isVisible:n,isFullWidth:x=!1,shouldCloseOnOutsideClick:f=!0,shouldCloseOnEscapePress:l=!0,showCloseButton:d=!0,onClose:c,children:g}){const v=e.useRef(null),M=e.useRef(null),[h,L]=e.useState(!1),[m,p]=e.useState(!1),b=e.useCallback(t=>{v.current=t,p(!1)},[]),R=e.useRef(null),w=e.useCallback(t=>{t&&(R.current=t)},[]),[T,q]=e.useState(n??!1),S=e.useMemo(()=>({isVisible:T,setInitialFocus:w,close:b}),[T,w,b]);e.useEffect(()=>{n&&(L(!0),q(!0))},[n]),e.useEffect(()=>{if(n){const t=setTimeout(()=>{p(!0)},100);return()=>{clearTimeout(t)}}p(!1)},[n]),e.useEffect(()=>{if(h&&!m){const t=setTimeout(()=>{c==null||c(v.current??void 0),q(!1)},370);return()=>{clearTimeout(t)}}},[h,m,c]),e.useEffect(()=>{const t=M.current;if(n&&f&&t){const j=_=>{t===_.target&&p(!1)};return t.addEventListener("click",j),()=>{t.removeEventListener("click",j)}}},[n,f]),e.useEffect(()=>{if(!n||!l)return;const t=j=>{j.key==="Escape"&&p(!1)};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[n,l]);const F=e.useMemo(()=>({initialFocus:()=>R.current??void 0,onActivate:()=>{var t;return(t=R.current)==null?void 0:t.focus()}}),[]),C=s.jsxRuntimeExports.jsx(I.default,{decorators:u,children:s.jsxRuntimeExports.jsx("div",{"aria-hidden":!m,style:{"--max-width":r?`${r}px`:void 0},className:E.cx("kakadu-components-4119461136",m&&"kakadu-components-2522346797",i),children:s.jsxRuntimeExports.jsx(I.default,{decorators:a,children:s.jsxRuntimeExports.jsx($.focusTrapReactExports.FocusTrap,{active:m,focusTrapOptions:F,children:s.jsxRuntimeExports.jsx("div",{ref:M,className:"kakadu-components-4011815997",children:s.jsxRuntimeExports.jsx("div",{role:"dialog","aria-modal":"true","aria-label":k??"Modal",className:E.cx("kakadu-components-3324483532",x&&"kakadu-components-3799971070",m&&"kakadu-components-968755580"),children:s.jsxRuntimeExports.jsxs(D,{value:S,children:[d?s.jsxRuntimeExports.jsx(z,{}):null,s.jsxRuntimeExports.jsx("div",{className:E.cx("kakadu-components-633990035",x&&"kakadu-components-171969824"),children:g})]})})})})})})});return o?P.createPortal(C,o):C}function H(o,u){const[a,k]=e.useState(!1),r=e.useRef(void 0),i=e.useRef(null),n=e.useCallback(async l=>(k(!0),i.current=l??document.activeElement,new Promise(d=>{r.current=d})),[]),x=e.useCallback(l=>{var d;if(k(!1),(d=r.current)==null||d.call(r,l),r.current=void 0,i.current){const c=i.current;c.isConnected&&c.focus(),i.current=null}},[]),f=e.useMemo(()=>s.jsxRuntimeExports.jsx(o,{...u,isVisible:a,onClose:x}),[o,u,a,x]);return e.useMemo(()=>({isVisible:a,show:n,modal:f}),[a,n,f])}exports.default=G;exports.useModal=H;exports.useModalContext=N;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { j as t } from "../jsx-runtime-B4hRZ52C.mjs";
|
|
2
|
-
import { createContext as q, useRef as
|
|
2
|
+
import { createContext as q, useRef as p, useState as w, useCallback as v, useMemo as T, useEffect as x, useContext as z } from "react";
|
|
3
3
|
import { cx as I } from "@kuma-ui/core";
|
|
4
4
|
import { createPortal as G } from "react-dom";
|
|
5
5
|
import { f as H } from "../focus-trap-react-DYXrtbDH.mjs";
|
|
6
6
|
import { IconType as J } from "../icons/icon.mjs";
|
|
7
7
|
import K from "./text-button.mjs";
|
|
8
|
+
import C from "./decorators.mjs";
|
|
8
9
|
const B = q({
|
|
9
10
|
isVisible: !1
|
|
10
11
|
}), {
|
|
@@ -15,118 +16,112 @@ function U() {
|
|
|
15
16
|
}
|
|
16
17
|
function V() {
|
|
17
18
|
const {
|
|
18
|
-
close:
|
|
19
|
-
} = U(),
|
|
20
|
-
|
|
21
|
-
}, [
|
|
19
|
+
close: o
|
|
20
|
+
} = U(), a = v(() => {
|
|
21
|
+
o == null || o();
|
|
22
|
+
}, [o]);
|
|
22
23
|
return /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
|
|
23
24
|
/* @__PURE__ */ t.jsx("div", { className: "kakadu-components-2543813221" }),
|
|
24
|
-
/* @__PURE__ */ t.jsx("div", { className: "kakadu-components-840864829", children: /* @__PURE__ */ t.jsx(K, { iconLeft: J.times, label: "Close", className: "kakadu-components-3855719072", onClick:
|
|
25
|
+
/* @__PURE__ */ t.jsx("div", { className: "kakadu-components-840864829", children: /* @__PURE__ */ t.jsx(K, { iconLeft: J.times, label: "Close", className: "kakadu-components-3855719072", onClick: a }) })
|
|
25
26
|
] });
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function te({
|
|
34
|
-
root: n,
|
|
35
|
-
outerDecorators: o = [],
|
|
36
|
-
innerDecorators: r = [],
|
|
37
|
-
label: u,
|
|
38
|
-
maxWidth: c,
|
|
28
|
+
function ne({
|
|
29
|
+
root: o,
|
|
30
|
+
outerDecorators: a = [],
|
|
31
|
+
innerDecorators: c = [],
|
|
32
|
+
label: j,
|
|
33
|
+
maxWidth: s,
|
|
39
34
|
className: i,
|
|
40
|
-
isVisible:
|
|
41
|
-
isFullWidth:
|
|
42
|
-
shouldCloseOnOutsideClick:
|
|
43
|
-
shouldCloseOnEscapePress:
|
|
44
|
-
showCloseButton:
|
|
45
|
-
onClose:
|
|
35
|
+
isVisible: n,
|
|
36
|
+
isFullWidth: m = !1,
|
|
37
|
+
shouldCloseOnOutsideClick: f = !0,
|
|
38
|
+
shouldCloseOnEscapePress: u = !0,
|
|
39
|
+
showCloseButton: l = !0,
|
|
40
|
+
onClose: r,
|
|
46
41
|
children: P
|
|
47
42
|
}) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
}, []), E =
|
|
43
|
+
const N = p(null), R = p(null), [y, A] = w(!1), [d, k] = w(!1), L = v((e) => {
|
|
44
|
+
N.current = e, k(!1);
|
|
45
|
+
}, []), E = p(null), M = v((e) => {
|
|
51
46
|
e && (E.current = e);
|
|
52
|
-
}, []), [
|
|
53
|
-
isVisible:
|
|
54
|
-
setInitialFocus:
|
|
55
|
-
close:
|
|
56
|
-
}), [M, L
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}, [
|
|
60
|
-
if (
|
|
47
|
+
}, []), [F, b] = w(n ?? !1), D = T(() => ({
|
|
48
|
+
isVisible: F,
|
|
49
|
+
setInitialFocus: M,
|
|
50
|
+
close: L
|
|
51
|
+
}), [F, M, L]);
|
|
52
|
+
x(() => {
|
|
53
|
+
n && (A(!0), b(!0));
|
|
54
|
+
}, [n]), x(() => {
|
|
55
|
+
if (n) {
|
|
61
56
|
const e = setTimeout(() => {
|
|
62
|
-
|
|
57
|
+
k(!0);
|
|
63
58
|
}, 100);
|
|
64
59
|
return () => {
|
|
65
60
|
clearTimeout(e);
|
|
66
61
|
};
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
}, [
|
|
70
|
-
if (
|
|
63
|
+
k(!1);
|
|
64
|
+
}, [n]), x(() => {
|
|
65
|
+
if (y && !d) {
|
|
71
66
|
const e = setTimeout(() => {
|
|
72
|
-
|
|
67
|
+
r == null || r(N.current ?? void 0), b(!1);
|
|
73
68
|
}, 370);
|
|
74
69
|
return () => {
|
|
75
70
|
clearTimeout(e);
|
|
76
71
|
};
|
|
77
72
|
}
|
|
78
|
-
}, [
|
|
79
|
-
const e =
|
|
80
|
-
if (
|
|
73
|
+
}, [y, d, r]), x(() => {
|
|
74
|
+
const e = R.current;
|
|
75
|
+
if (n && f && e) {
|
|
81
76
|
const h = ($) => {
|
|
82
|
-
e === $.target &&
|
|
77
|
+
e === $.target && k(!1);
|
|
83
78
|
};
|
|
84
79
|
return e.addEventListener("click", h), () => {
|
|
85
80
|
e.removeEventListener("click", h);
|
|
86
81
|
};
|
|
87
82
|
}
|
|
88
|
-
}, [
|
|
89
|
-
if (!
|
|
83
|
+
}, [n, f]), x(() => {
|
|
84
|
+
if (!n || !u)
|
|
90
85
|
return;
|
|
91
86
|
const e = (h) => {
|
|
92
|
-
h.key === "Escape" &&
|
|
87
|
+
h.key === "Escape" && k(!1);
|
|
93
88
|
};
|
|
94
89
|
return window.addEventListener("keydown", e), () => {
|
|
95
90
|
window.removeEventListener("keydown", e);
|
|
96
91
|
};
|
|
97
|
-
}, [
|
|
92
|
+
}, [n, u]);
|
|
98
93
|
const S = T(() => ({
|
|
99
94
|
initialFocus: () => E.current ?? void 0,
|
|
100
95
|
onActivate: () => {
|
|
101
96
|
var e;
|
|
102
97
|
return (e = E.current) == null ? void 0 : e.focus();
|
|
103
98
|
}
|
|
104
|
-
}), []),
|
|
105
|
-
"--max-width":
|
|
106
|
-
}, className: I("kakadu-components-4119461136",
|
|
107
|
-
|
|
108
|
-
/* @__PURE__ */ t.jsx("div", { className: I("kakadu-components-633990035",
|
|
99
|
+
}), []), g = /* @__PURE__ */ t.jsx(C, { decorators: a, children: /* @__PURE__ */ t.jsx("div", { "aria-hidden": !d, style: {
|
|
100
|
+
"--max-width": s ? `${s}px` : void 0
|
|
101
|
+
}, className: I("kakadu-components-4119461136", d && "kakadu-components-2522346797", i), children: /* @__PURE__ */ t.jsx(C, { decorators: c, children: /* @__PURE__ */ t.jsx(H.FocusTrap, { active: d, focusTrapOptions: S, children: /* @__PURE__ */ t.jsx("div", { ref: R, className: "kakadu-components-4011815997", children: /* @__PURE__ */ t.jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": j ?? "Modal", className: I("kakadu-components-3324483532", m && "kakadu-components-3799971070", d && "kakadu-components-968755580"), children: /* @__PURE__ */ t.jsxs(Q, { value: D, children: [
|
|
102
|
+
l ? /* @__PURE__ */ t.jsx(V, {}) : null,
|
|
103
|
+
/* @__PURE__ */ t.jsx("div", { className: I("kakadu-components-633990035", m && "kakadu-components-171969824"), children: P })
|
|
109
104
|
] }) }) }) }) }) }) });
|
|
110
|
-
return
|
|
105
|
+
return o ? G(g, o) : g;
|
|
111
106
|
}
|
|
112
|
-
function
|
|
113
|
-
const [
|
|
114
|
-
|
|
115
|
-
})), []),
|
|
116
|
-
var
|
|
117
|
-
if (
|
|
118
|
-
const
|
|
119
|
-
|
|
107
|
+
function oe(o, a) {
|
|
108
|
+
const [c, j] = w(!1), s = p(void 0), i = p(null), n = v(async (u) => (j(!0), i.current = u ?? document.activeElement, new Promise((l) => {
|
|
109
|
+
s.current = l;
|
|
110
|
+
})), []), m = v((u) => {
|
|
111
|
+
var l;
|
|
112
|
+
if (j(!1), (l = s.current) == null || l.call(s, u), s.current = void 0, i.current) {
|
|
113
|
+
const r = i.current;
|
|
114
|
+
r.isConnected && r.focus(), i.current = null;
|
|
120
115
|
}
|
|
121
|
-
}, []),
|
|
116
|
+
}, []), f = T(() => /* @__PURE__ */ t.jsx(o, { ...a, isVisible: c, onClose: m }), [o, a, c, m]);
|
|
122
117
|
return T(() => ({
|
|
123
|
-
isVisible:
|
|
124
|
-
show:
|
|
125
|
-
modal:
|
|
126
|
-
}), [
|
|
118
|
+
isVisible: c,
|
|
119
|
+
show: n,
|
|
120
|
+
modal: f
|
|
121
|
+
}), [c, n, f]);
|
|
127
122
|
}
|
|
128
123
|
export {
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
ne as default,
|
|
125
|
+
oe as useModal,
|
|
131
126
|
U as useModalContext
|
|
132
127
|
};
|
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
import { type MouseEvent, type ReactNode } from 'react';
|
|
1
|
+
import { type FocusEvent, type MouseEvent, type ReactNode, type Ref } from 'react';
|
|
2
2
|
import { type IconType } from '../icons/icon';
|
|
3
|
+
import { type DecoratorType } from './decorators';
|
|
4
|
+
type PopoverMenuItemElementType = HTMLButtonElement | HTMLAnchorElement;
|
|
3
5
|
export type PopoverMenuItemProperties = {
|
|
6
|
+
type: 'separator';
|
|
7
|
+
} | {
|
|
8
|
+
type: 'group';
|
|
4
9
|
readonly label: ReactNode;
|
|
10
|
+
} | {
|
|
11
|
+
readonly reference?: Ref<PopoverMenuItemElementType>;
|
|
12
|
+
readonly label: ReactNode;
|
|
13
|
+
readonly href?: string;
|
|
5
14
|
readonly iconLeft?: IconType;
|
|
6
15
|
readonly iconRight?: IconType;
|
|
7
|
-
readonly
|
|
16
|
+
readonly submenu?: ReturnType<typeof usePopoverMenu>;
|
|
8
17
|
readonly shouldCloseOnClick?: boolean;
|
|
9
|
-
readonly
|
|
18
|
+
readonly decorators?: DecoratorType[];
|
|
19
|
+
readonly className?: string;
|
|
20
|
+
readonly onClick?: (event: MouseEvent<PopoverMenuItemElementType>) => void;
|
|
21
|
+
readonly onFocus?: (event: FocusEvent<PopoverMenuItemElementType>) => void;
|
|
22
|
+
readonly onMouseEnter?: (event: MouseEvent<PopoverMenuItemElementType>) => void;
|
|
10
23
|
};
|
|
11
24
|
export declare function usePopoverMenu(items: PopoverMenuItemProperties[]): {
|
|
12
25
|
show: (reference?: HTMLElement) => Promise<void | undefined>;
|
|
@@ -14,6 +27,8 @@ export declare function usePopoverMenu(items: PopoverMenuItemProperties[]): {
|
|
|
14
27
|
};
|
|
15
28
|
export type PopoverMenuProperties = {
|
|
16
29
|
readonly menu: ReactNode;
|
|
17
|
-
readonly
|
|
30
|
+
readonly className?: string;
|
|
31
|
+
readonly children?: ReactNode;
|
|
18
32
|
};
|
|
19
|
-
export default function PopoverMenu({ menu, children }: PopoverMenuProperties): import("react/jsx-runtime").JSX.Element;
|
|
33
|
+
export default function PopoverMenu({ menu, className, children, }: PopoverMenuProperties): import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../jsx-runtime-BB_1_6y_.js"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../jsx-runtime-BB_1_6y_.js"),w=require("@kuma-ui/core"),a=require("react"),M=require("../theme.js"),v=require("../icons/icon.js"),d=require("./popover.js"),q=require("./atom.js"),k=require("./text.js"),E=require("./hover-gradient.js"),y=require("./click-ripples.js"),P=require("./separator.js"),_=require("./decorators.js");function b({label:t,iconLeft:n,iconRight:r,href:c,shouldCloseOnClick:x=!0,decorators:f=[],submenu:p,className:j,onClick:l,...s}){const{isFocused:o,close:u}=d.usePopoverContext(),i=a.useCallback(R=>{o&&(l==null||l(R),p?p.show():x&&(u==null||u()))},[o,l,x,u,p]),m=a.useMemo(()=>e.jsxRuntimeExports.jsxs(q.default,{as:c?"a":"button",...s,type:c?void 0:"button",role:"menuitem",href:c,className:w.cx(M.buttonResetStyles,"kakadu-components-2758794973",j),onClick:i,children:[e.jsxRuntimeExports.jsxs(k.Span,{className:"kakadu-components-1109353535",children:[n?e.jsxRuntimeExports.jsx(v.default,{width:12,height:12,type:n}):null,e.jsxRuntimeExports.jsx("span",{className:"kakadu-components-913703148",children:t}),r?e.jsxRuntimeExports.jsx(v.default,{width:12,height:12,type:r}):null]}),e.jsxRuntimeExports.jsx(E.default,{size:150,className:E.normalBlendStyles}),e.jsxRuntimeExports.jsx(y.default,{size:100})]}),[s,c,j,i,n,t,r,o]);return e.jsxRuntimeExports.jsx(_.default,{decorators:f,children:p?e.jsxRuntimeExports.jsx(h,{menu:p.popoverMenu,className:"kakadu-components-1861176543",children:m}):m})}function g(t){if("type"in t){if(t.type==="separator")return e.jsxRuntimeExports.jsx(P.default,{});if(t.type==="group")return e.jsxRuntimeExports.jsx(k.Span,{className:"kakadu-components-1499037363",children:t.label})}return e.jsxRuntimeExports.jsx(b,{...t})}function I({items:t}){const{isFocused:n}=d.usePopoverContext(),[r,c]=a.useState(0),[x,f]=a.useState([]),p=a.useCallback(s=>{s&&f(o=>[...o,s])},[]),j=a.useCallback(s=>{n&&s.currentTarget.focus()},[n]),l=a.useCallback(s=>{if(n){const o=s.target;c(x.indexOf(o))}},[n,x]);return a.useEffect(()=>{if(!n)return;const s=o=>{const u=x.length;if(u===0)return;let i;switch(o.key){case"ArrowDown":{i=(r+1)%u;break}case"ArrowUp":{i=(r-1+u)%u;break}case"Home":{i=0;break}case"End":{i=u-1;break}}if(i!==void 0){o.preventDefault(),o.stopPropagation();const m=x[i];m&&m.focus()}};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[n,x,r]),e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:t.map((s,o)=>e.jsxRuntimeExports.jsx(g,{...s,reference:p,onFocus:l,onMouseEnter:j},o))})}function S({items:t,...n}){return e.jsxRuntimeExports.jsx(d.default,{...n,as:"nav",role:"menu",innerClassName:"kakadu-components-3600436535",children:e.jsxRuntimeExports.jsx(I,{items:t})})}function N(t){const n=a.useMemo(()=>({items:t}),[t]),{show:r,popover:c}=d.usePopover(S,n);return a.useMemo(()=>({show:r,popoverMenu:c}),[r,c])}function h({menu:t,className:n,children:r}){return e.jsxRuntimeExports.jsxs(d.PopoverContainer,{className:n,children:[r,t]})}exports.default=h;exports.usePopoverMenu=N;
|
|
@@ -1,68 +1,142 @@
|
|
|
1
1
|
import { j as e } from "../jsx-runtime-B4hRZ52C.mjs";
|
|
2
|
-
import { cx as
|
|
3
|
-
import { useMemo as
|
|
4
|
-
import { buttonResetStyles as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { Span as
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
import { cx as P } from "@kuma-ui/core";
|
|
3
|
+
import { useMemo as v, useState as j, useCallback as f, useEffect as M } from "react";
|
|
4
|
+
import { buttonResetStyles as I } from "../theme.mjs";
|
|
5
|
+
import h from "../icons/icon.mjs";
|
|
6
|
+
import E, { PopoverContainer as g, usePopover as N, usePopoverContext as k } from "./popover.mjs";
|
|
7
|
+
import F from "./atom.mjs";
|
|
8
|
+
import { Span as w } from "./text.mjs";
|
|
9
|
+
import S, { normalBlendStyles as b } from "./hover-gradient.mjs";
|
|
10
|
+
import A from "./click-ripples.mjs";
|
|
11
|
+
import D from "./separator.mjs";
|
|
12
|
+
import H from "./decorators.mjs";
|
|
13
|
+
function z({
|
|
14
|
+
label: n,
|
|
15
|
+
iconLeft: o,
|
|
16
|
+
iconRight: s,
|
|
17
|
+
href: c,
|
|
18
|
+
shouldCloseOnClick: i = !0,
|
|
19
|
+
decorators: x = [],
|
|
20
|
+
submenu: m,
|
|
21
|
+
className: l,
|
|
22
|
+
onClick: p,
|
|
23
|
+
...t
|
|
19
24
|
}) {
|
|
20
25
|
const {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/* @__PURE__ */ e.jsxs(
|
|
27
|
-
|
|
28
|
-
/* @__PURE__ */ e.jsx("span", { className: "kakadu-components-
|
|
29
|
-
|
|
26
|
+
isFocused: r,
|
|
27
|
+
close: a
|
|
28
|
+
} = k(), u = f((y) => {
|
|
29
|
+
r && (p == null || p(y), m ? m.show() : i && (a == null || a()));
|
|
30
|
+
}, [r, p, i, a, m]), d = v(() => /* @__PURE__ */ e.jsxs(F, { as: c ? "a" : "button", ...t, type: c ? void 0 : "button", role: "menuitem", href: c, className: P(I, "kakadu-components-2758794973", l), onClick: u, children: [
|
|
31
|
+
/* @__PURE__ */ e.jsxs(w, { className: "kakadu-components-1109353535", children: [
|
|
32
|
+
o ? /* @__PURE__ */ e.jsx(h, { width: 12, height: 12, type: o }) : null,
|
|
33
|
+
/* @__PURE__ */ e.jsx("span", { className: "kakadu-components-913703148", children: n }),
|
|
34
|
+
s ? /* @__PURE__ */ e.jsx(h, { width: 12, height: 12, type: s }) : null
|
|
30
35
|
] }),
|
|
31
|
-
/* @__PURE__ */ e.jsx(
|
|
32
|
-
/* @__PURE__ */ e.jsx(
|
|
33
|
-
] });
|
|
36
|
+
/* @__PURE__ */ e.jsx(S, { size: 150, className: b }),
|
|
37
|
+
/* @__PURE__ */ e.jsx(A, { size: 100 })
|
|
38
|
+
] }), [t, c, l, u, o, n, s, r]);
|
|
39
|
+
return /* @__PURE__ */ e.jsx(H, { decorators: x, children: m ? /* @__PURE__ */ e.jsx(B, { menu: m.popoverMenu, className: "kakadu-components-1861176543", children: d }) : d });
|
|
40
|
+
}
|
|
41
|
+
function C(n) {
|
|
42
|
+
if ("type" in n) {
|
|
43
|
+
if (n.type === "separator")
|
|
44
|
+
return /* @__PURE__ */ e.jsx(D, {});
|
|
45
|
+
if (n.type === "group")
|
|
46
|
+
return /* @__PURE__ */ e.jsx(w, { className: "kakadu-components-1499037363", children: n.label });
|
|
47
|
+
}
|
|
48
|
+
return /* @__PURE__ */ e.jsx(z, { ...n });
|
|
34
49
|
}
|
|
35
|
-
function
|
|
36
|
-
items:
|
|
37
|
-
...r
|
|
50
|
+
function L({
|
|
51
|
+
items: n
|
|
38
52
|
}) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
const {
|
|
54
|
+
isFocused: o
|
|
55
|
+
} = k(), [s, c] = j(0), [i, x] = j([]), m = f((t) => {
|
|
56
|
+
t && x((r) => [...r, t]);
|
|
57
|
+
}, []), l = f((t) => {
|
|
58
|
+
o && t.currentTarget.focus();
|
|
59
|
+
}, [o]), p = f((t) => {
|
|
60
|
+
if (o) {
|
|
61
|
+
const r = t.target;
|
|
62
|
+
c(i.indexOf(r));
|
|
63
|
+
}
|
|
64
|
+
}, [o, i]);
|
|
65
|
+
return M(() => {
|
|
66
|
+
if (!o)
|
|
67
|
+
return;
|
|
68
|
+
const t = (r) => {
|
|
69
|
+
const a = i.length;
|
|
70
|
+
if (a === 0)
|
|
71
|
+
return;
|
|
72
|
+
let u;
|
|
73
|
+
switch (r.key) {
|
|
74
|
+
case "ArrowDown": {
|
|
75
|
+
u = (s + 1) % a;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case "ArrowUp": {
|
|
79
|
+
u = (s - 1 + a) % a;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case "Home": {
|
|
83
|
+
u = 0;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case "End": {
|
|
87
|
+
u = a - 1;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (u !== void 0) {
|
|
92
|
+
r.preventDefault(), r.stopPropagation();
|
|
93
|
+
const d = i[u];
|
|
94
|
+
d && d.focus();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return window.addEventListener("keydown", t), () => {
|
|
98
|
+
window.removeEventListener("keydown", t);
|
|
99
|
+
};
|
|
100
|
+
}, [o, i, s]), /* @__PURE__ */ e.jsx(e.Fragment, { children: n.map((t, r) => /* @__PURE__ */ e.jsx(
|
|
101
|
+
C,
|
|
102
|
+
{
|
|
103
|
+
...t,
|
|
104
|
+
reference: m,
|
|
105
|
+
onFocus: p,
|
|
106
|
+
onMouseEnter: l
|
|
107
|
+
},
|
|
108
|
+
r
|
|
42
109
|
)) });
|
|
43
110
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
111
|
+
function R({
|
|
112
|
+
items: n,
|
|
113
|
+
...o
|
|
114
|
+
}) {
|
|
115
|
+
return /* @__PURE__ */ e.jsx(E, { ...o, as: "nav", role: "menu", innerClassName: "kakadu-components-3600436535", children: /* @__PURE__ */ e.jsx(L, { items: n }) });
|
|
116
|
+
}
|
|
117
|
+
function Z(n) {
|
|
118
|
+
const o = v(() => ({
|
|
119
|
+
items: n
|
|
120
|
+
}), [n]), {
|
|
121
|
+
show: s,
|
|
122
|
+
popover: c
|
|
123
|
+
} = N(R, o);
|
|
124
|
+
return v(() => ({
|
|
125
|
+
show: s,
|
|
126
|
+
popoverMenu: c
|
|
127
|
+
}), [s, c]);
|
|
55
128
|
}
|
|
56
|
-
function
|
|
57
|
-
menu:
|
|
58
|
-
|
|
129
|
+
function B({
|
|
130
|
+
menu: n,
|
|
131
|
+
className: o,
|
|
132
|
+
children: s
|
|
59
133
|
}) {
|
|
60
|
-
return /* @__PURE__ */ e.jsxs(
|
|
61
|
-
|
|
62
|
-
|
|
134
|
+
return /* @__PURE__ */ e.jsxs(g, { className: o, children: [
|
|
135
|
+
s,
|
|
136
|
+
n
|
|
63
137
|
] });
|
|
64
138
|
}
|
|
65
139
|
export {
|
|
66
|
-
|
|
67
|
-
|
|
140
|
+
B as default,
|
|
141
|
+
Z as usePopoverMenu
|
|
68
142
|
};
|
|
@@ -3,6 +3,7 @@ import { type AtomElementType, type AtomProperties, type DefaultAtomElementType
|
|
|
3
3
|
type InitialFocusElement = HTMLElement | null;
|
|
4
4
|
type PopoverProviderProperties<Data = any> = {
|
|
5
5
|
isVisible: boolean;
|
|
6
|
+
isFocused: boolean;
|
|
6
7
|
setInitialFocus?: (initialFocus?: InitialFocusElement) => void;
|
|
7
8
|
close?: (data?: Data) => void;
|
|
8
9
|
};
|
|
@@ -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"),d=require("@kuma-ui/core"),e=require("react"),B=require("../focus-trap-react-CcpTuiJi.js"),E=require("./atom.js"),A=e.createContext({isVisible:!1,isFocused:!1}),{Provider:$}=A;function H(){return e.useContext(A)}function U({as:u,className:s,...o}){return n.jsxRuntimeExports.jsx(E.default,{as:u??E.defaultAtomElementType,...o,className:d.cx("kakadu-components-2845019685",s)})}function G({as:u,isVisible:s,label:o,shouldCloseOnOutsideClick:m=!0,shouldCloseOnEscapePress:c=!0,children:i,className:k,innerClassName:R,onClose:r,...p}){const a=e.useRef(null),x=e.useRef(null),[F,h]=e.useState(!1),[C,W]=e.useState(!1),[l,j]=e.useState(!1),I=e.useCallback(t=>{a.current=t,j(!1)},[]),g=e.useRef(null),M=e.useCallback(t=>{t&&(g.current=t)},[]),_=e.useMemo(()=>({initialFocus:()=>g.current??void 0,onActivate(){var t;(t=g.current)==null||t.focus(),h(!0)},returnFocusOnDeactivate:!1,clickOutsideDeactivates:m,escapeDeactivates:c,onUnpause(){h(!0)},onPause(){h(!1)},onDeactivate(){j(!1),h(!1)}}),[m,c]),[S,q]=e.useState(s??!1),z=e.useMemo(()=>({isVisible:S,isFocused:F,setInitialFocus:M,close:I}),[S,F,M,I]),[f,N]=e.useState("center");return e.useEffect(()=>{const t=x.current;if(t){const P=()=>{const O=t.offsetParent,b=O instanceof HTMLElement?O.getBoundingClientRect():null,D=t.getBoundingClientRect();if(!b){N("center");return}const T=b.left+b.width/2-D.width/2,L=T+D.width,y=T<0,V=L>window.innerWidth;let v="center";if(y&&V){const w=Math.abs(T);v=L-window.innerWidth>w?"right":"left"}else V?v="right":y&&(v="left");N(w=>w===v?w:v)};return P(),window.addEventListener("resize",P),()=>{window.removeEventListener("resize",P)}}},[]),e.useEffect(()=>{s&&(W(!0),q(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{j(!0)},100);return()=>{clearTimeout(t)}}j(!1)},[s]),e.useEffect(()=>{if(C&&!l){const t=setTimeout(()=>{r==null||r(a.current??void 0),q(!1)},370);return()=>{clearTimeout(t)}}},[C,l,r]),n.jsxRuntimeExports.jsx(E.default,{reference:x,as:u??E.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:n.jsxRuntimeExports.jsxs("div",{className:d.cx("kakadu-components-1118152266",l&&"kakadu-components-231244945"),children:[n.jsxRuntimeExports.jsx("div",{className:d.cx("kakadu-components-4117373591",f==="left"&&"kakadu-components-1495725644",f==="right"&&"kakadu-components-4235689197")}),n.jsxRuntimeExports.jsx(B.focusTrapReactExports.FocusTrap,{active:l,focusTrapOptions:_,children:n.jsxRuntimeExports.jsxs("div",{className:d.cx("kakadu-components-2488426662",R),children:[n.jsxRuntimeExports.jsx($,{value:z,children:i}),n.jsxRuntimeExports.jsx("div",{className:d.cx("kakadu-components-3252390100",f==="left"&&"kakadu-components-3754561431",f==="right"&&"kakadu-components-2265262600")})]})})]})})}function J(u,s){const[o,m]=e.useState(!1),c=e.useRef(void 0),i=e.useRef(null),k=e.useCallback(async p=>(m(!0),i.current=p??document.activeElement,new Promise(a=>{c.current=a})),[]),R=e.useCallback(p=>{var a;if(m(!1),(a=c.current)==null||a.call(c,p),c.current=void 0,i.current){const x=i.current;x.isConnected&&x.focus(),i.current=null}},[]),r=e.useMemo(()=>n.jsxRuntimeExports.jsx(u,{...s,isVisible:o,onClose:R}),[u,s,o,R]);return e.useMemo(()=>({isVisible:o,show:k,popover:r}),[o,k,r])}exports.PopoverContainer=U;exports.default=G;exports.usePopover=J;exports.usePopoverContext=H;
|