@kakadu/components 3.6.0 → 3.7.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.
@@ -22,6 +22,7 @@ export type PopoverMenuItemProperties = {
22
22
  };
23
23
  export declare function usePopoverMenu(items: PopoverMenuItemProperties[]): {
24
24
  show: () => Promise<void | undefined>;
25
+ close: (result?: void | undefined) => void;
25
26
  popoverMenu: import("react/jsx-runtime").JSX.Element;
26
27
  };
27
28
  export type PopoverMenuProperties = {
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("../jsx-runtime-BB_1_6y_.js"),q=require("@kuma-ui/core"),a=require("react"),I=require("../theme.js"),h=require("../icons/icon.js"),j=require("./popover.js"),N=require("./atom.js"),y=require("./text.js"),b=require("./hover-gradient.js"),S=require("./click-ripples.js"),_=require("./separator.js"),C=require("./decorators.js"),k=new Set;function w(){const[e,n]=a.useState(!1),u=a.useCallback(s=>{n(s);for(const c of k)c(s)},[]);return a.useEffect(()=>{const s=c=>{n(c)};return k.add(s),()=>{k.delete(s)}},[]),a.useMemo(()=>({isKeyboardNavigating:e,setIsKeyboardNavigating:u}),[e,u])}function K({label:e,iconLeft:n,iconRight:u,href:s,shouldCloseOnClick:c=!0,decorators:v=[],submenu:p,className:i,onClick:r,...f}){const{isVisible:d,isFocused:o,close:x}=j.usePopoverContext(),{isKeyboardNavigating:l}=w(),m=a.useRef(!0),E=a.useCallback(()=>{m.current=o},[o]),R=a.useCallback(P=>{!l&&!m.current||o&&(r==null||r(P),p?p.show():c&&(x==null||x()))},[l,o,r,p,c,x]),g=a.useMemo(()=>t.jsxRuntimeExports.jsxs(N.default,{as:s?"a":"button",...f,type:s?void 0:"button",role:"menuitem",href:s,disabled:s?void 0:!d,className:q.cx(I.buttonResetStyles,"kakadu-components-4075327442",o&&"kakadu-components-3160069815",l?"kakadu-components-2043829669":o&&"kakadu-components-2862719809",i),onClick:R,onPointerDownCapture:E,children:[t.jsxRuntimeExports.jsxs(y.Span,{className:"kakadu-components-1109353535",children:[n?t.jsxRuntimeExports.jsx(h.default,{width:12,height:12,type:n}):null,t.jsxRuntimeExports.jsx("span",{className:"kakadu-components-913703148",children:e}),u?t.jsxRuntimeExports.jsx(h.default,{width:12,height:12,type:u}):null]}),l?null:t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(S.default,{isActive:o,size:100}),t.jsxRuntimeExports.jsx(b.default,{isActive:o,size:150,className:b.normalBlendStyles})]})]}),[s,f,d,l,i,R,E,n,e,u,o]);return t.jsxRuntimeExports.jsx(C.default,{decorators:v,children:p?t.jsxRuntimeExports.jsx(M,{menu:p.popoverMenu,className:"kakadu-components-1861176543",children:g}):g})}function A(e){if("type"in e){if(e.type==="separator")return t.jsxRuntimeExports.jsx(_.default,{});if(e.type==="group")return t.jsxRuntimeExports.jsx(y.Span,{className:"kakadu-components-1499037363",children:e.label})}return t.jsxRuntimeExports.jsx(K,{...e})}function D({items:e}){const{isFocused:n}=j.usePopoverContext(),[u,s]=a.useState([]),{setIsKeyboardNavigating:c}=w(),v=a.useCallback(i=>{i&&s(r=>r.includes(i)?r:[...r,i])},[]),p=a.useCallback(i=>{n&&(i.currentTarget.focus(),c(!1))},[n,c]);return a.useEffect(()=>{if(!n)return;const i=r=>{const f=u.filter(m=>m.isConnected),d=f.length;if(d===0)return;let o;const x=document.activeElement;let l=x?f.indexOf(x):-1;switch(l===-1&&(l=0),r.key){case"ArrowDown":{o=(l+1)%d;break}case"ArrowUp":{o=(l-1+d)%d;break}case"Home":{o=0;break}case"End":{o=d-1;break}case"Tab":{c(!0);return}}if(o!==void 0){r.preventDefault(),r.stopPropagation();const m=f[o];m&&(m.focus(),c(!0))}};return window.addEventListener("keydown",i,{capture:!0}),()=>{window.removeEventListener("keydown",i,{capture:!0})}},[n,u,c]),t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:e.map((i,r)=>t.jsxRuntimeExports.jsx(A,{...i,reference:v,onMouseEnter:p},r))})}function F({items:e,...n}){return t.jsxRuntimeExports.jsx(j.default,{...n,as:"nav",role:"menu",innerClassName:"kakadu-components-3600436535",children:t.jsxRuntimeExports.jsx(D,{items:e})})}function T(e){const n=a.useMemo(()=>({items:e}),[e]),{show:u,popover:s}=j.usePopover(F,n);return a.useMemo(()=>({show:u,popoverMenu:s}),[u,s])}function M({menu:e,className:n,children:u}){return t.jsxRuntimeExports.jsxs(j.PopoverContainer,{className:n,children:[u,e]})}exports.default=M;exports.usePopoverMenu=T;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("../jsx-runtime-BB_1_6y_.js"),q=require("@kuma-ui/core"),i=require("react"),I=require("../theme.js"),h=require("../icons/icon.js"),j=require("./popover.js"),N=require("./atom.js"),y=require("./text.js"),b=require("./hover-gradient.js"),S=require("./click-ripples.js"),_=require("./separator.js"),C=require("./decorators.js"),k=new Set;function w(){const[e,n]=i.useState(!1),a=i.useCallback(s=>{n(s);for(const r of k)r(s)},[]);return i.useEffect(()=>{const s=r=>{n(r)};return k.add(s),()=>{k.delete(s)}},[]),i.useMemo(()=>({isKeyboardNavigating:e,setIsKeyboardNavigating:a}),[e,a])}function K({label:e,iconLeft:n,iconRight:a,href:s,shouldCloseOnClick:r=!0,decorators:v=[],submenu:p,className:c,onClick:u,...f}){const{isVisible:d,isFocused:o,close:x}=j.usePopoverContext(),{isKeyboardNavigating:l}=w(),m=i.useRef(!0),E=i.useCallback(()=>{m.current=o},[o]),R=i.useCallback(P=>{!l&&!m.current||o&&(u==null||u(P),p?p.show():r&&(x==null||x()))},[l,o,u,p,r,x]),g=i.useMemo(()=>t.jsxRuntimeExports.jsxs(N.default,{as:s?"a":"button",...f,type:s?void 0:"button",role:"menuitem",href:s,disabled:s?void 0:!d,className:q.cx(I.buttonResetStyles,"kakadu-components-4075327442",o&&"kakadu-components-3160069815",l?"kakadu-components-2043829669":o&&"kakadu-components-2862719809",c),onClick:R,onPointerDownCapture:E,children:[t.jsxRuntimeExports.jsxs(y.Span,{className:"kakadu-components-1109353535",children:[n?t.jsxRuntimeExports.jsx(h.default,{width:12,height:12,type:n}):null,t.jsxRuntimeExports.jsx("span",{className:"kakadu-components-913703148",children:e}),a?t.jsxRuntimeExports.jsx(h.default,{width:12,height:12,type:a}):null]}),l?null:t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(S.default,{isActive:o,size:100}),t.jsxRuntimeExports.jsx(b.default,{isActive:o,size:150,className:b.normalBlendStyles})]})]}),[s,f,d,l,c,R,E,n,e,a,o]);return t.jsxRuntimeExports.jsx(C.default,{decorators:v,children:p?t.jsxRuntimeExports.jsx(M,{menu:p.popoverMenu,className:"kakadu-components-1861176543",children:g}):g})}function A(e){if("type"in e){if(e.type==="separator")return t.jsxRuntimeExports.jsx(_.default,{});if(e.type==="group")return t.jsxRuntimeExports.jsx(y.Span,{className:"kakadu-components-1499037363",children:e.label})}return t.jsxRuntimeExports.jsx(K,{...e})}function D({items:e}){const{isFocused:n}=j.usePopoverContext(),[a,s]=i.useState([]),{setIsKeyboardNavigating:r}=w(),v=i.useCallback(c=>{c&&s(u=>u.includes(c)?u:[...u,c])},[]),p=i.useCallback(c=>{n&&(c.currentTarget.focus(),r(!1))},[n,r]);return i.useEffect(()=>{if(!n)return;const c=u=>{const f=a.filter(m=>m.isConnected),d=f.length;if(d===0)return;let o;const x=document.activeElement;let l=x?f.indexOf(x):-1;switch(l===-1&&(l=0),u.key){case"ArrowDown":{o=(l+1)%d;break}case"ArrowUp":{o=(l-1+d)%d;break}case"Home":{o=0;break}case"End":{o=d-1;break}case"Tab":{r(!0);return}}if(o!==void 0){u.preventDefault(),u.stopPropagation();const m=f[o];m&&(m.focus(),r(!0))}};return window.addEventListener("keydown",c,{capture:!0}),()=>{window.removeEventListener("keydown",c,{capture:!0})}},[n,a,r]),t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:e.map((c,u)=>t.jsxRuntimeExports.jsx(A,{...c,reference:v,onMouseEnter:p},u))})}function F({items:e,...n}){return t.jsxRuntimeExports.jsx(j.default,{...n,as:"nav",role:"menu",innerClassName:"kakadu-components-3600436535",children:t.jsxRuntimeExports.jsx(D,{items:e})})}function T(e){const n=i.useMemo(()=>({items:e}),[e]),{show:a,close:s,popover:r}=j.usePopover(F,n);return i.useMemo(()=>({show:a,close:s,popoverMenu:r}),[a,s,r])}function M({menu:e,className:n,children:a}){return t.jsxRuntimeExports.jsxs(j.PopoverContainer,{className:n,children:[a,e]})}exports.default=M;exports.usePopoverMenu=T;
@@ -12,33 +12,33 @@ import T from "./separator.mjs";
12
12
  import V from "./decorators.mjs";
