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