@kakadu/components 3.1.3 → 3.1.4

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