13
13
  const j = /* @__PURE__ */ new Set();
14
14
  function M() {
15
- const [e, t] = b(!1), a = v((o) => {
15
+ const [e, t] = b(!1), i = v((o) => {
16
16
  t(o);
17
- for (const c of j)
18
- c(o);
17
+ for (const s of j)
18
+ s(o);
19
19
  }, []);
20
20
  return I(() => {
21
- const o = (c) => {
22
- t(c);
21
+ const o = (s) => {
22
+ t(s);
23
23
  };
24
24
  return j.add(o), () => {
25
25
  j.delete(o);
26
26
  };
27
27
  }, []), x(() => ({
28
28
  isKeyboardNavigating: e,
29
- setIsKeyboardNavigating: a
30
- }), [e, a]);
29
+ setIsKeyboardNavigating: i
30
+ }), [e, i]);
31
31
  }
32
32
  function B({
33
33
  label: e,
34
34
  iconLeft: t,
35
- iconRight: a,
35
+ iconRight: i,
36
36
  href: o,
37
- shouldCloseOnClick: c = !0,
37
+ shouldCloseOnClick: s = !0,
38
38
  decorators: k = [],
39
39
  submenu: l,
40
- className: i,
41
- onClick: s,
40
+ className: c,
41
+ onClick: a,
42
42
  ...f
43
43
  }) {
44
44
  const {
@@ -50,18 +50,18 @@ function B({
50
50
  } = M(), p = K(!0), g = v(() => {
51
51
  p.current = r;
52
52
  }, [r]), h = v((E) => {
53
- !u && !p.current || r && (s == null || s(E), l ? l.show() : c && (m == null || m()));
54
- }, [u, r, s, l, c, m]), w = x(() => /* @__PURE__ */ n.jsxs(H, { as: o ? "a" : "button", ...f, type: o ? void 0 : "button", role: "menuitem", href: o, disabled: o ? void 0 : !d, className: S(A, "kakadu-components-4075327442", r && "kakadu-components-3160069815", u ? "kakadu-components-2043829669" : r && "kakadu-components-2862719809", i), onClick: h, onPointerDownCapture: g, children: [
53
+ !u && !p.current || r && (a == null || a(E), l ? l.show() : s && (m == null || m()));
54
+ }, [u, r, a, l, s, m]), w = x(() => /* @__PURE__ */ n.jsxs(H, { as: o ? "a" : "button", ...f, type: o ? void 0 : "button", role: "menuitem", href: o, disabled: o ? void 0 : !d, className: S(A, "kakadu-components-4075327442", r && "kakadu-components-3160069815", u ? "kakadu-components-2043829669" : r && "kakadu-components-2862719809", c), onClick: h, onPointerDownCapture: g, children: [
55
55
  /* @__PURE__ */ n.jsxs(N, { className: "kakadu-components-1109353535", children: [
56
56
  t ? /* @__PURE__ */ n.jsx(y, { width: 12, height: 12, type: t }) : null,
57
57
  /* @__PURE__ */ n.jsx("span", { className: "kakadu-components-913703148", children: e }),
58
- a ? /* @__PURE__ */ n.jsx(y, { width: 12, height: 12, type: a }) : null
58
+ i ? /* @__PURE__ */ n.jsx(y, { width: 12, height: 12, type: i }) : null
59
59
  ] }),
60
60
  u ? null : /* @__PURE__ */ n.jsxs(n.Fragment, { children: [
61
61
  /* @__PURE__ */ n.jsx(L, { isActive: r, size: 100 }),
62
62
  /* @__PURE__ */ n.jsx(R, { isActive: r, size: 150, className: z })
63
63
  ] })
64
- ] }), [o, f, d, u, i, h, g, t, e, a, r]);
64
+ ] }), [o, f, d, u, c, h, g, t, e, i, r]);
65
65
  return /* @__PURE__ */ n.jsx(V, { decorators: k, children: l ? /* @__PURE__ */ n.jsx(J, { menu: l.popoverMenu, className: "kakadu-components-1861176543", children: w }) : w });
66
66
  }
