@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.
@@ -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;
@@ -0,0 +1,13 @@
1
+ import { j as u } from "../jsx-runtime-B4hRZ52C.mjs";
2
+ function o({
3
+ decorators: t,
4
+ children: r
5
+ }) {
6
+ return t.length === 0 ? r : t.reduceRight(
7
+ (e, n) => /* @__PURE__ */ u.jsx(n, { children: e }),
8
+ r
9
+ );
10
+ }
11
+ export {
12
+ o as default
13
+ };
@@ -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"),D=require("./text-button.js"),I=e.createContext({isVisible:!1}),{Provider:A}=I;function y(){return e.useContext(I)}function z(){const{close:n}=y(),r=e.useCallback(()=>{n==null||n()},[n]);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(D.default,{iconLeft:B.IconType.times,label:"Close",className:"kakadu-components-3855719072",onClick:r})})]})}function q({decorators:n,children:r}){return n.length===0?r:n.reduceRight((c,i)=>s.jsxRuntimeExports.jsx(i,{children:c}),r)}function G({root:n,outerDecorators:r=[],innerDecorators:c=[],label:i,maxWidth:u,className:l,isVisible:o,isFullWidth:f=!1,shouldCloseOnOutsideClick:p=!0,shouldCloseOnEscapePress:d=!0,showCloseButton:x=!0,onClose:a,children:N}){const v=e.useRef(null),h=e.useRef(null),[M,L]=e.useState(!1),[m,j]=e.useState(!1),b=e.useCallback(t=>{v.current=t,j(!1)},[]),R=e.useRef(null),w=e.useCallback(t=>{t&&(R.current=t)},[]),[T,C]=e.useState(o??!1),S=e.useMemo(()=>({isVisible:T,setInitialFocus:w,close:b}),[T,w,b]);e.useEffect(()=>{o&&(L(!0),C(!0))},[o]),e.useEffect(()=>{if(o){const t=setTimeout(()=>{j(!0)},100);return()=>{clearTimeout(t)}}j(!1)},[o]),e.useEffect(()=>{if(M&&!m){const t=setTimeout(()=>{a==null||a(v.current??void 0),C(!1)},370);return()=>{clearTimeout(t)}}},[M,m,a]),e.useEffect(()=>{const t=h.current;if(o&&p&&t){const k=_=>{t===_.target&&j(!1)};return t.addEventListener("click",k),()=>{t.removeEventListener("click",k)}}},[o,p]),e.useEffect(()=>{if(!o||!d)return;const t=k=>{k.key==="Escape"&&j(!1)};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[o,d]);const F=e.useMemo(()=>({initialFocus:()=>R.current??void 0,onActivate:()=>{var t;return(t=R.current)==null?void 0:t.focus()}}),[]),g=s.jsxRuntimeExports.jsx(q,{decorators:r,children:s.jsxRuntimeExports.jsx("div",{"aria-hidden":!m,style:{"--max-width":u?`${u}px`:void 0},className:E.cx("kakadu-components-4119461136",m&&"kakadu-components-2522346797",l),children:s.jsxRuntimeExports.jsx(q,{decorators:c,children:s.jsxRuntimeExports.jsx($.focusTrapReactExports.FocusTrap,{active:m,focusTrapOptions:F,children:s.jsxRuntimeExports.jsx("div",{ref:h,className:"kakadu-components-4011815997",children:s.jsxRuntimeExports.jsx("div",{role:"dialog","aria-modal":"true","aria-label":i??"Modal",className:E.cx("kakadu-components-3324483532",f&&"kakadu-components-3799971070",m&&"kakadu-components-968755580"),children:s.jsxRuntimeExports.jsxs(A,{value:S,children:[x?s.jsxRuntimeExports.jsx(z,{}):null,s.jsxRuntimeExports.jsx("div",{className:E.cx("kakadu-components-633990035",f&&"kakadu-components-171969824"),children:N})]})})})})})})});return n?P.createPortal(g,n):g}function H(n,r){const[c,i]=e.useState(!1),u=e.useRef(void 0),l=e.useRef(null),o=e.useCallback(async d=>(i(!0),l.current=d??document.activeElement,new Promise(x=>{u.current=x})),[]),f=e.useCallback(d=>{var x;if(i(!1),(x=u.current)==null||x.call(u,d),u.current=void 0,l.current){const a=l.current;a.isConnected&&a.focus(),l.current=null}},[]),p=e.useMemo(()=>s.jsxRuntimeExports.jsx(n,{...r,isVisible:c,onClose:f}),[n,r,c,f]);return e.useMemo(()=>({isVisible:c,show:o,modal:p}),[c,o,p])}exports.default=G;exports.useModal=H;exports.useModalContext=y;
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 v, useState as w, useCallback as j, useMemo as T, useEffect as p, useContext as z } from "react";
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: n
19
- } = U(), o = j(() => {
20
- n == null || n();
21
- }, [n]);
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: o }) })
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 C({
28
- decorators: n,
29
- children: o
30
- }) {
31
- return n.length === 0 ? o : n.reduceRight((r, u) => /* @__PURE__ */ t.jsx(u, { children: r }), o);
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: s,
41
- isFullWidth: f = !1,
42
- shouldCloseOnOutsideClick: k = !0,
43
- shouldCloseOnEscapePress: l = !0,
44
- showCloseButton: d = !0,
45
- onClose: a,
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 R = v(null), N = v(null), [g, A] = w(!1), [m, x] = w(!1), y = j((e) => {
49
- R.current = e, x(!1);
50
- }, []), E = v(null), L = j((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
- }, []), [M, F] = w(s ?? !1), D = T(() => ({
53
- isVisible: M,
54
- setInitialFocus: L,
55
- close: y
56
- }), [M, L, y]);
57
- p(() => {
58
- s && (A(!0), F(!0));
59
- }, [s]), p(() => {
60
- if (s) {
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
- x(!0);
57
+ k(!0);
63
58
  }, 100);
64
59
  return () => {
65
60
  clearTimeout(e);
66
61
  };
67
62
  }
68
- x(!1);
69
- }, [s]), p(() => {
70
- if (g && !m) {
63
+ k(!1);
64
+ }, [n]), x(() => {
65
+ if (y && !d) {
71
66
  const e = setTimeout(() => {
72
- a == null || a(R.current ?? void 0), F(!1);
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
- }, [g, m, a]), p(() => {
79
- const e = N.current;
80
- if (s && k && e) {
73
+ }, [y, d, r]), x(() => {
74
+ const e = R.current;
75
+ if (n && f && e) {
81
76
  const h = ($) => {
82
- e === $.target && x(!1);
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
- }, [s, k]), p(() => {
89
- if (!s || !l)
83
+ }, [n, f]), x(() => {
84
+ if (!n || !u)
90
85
  return;
91
86
  const e = (h) => {
92
- h.key === "Escape" && x(!1);
87
+ h.key === "Escape" && k(!1);
93
88
  };
94
89
  return window.addEventListener("keydown", e), () => {
95
90
  window.removeEventListener("keydown", e);
96
91
  };
97
- }, [s, l]);
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
- }), []), b = /* @__PURE__ */ t.jsx(C, { decorators: o, children: /* @__PURE__ */ t.jsx("div", { "aria-hidden": !m, style: {
105
- "--max-width": c ? `${c}px` : void 0
106
- }, className: I("kakadu-components-4119461136", m && "kakadu-components-2522346797", i), children: /* @__PURE__ */ t.jsx(C, { decorators: r, children: /* @__PURE__ */ t.jsx(H.FocusTrap, { active: m, focusTrapOptions: S, children: /* @__PURE__ */ t.jsx("div", { ref: N, className: "kakadu-components-4011815997", children: /* @__PURE__ */ t.jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": u ?? "Modal", className: I("kakadu-components-3324483532", f && "kakadu-components-3799971070", m && "kakadu-components-968755580"), children: /* @__PURE__ */ t.jsxs(Q, { value: D, children: [
107
- d ? /* @__PURE__ */ t.jsx(V, {}) : null,
108
- /* @__PURE__ */ t.jsx("div", { className: I("kakadu-components-633990035", f && "kakadu-components-171969824"), children: P })
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 n ? G(b, n) : b;
105
+ return o ? G(g, o) : g;
111
106
  }
112
- function ne(n, o) {
113
- const [r, u] = w(!1), c = v(void 0), i = v(null), s = j(async (l) => (u(!0), i.current = l ?? document.activeElement, new Promise((d) => {
114
- c.current = d;
115
- })), []), f = j((l) => {
116
- var d;
117
- if (u(!1), (d = c.current) == null || d.call(c, l), c.current = void 0, i.current) {
118
- const a = i.current;
119
- a.isConnected && a.focus(), i.current = null;
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
- }, []), k = T(() => /* @__PURE__ */ t.jsx(n, { ...o, isVisible: r, onClose: f }), [n, o, r, f]);
116
+ }, []), f = T(() => /* @__PURE__ */ t.jsx(o, { ...a, isVisible: c, onClose: m }), [o, a, c, m]);
122
117
  return T(() => ({
123
- isVisible: r,
124
- show: s,
125
- modal: k
126
- }), [r, s, k]);
118
+ isVisible: c,
119
+ show: n,
120
+ modal: f
121
+ }), [c, n, f]);
127
122
  }
128
123
  export {
129
- te as default,
130
- ne as useModal,
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 href?: string;
16
+ readonly submenu?: ReturnType<typeof usePopoverMenu>;
8
17
  readonly shouldCloseOnClick?: boolean;
9
- readonly onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
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 children: ReactNode;
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"),j=require("@kuma-ui/core"),p=require("react"),v=require("../theme.js"),c=require("../icons/icon.js"),i=require("./popover.js"),R=require("./atom.js"),h=require("./text.js"),m=require("./hover-gradient.js"),q=require("./click-ripples.js");function f({label:t,iconLeft:s,iconRight:o,href:n,shouldCloseOnClick:a=!0,onClick:r,...x}){const{close:u}=i.usePopoverContext(),l=p.useCallback(d=>{r==null||r(d),a&&(u==null||u())},[r,a,u]);return e.jsxRuntimeExports.jsxs(R.default,{as:n?"a":"button",...x,type:n?void 0:"button",role:"menuitem",href:n,className:j.cx(v.buttonResetStyles,"kakadu-components-3983689191"),onClick:l,children:[e.jsxRuntimeExports.jsxs(h.Span,{className:"kakadu-components-2031937592",children:[s?e.jsxRuntimeExports.jsx(c.default,{width:12,height:12,type:s}):null,e.jsxRuntimeExports.jsx("span",{className:"kakadu-components-3911899222",children:t}),o?e.jsxRuntimeExports.jsx(c.default,{width:12,height:12,type:o}):null]}),e.jsxRuntimeExports.jsx(m.default,{size:100,className:m.normalBlendStyles}),e.jsxRuntimeExports.jsx(q.default,{size:100})]})}function E({items:t,...s}){return e.jsxRuntimeExports.jsx(i.default,{...s,as:"nav",role:"menu",innerClassName:"kakadu-components-3719863410",children:t.map((o,n)=>e.jsxRuntimeExports.jsx(f,{...o},n))})}function M(t){const s=p.useMemo(()=>({items:t}),[t]),{show:o,popover:n}=i.usePopover(E,s);return p.useMemo(()=>({show:o,popoverMenu:n}),[o,n])}function P({menu:t,children:s}){return e.jsxRuntimeExports.jsxs(i.PopoverContainer,{children:[s,t]})}exports.default=P;exports.usePopoverMenu=M;
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 d } from "@kuma-ui/core";
3
- import { useMemo as a, useCallback as x } from "react";
4
- import { buttonResetStyles as f } from "../theme.mjs";
5
- import u from "../icons/icon.mjs";
6
- import v, { PopoverContainer as j, usePopover as h, usePopoverContext as P } from "./popover.mjs";
7
- import k from "./atom.mjs";
8
- import { Span as M } from "./text.mjs";
9
- import y, { normalBlendStyles as N } from "./hover-gradient.mjs";
10
- import b from "./click-ripples.mjs";
11
- function w({
12
- label: o,
13
- iconLeft: r,
14
- iconRight: n,
15
- href: t,
16
- shouldCloseOnClick: m = !0,
17
- onClick: s,
18
- ...i
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
- close: p
22
- } = P(), c = x((l) => {
23
- s == null || s(l), m && (p == null || p());
24
- }, [s, m, p]);
25
- return /* @__PURE__ */ e.jsxs(k, { as: t ? "a" : "button", ...i, type: t ? void 0 : "button", role: "menuitem", href: t, className: d(f, "kakadu-components-3983689191"), onClick: c, children: [
26
- /* @__PURE__ */ e.jsxs(M, { className: "kakadu-components-2031937592", children: [
27
- r ? /* @__PURE__ */ e.jsx(u, { width: 12, height: 12, type: r }) : null,
28
- /* @__PURE__ */ e.jsx("span", { className: "kakadu-components-3911899222", children: o }),
29
- n ? /* @__PURE__ */ e.jsx(u, { width: 12, height: 12, type: n }) : null
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(y, { size: 100, className: N }),
32
- /* @__PURE__ */ e.jsx(b, { size: 100 })
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 I({
36
- items: o,
37
- ...r
50
+ function L({
51
+ items: n
38
52
  }) {
39
- return /* @__PURE__ */ e.jsx(v, { ...r, as: "nav", role: "menu", innerClassName: "kakadu-components-3719863410", children: o.map((n, t) => (
40
- // eslint-disable-next-line react/no-array-index-key
41
- /* @__PURE__ */ e.jsx(w, { ...n }, t)
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 C(o) {
45
- const r = a(() => ({
46
- items: o
47
- }), [o]), {
48
- show: n,
49
- popover: t
50
- } = h(I, r);
51
- return a(() => ({
52
- show: n,
53
- popoverMenu: t
54
- }), [n, t]);
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 D({
57
- menu: o,
58
- children: r
129
+ function B({
130
+ menu: n,
131
+ className: o,
132
+ children: s
59
133
  }) {
60
- return /* @__PURE__ */ e.jsxs(j, { children: [
61
- r,
62
- o
134
+ return /* @__PURE__ */ e.jsxs(g, { className: o, children: [
135
+ s,
136
+ n
63
137
  ] });
64
138
  }
65
139
  export {
66
- D as default,
67
- C as usePopoverMenu
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 s=require("../jsx-runtime-BB_1_6y_.js"),d=require("@kuma-ui/core"),e=require("react"),_=require("../focus-trap-react-CcpTuiJi.js"),w=require("./atom.js"),D=e.createContext({isVisible:!1}),{Provider:z}=D;function B(){return e.useContext(D)}function $({as:i,className:n,...o}){return s.jsxRuntimeExports.jsx(w.default,{as:i??w.defaultAtomElementType,...o,className:d.cx("kakadu-components-2845019685",n)})}function H({as:i,isVisible:n,label:o,shouldCloseOnOutsideClick:m=!0,shouldCloseOnEscapePress:r=!0,children:u,className:k,innerClassName:R,onClose:c,...p}){const a=e.useRef(null),x=e.useRef(null),[T,V]=e.useState(!1),[l,h]=e.useState(!1),C=e.useCallback(t=>{a.current=t,h(!1)},[]),E=e.useRef(null),M=e.useCallback(t=>{t&&(E.current=t)},[]),A=e.useMemo(()=>({initialFocus:()=>E.current??void 0,onActivate:()=>{var t;return(t=E.current)==null?void 0:t.focus()},clickOutsideDeactivates:m,escapeDeactivates:r,onDeactivate(){h(!1)}}),[m,r]),[I,S]=e.useState(n??!1),W=e.useMemo(()=>({isVisible:I,setInitialFocus:M,close:C}),[I,M,C]),[f,q]=e.useState("center");return e.useEffect(()=>{const t=x.current;if(t){const g=()=>{const N=t.offsetParent,b=N instanceof HTMLElement?N.getBoundingClientRect():null,F=t.getBoundingClientRect();if(!b){q("center");return}const P=b.left+b.width/2-F.width/2,L=P+F.width,O=P<0,y=L>window.innerWidth;let v="center";if(O&&y){const j=Math.abs(P);v=L-window.innerWidth>j?"right":"left"}else y?v="right":O&&(v="left");q(j=>j===v?j:v)};return g(),window.addEventListener("resize",g),()=>{window.removeEventListener("resize",g)}}},[]),e.useEffect(()=>{n&&(V(!0),S(!0))},[n]),e.useEffect(()=>{if(n){const t=setTimeout(()=>{h(!0)},100);return()=>{clearTimeout(t)}}h(!1)},[n]),e.useEffect(()=>{if(T&&!l){const t=setTimeout(()=>{c==null||c(a.current??void 0),S(!1)},370);return()=>{clearTimeout(t)}}},[T,l,c]),s.jsxRuntimeExports.jsx(w.default,{reference:x,as:i??w.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:s.jsxRuntimeExports.jsxs("div",{className:d.cx("kakadu-components-1118152266",l&&"kakadu-components-231244945"),children:[s.jsxRuntimeExports.jsx("div",{className:d.cx("kakadu-components-3330289187",f==="left"&&"kakadu-components-1495725644",f==="right"&&"kakadu-components-4235689197")}),s.jsxRuntimeExports.jsx(_.focusTrapReactExports.FocusTrap,{active:l,focusTrapOptions:A,children:s.jsxRuntimeExports.jsxs("div",{className:d.cx("kakadu-components-3253940005",R),children:[s.jsxRuntimeExports.jsx(z,{value:W,children:u}),s.jsxRuntimeExports.jsx("div",{className:d.cx("kakadu-components-3252390100",f==="left"&&"kakadu-components-3754561431",f==="right"&&"kakadu-components-2265262600")})]})})]})})}function G(i,n){const[o,m]=e.useState(!1),r=e.useRef(void 0),u=e.useRef(null),k=e.useCallback(async p=>(m(!0),u.current=p??document.activeElement,new Promise(a=>{r.current=a})),[]),R=e.useCallback(p=>{var a;if(m(!1),(a=r.current)==null||a.call(r,p),r.current=void 0,u.current){const x=u.current;x.isConnected&&x.focus(),u.current=null}},[]),c=e.useMemo(()=>s.jsxRuntimeExports.jsx(i,{...n,isVisible:o,onClose:R}),[i,n,o,R]);return e.useMemo(()=>({isVisible:o,show:k,popover:c}),[o,k,c])}exports.PopoverContainer=$;exports.default=H;exports.usePopover=G;exports.usePopoverContext=B;
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;