67
67
  function G(e) {
@@ -78,24 +78,24 @@ function U({
78
78
  }) {
79
79
  const {
80
80
  isFocused: t
81
- } = P(), [a, o] = b([]), {
82
- setIsKeyboardNavigating: c
83
- } = M(), k = v((i) => {
84
- i && o((s) => s.includes(i) ? s : [...s, i]);
85
- }, []), l = v((i) => {
86
- t && (i.currentTarget.focus(), c(!1));
87
- }, [t, c]);
81
+ } = P(), [i, o] = b([]), {
82
+ setIsKeyboardNavigating: s
83
+ } = M(), k = v((c) => {
84
+ c && o((a) => a.includes(c) ? a : [...a, c]);
85
+ }, []), l = v((c) => {
86
+ t && (c.currentTarget.focus(), s(!1));
87
+ }, [t, s]);
88
88
  return I(() => {
89
89
  if (!t)
90
90
  return;
91
- const i = (s) => {
92
- const f = a.filter((p) => p.isConnected), d = f.length;
91
+ const c = (a) => {
92
+ const f = i.filter((p) => p.isConnected), d = f.length;
93
93
  if (d === 0)
94
94
  return;
95
95
  let r;
96
96
  const m = document.activeElement;
97
97
  let u = m ? f.indexOf(m) : -1;
98
- switch (u === -1 && (u = 0), s.key) {
98
+ switch (u === -1 && (u = 0), a.key) {
99
99
  case "ArrowDown": {
100
100
  r = (u + 1) % d;
101
101
  break;
@@ -113,31 +113,31 @@ function U({
113
113
  break;
114
114
  }
115
115
  case "Tab": {
116
- c(!0);
116
+ s(!0);
117
117
  return;
118
118
  }
119
119
  }
120
120
  if (r !== void 0) {
121
- s.preventDefault(), s.stopPropagation();
121
+ a.preventDefault(), a.stopPropagation();
122
122
  const p = f[r];
123
- p && (p.focus(), c(!0));
123
+ p && (p.focus(), s(!0));
124
124
  }
125
125
  };
126
- return window.addEventListener("keydown", i, {
126
+ return window.addEventListener("keydown", c, {
127
127
  capture: !0
128
128
  }), () => {
129
- window.removeEventListener("keydown", i, {
129
+ window.removeEventListener("keydown", c, {
130
130
  capture: !0
131
131
  });
132
132
  };
133
- }, [t, a, c]), /* @__PURE__ */ n.jsx(n.Fragment, { children: e.map((i, s) => /* @__PURE__ */ n.jsx(
133
+ }, [t, i, s]), /* @__PURE__ */ n.jsx(n.Fragment, { children: e.map((c, a) => /* @__PURE__ */ n.jsx(
134
134
  G,
135
135
  {
136
- ...i,
136
+ ...c,
137
137
  reference: k,
138
138
  onMouseEnter: l
139
139
  },
140
- s
140
+ a
141
141
  )) });
142
142
  }
143
143
  function q({
@@ -150,21 +150,23 @@ function re(e) {
150
150
  const t = x(() => ({
151
151
  items: e
152
152
  }), [e]), {
153
- show: a,
154
- popover: o
153
+ show: i,
154
+ close: o,
155
+ popover: s
155
156
  } = F(q, t);
156
157
  return x(() => ({
157
- show: a,
158
- popoverMenu: o
159
- }), [a, o]);
158
+ show: i,
159
+ close: o,
160
+ popoverMenu: s
161
+ }), [i, o, s]);
160
162
  }
161
163
  function J({
162
164
  menu: e,
163
165
  className: t,
164
- children: a
166
+ children: i
165
167
  }) {
166
168
  return /* @__PURE__ */ n.jsxs(D, { className: t, children: [
167
- a,
169
+ i,
168
170
  e
169
171
  ] });
170
172
  }
@@ -23,6 +23,7 @@ export default function Popover<Data = any, Type extends AtomElementType = Defau
23
23
  export declare function usePopover<PopoverResult, PopoverProperties = PopoverBaseProperties<PopoverResult>>(PopoverComponent: ComponentType<PopoverProperties>, properties?: PopoverProperties): {
24
24
  isVisible: boolean;
25
25
  show: () => Promise<PopoverResult | undefined>;
26
+ close: (result?: PopoverResult) => void;
26
27
  popover: import("react/jsx-runtime").JSX.Element;
27
28
  };
28
29
  export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),l=require("@kuma-ui/core"),e=require("react"),H=require("../focus-trap-react-CcpTuiJi.js"),g=require("./atom.js"),z=e.createContext({isVisible:!1,isFocused:!1}),{Provider:U}=z;function G(){return e.useContext(z)}function J({as:r,className:s,...o}){return n.jsxRuntimeExports.jsx(g.default,{as:r??g.defaultAtomElementType,...o,className:l.cx("kakadu-components-2845019685",s)})}function K({as:r,isVisible:s,label:o,shouldCloseOnOutsideClick:f=!0,shouldCloseOnEscapePress:c=!0,children:m,className:p,innerClassName:x,onClose:a,...v}){const b=e.useRef(null),F=e.useRef(null),[I,k]=e.useState(!1),[S,B]=e.useState(!1),[u,R]=e.useState(!1),C=e.useCallback(t=>{b.current=t,R(!1)},[]),j=e.useRef(null),M=e.useCallback(t=>{t&&(j.current=t)},[]),W=e.useMemo(()=>({initialFocus:()=>j.current??void 0,onPostActivate(){var t;k(!0),(t=j.current)==null||t.focus()},clickOutsideDeactivates:f,escapeDeactivates:c,onPostUnpause(){k(!0)},onPause(){k(!1)},onDeactivate(){R(!1),k(!1)}}),[f,c]),[q,N]=e.useState(s??!1),$=e.useMemo(()=>({isVisible:q,isFocused:I,setInitialFocus:M,close:C}),[q,I,M,C]),[i,L]=e.useState("center");return e.useEffect(()=>{const t=F.current;if(t){const w=()=>{const O=t.offsetParent,E=O instanceof HTMLElement?O.getBoundingClientRect():null,y=t.getBoundingClientRect();if(!E){L("center");return}const P=16,D=window.innerWidth-P,T=E.left+E.width/2-y.width/2,V=T+y.width,A=T<P,_=V>D;let d="center";if(A&&_){const h=P-T;d=V-D>h?"right":"left"}else _?d="right":A&&(d="left");L(h=>h===d?h:d)};return w(),window.addEventListener("resize",w),()=>{window.removeEventListener("resize",w)}}},[]),e.useEffect(()=>{s&&(B(!0),N(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{R(!0)},100);return()=>{clearTimeout(t)}}R(!1)},[s]),e.useEffect(()=>{if(S&&!u){const t=setTimeout(()=>{a==null||a(b.current??void 0),N(!1)},370);return()=>{clearTimeout(t)}}},[S,u,a]),n.jsxRuntimeExports.jsx(g.default,{reference:F,as:r??g.defaultAtomElementType,role:"dialog","aria-hidden":!u,"aria-label":o??"Popover",...v,className:l.cx("kakadu-components-3920007758",i==="left"&&"kakadu-components-611400930",i==="right"&&"kakadu-components-944244368",u&&"kakadu-components-1399012551",p),children:n.jsxRuntimeExports.jsxs("div",{className:l.cx("kakadu-components-1118152266",u&&"kakadu-components-231244945"),children:[n.jsxRuntimeExports.jsx("div",{className:l.cx("kakadu-components-1951789226",i==="left"&&"kakadu-components-1495725644",i==="right"&&"kakadu-components-4235689197")}),n.jsxRuntimeExports.jsx(H.focusTrapReactExports.FocusTrap,{active:u,focusTrapOptions:W,children:n.jsxRuntimeExports.jsxs("div",{className:l.cx("kakadu-components-2488426662",x),children:[n.jsxRuntimeExports.jsx(U,{value:$,children:m}),n.jsxRuntimeExports.jsx("div",{className:l.cx("kakadu-components-3252390100",i==="left"&&"kakadu-components-3754561431",i==="right"&&"kakadu-components-2265262600")})]})})]})})}function Q(r,s){const[o,f]=e.useState(!1),c=e.useRef(void 0),m=e.useCallback(async()=>(f(!0),new Promise(a=>{c.current=a})),[]),p=e.useCallback(a=>{var v;f(!1),(v=c.current)==null||v.call(c,a),c.current=void 0},[]),x=e.useMemo(()=>n.jsxRuntimeExports.jsx(r,{...s,isVisible:o,onClose:p}),[r,s,o,p]);return e.useMemo(()=>({isVisible:o,show:m,popover:x}),[o,m,x])}exports.PopoverContainer=J;exports.default=K;exports.usePopover=Q;exports.usePopoverContext=G;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),f=require("@kuma-ui/core"),e=require("react"),H=require("../focus-trap-react-CcpTuiJi.js"),g=require("./atom.js"),z=e.createContext({isVisible:!1,isFocused:!1}),{Provider:U}=z;function G(){return e.useContext(z)}function J({as:r,className:s,...o}){return n.jsxRuntimeExports.jsx(g.default,{as:r??g.defaultAtomElementType,...o,className:f.cx("kakadu-components-2845019685",s)})}function K({as:r,isVisible:s,label:o,shouldCloseOnOutsideClick:d=!0,shouldCloseOnEscapePress:c=!0,children:p,className:u,innerClassName:x,onClose:a,...v}){const b=e.useRef(null),F=e.useRef(null),[I,k]=e.useState(!1),[S,B]=e.useState(!1),[i,R]=e.useState(!1),C=e.useCallback(t=>{b.current=t,R(!1)},[]),j=e.useRef(null),M=e.useCallback(t=>{t&&(j.current=t)},[]),W=e.useMemo(()=>({initialFocus:()=>j.current??void 0,onPostActivate(){var t;k(!0),(t=j.current)==null||t.focus()},clickOutsideDeactivates:d,escapeDeactivates:c,onPostUnpause(){k(!0)},onPause(){k(!1)},onDeactivate(){R(!1),k(!1)}}),[d,c]),[q,N]=e.useState(s??!1),$=e.useMemo(()=>({isVisible:q,isFocused:I,setInitialFocus:M,close:C}),[q,I,M,C]),[l,L]=e.useState("center");return e.useEffect(()=>{const t=F.current;if(t){const w=()=>{const O=t.offsetParent,E=O instanceof HTMLElement?O.getBoundingClientRect():null,y=t.getBoundingClientRect();if(!E){L("center");return}const P=16,D=window.innerWidth-P,T=E.left+E.width/2-y.width/2,V=T+y.width,A=T<P,_=V>D;let m="center";if(A&&_){const h=P-T;m=V-D>h?"right":"left"}else _?m="right":A&&(m="left");L(h=>h===m?h:m)};return w(),window.addEventListener("resize",w),()=>{window.removeEventListener("resize",w)}}},[]),e.useEffect(()=>{s&&(B(!0),N(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{R(!0)},100);return()=>{clearTimeout(t)}}R(!1)},[s]),e.useEffect(()=>{if(S&&!i){const t=setTimeout(()=>{a==null||a(b.current??void 0),N(!1)},370);return()=>{clearTimeout(t)}}},[S,i,a]),n.jsxRuntimeExports.jsx(g.default,{reference:F,as:r??g.defaultAtomElementType,role:"dialog","aria-hidden":!i,"aria-label":o??"Popover",...v,className:f.cx("kakadu-components-3920007758",l==="left"&&"kakadu-components-611400930",l==="right"&&"kakadu-components-944244368",i&&"kakadu-components-1399012551",u),children:n.jsxRuntimeExports.jsxs("div",{className:f.cx("kakadu-components-1118152266",i&&"kakadu-components-231244945"),children:[n.jsxRuntimeExports.jsx("div",{className:f.cx("kakadu-components-1951789226",l==="left"&&"kakadu-components-1495725644",l==="right"&&"kakadu-components-4235689197")}),n.jsxRuntimeExports.jsx(H.focusTrapReactExports.FocusTrap,{active:i,focusTrapOptions:W,children:n.jsxRuntimeExports.jsxs("div",{className:f.cx("kakadu-components-2488426662",x),children:[n.jsxRuntimeExports.jsx(U,{value:$,children:p}),n.jsxRuntimeExports.jsx("div",{className:f.cx("kakadu-components-3252390100",l==="left"&&"kakadu-components-3754561431",l==="right"&&"kakadu-components-2265262600")})]})})]})})}function Q(r,s){const[o,d]=e.useState(!1),c=e.useRef(void 0),p=e.useCallback(async()=>(d(!0),new Promise(a=>{c.current=a})),[]),u=e.useCallback(a=>{var v;d(!1),(v=c.current)==null||v.call(c,a),c.current=void 0},[]),x=e.useMemo(()=>n.jsxRuntimeExports.jsx(r,{...s,isVisible:o,onClose:u}),[r,s,o,u]);return e.useMemo(()=>({isVisible:o,show:p,close:u,popover:x}),[o,p,u,x])}exports.PopoverContainer=J;exports.default=K;exports.usePopover=Q;exports.usePopoverContext=G;
@@ -1,6 +1,6 @@
1
1
  import { j as n } from "../jsx-runtime-B4hRZ52C.mjs";
2
- import { cx as u } from "@kuma-ui/core";
3
- import { createContext as Y, useRef as j, useState as l, useCallback as P, useMemo as R, useEffect as w, useContext as Z } from "react";
2
+ import { cx as l } from "@kuma-ui/core";
3
+ import { createContext as Y, useRef as j, useState as d, useCallback as P, useMemo as R, useEffect as w, useContext as Z } from "react";
4
4
  import { f as _ } from "../focus-trap-react-DYXrtbDH.mjs";
5
5
  import q, { defaultAtomElementType as G } from "./atom.mjs";
6
6
  const J = Y({
@@ -17,21 +17,21 @@ function re({
17
17
  className: t,
18
18
  ...s
19
19
  }) {
20
- return /* @__PURE__ */ n.jsx(q, { as: c ?? G, ...s, className: u("kakadu-components-2845019685", t) });
20
+ return /* @__PURE__ */ n.jsx(q, { as: c ?? G, ...s, className: l("kakadu-components-2845019685", t) });
21
21
  }
22
22
  function ie({
23
23
  as: c,
24
24
  isVisible: t,
25
25
  label: s,
26
- shouldCloseOnOutsideClick: d = !0,
26
+ shouldCloseOnOutsideClick: f = !0,
27
27
  shouldCloseOnEscapePress: o = !0,
28
- children: m,
29
- className: p,
28
+ children: p,
29
+ className: r,
30
30
  innerClassName: k,
31
31
  onClose: a,
32
32
  ...v
33
33
  }) {
34
- const N = j(null), L = j(null), [D, h] = l(!1), [O, K] = l(!1), [r, x] = l(!1), V = P((e) => {
34
+ const N = j(null), L = j(null), [D, h] = d(!1), [O, K] = d(!1), [i, x] = d(!1), V = P((e) => {
35
35
  N.current = e, x(!1);
36
36
  }, []), T = j(null), A = P((e) => {
37
37
  e && (T.current = e);
@@ -41,7 +41,7 @@ function ie({
41
41
  var e;
42
42
  h(!0), (e = T.current) == null || e.focus();
43
43
  },
44
- clickOutsideDeactivates: d,
44
+ clickOutsideDeactivates: f,
45
45
  escapeDeactivates: o,
46
46
  onPostUnpause() {
47
47
  h(!0);
@@ -52,12 +52,12 @@ function ie({
52
52
  onDeactivate() {
53
53
  x(!1), h(!1);
54
54
  }
55
- }), [d, o]), [y, z] = l(t ?? !1), X = R(() => ({
55
+ }), [f, o]), [y, z] = d(t ?? !1), X = R(() => ({
56
56
  isVisible: y,
57
57
  isFocused: D,
58
58
  setInitialFocus: A,
59
59
  close: V
60
- }), [y, D, A, V]), [i, B] = l("center");
60
+ }), [y, D, A, V]), [u, B] = d("center");
61
61
  return w(() => {
62
62
  const e = L.current;
63
63
  if (e) {
@@ -68,12 +68,12 @@ function ie({
68
68
  return;
69
69
  }
70
70
  const b = 16, W = window.innerWidth - b, E = I.left + I.width / 2 - M.width / 2, H = E + M.width, S = E < b, U = H > W;
71
- let f = "center";
71
+ let m = "center";
72
72
  if (S && U) {
73
73
  const g = b - E;
74
- f = H - W > g ? "right" : "left";
75
- } else U ? f = "right" : S && (f = "left");
76
- B((g) => g === f ? g : f);
74
+ m = H - W > g ? "right" : "left";
75
+ } else U ? m = "right" : S && (m = "left");
76
+ B((g) => g === m ? g : m);
77
77
  };
78
78
  return F(), window.addEventListener("resize", F), () => {
79
79
  window.removeEventListener("resize", F);
@@ -92,7 +92,7 @@ function ie({
92
92
  }
93
93
  x(!1);
94
94
  }, [t]), w(() => {
95
- if (O && !r) {
95
+ if (O && !i) {
96
96
  const e = setTimeout(() => {
97
97
  a == null || a(N.current ?? void 0), z(!1);
98
98
  }, 370);
@@ -100,26 +100,27 @@ function ie({
100
100
  clearTimeout(e);
101
101
  };
102
102
  }
103
- }, [O, r, a]), /* @__PURE__ */ n.jsx(q, { reference: L, as: c ?? G, role: "dialog", "aria-hidden": !r, "aria-label": s ?? "Popover", ...v, className: u("kakadu-components-3920007758", i === "left" && "kakadu-components-611400930", i === "right" && "kakadu-components-944244368", r && "kakadu-components-1399012551", p), children: /* @__PURE__ */ n.jsxs("div", { className: u("kakadu-components-1118152266", r && "kakadu-components-231244945"), children: [
104
- /* @__PURE__ */ n.jsx("div", { className: u("kakadu-components-1951789226", i === "left" && "kakadu-components-1495725644", i === "right" && "kakadu-components-4235689197") }),
105
- /* @__PURE__ */ n.jsx(_.FocusTrap, { active: r, focusTrapOptions: Q, children: /* @__PURE__ */ n.jsxs("div", { className: u("kakadu-components-2488426662", k), children: [
106
- /* @__PURE__ */ n.jsx($, { value: X, children: m }),
107
- /* @__PURE__ */ n.jsx("div", { className: u("kakadu-components-3252390100", i === "left" && "kakadu-components-3754561431", i === "right" && "kakadu-components-2265262600") })
103
+ }, [O, i, a]), /* @__PURE__ */ n.jsx(q, { reference: L, as: c ?? G, role: "dialog", "aria-hidden": !i, "aria-label": s ?? "Popover", ...v, className: l("kakadu-components-3920007758", u === "left" && "kakadu-components-611400930", u === "right" && "kakadu-components-944244368", i && "kakadu-components-1399012551", r), children: /* @__PURE__ */ n.jsxs("div", { className: l("kakadu-components-1118152266", i && "kakadu-components-231244945"), children: [
104
+ /* @__PURE__ */ n.jsx("div", { className: l("kakadu-components-1951789226", u === "left" && "kakadu-components-1495725644", u === "right" && "kakadu-components-4235689197") }),
105
+ /* @__PURE__ */ n.jsx(_.FocusTrap, { active: i, focusTrapOptions: Q, children: /* @__PURE__ */ n.jsxs("div", { className: l("kakadu-components-2488426662", k), children: [
106
+ /* @__PURE__ */ n.jsx($, { value: X, children: p }),
107
+ /* @__PURE__ */ n.jsx("div", { className: l("kakadu-components-3252390100", u === "left" && "kakadu-components-3754561431", u === "right" && "kakadu-components-2265262600") })
108
108
  ] }) })
109
109
  ] }) });
110
110
  }
111
111
  function ue(c, t) {
112
- const [s, d] = l(!1), o = j(void 0), m = P(async () => (d(!0), new Promise((a) => {
112
+ const [s, f] = d(!1), o = j(void 0), p = P(async () => (f(!0), new Promise((a) => {
113
113
  o.current = a;
114
- })), []), p = P((a) => {
114
+ })), []), r = P((a) => {
115
115
  var v;
116
- d(!1), (v = o.current) == null || v.call(o, a), o.current = void 0;
117
- }, []), k = R(() => /* @__PURE__ */ n.jsx(c, { ...t, isVisible: s, onClose: p }), [c, t, s, p]);
116
+ f(!1), (v = o.current) == null || v.call(o, a), o.current = void 0;
117
+ }, []), k = R(() => /* @__PURE__ */ n.jsx(c, { ...t, isVisible: s, onClose: r }), [c, t, s, r]);
118
118
  return R(() => ({
119
119
  isVisible: s,
120
- show: m,
120
+ show: p,
121
+ close: r,
121
122
  popover: k
122
- }), [s, m, k]);
123
+ }), [s, p, r, k]);
123
124
  }
124
125
  export {
125
126
  re as PopoverContainer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakadu/components",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "Kakadu components library",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",