@kakadu/components 3.2.2 → 3.2.3

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.
@@ -3,6 +3,7 @@ import { type DecoratorType } from './decorators';
3
3
  type InitialFocusElement = HTMLElement | null;
4
4
  type ModalProviderProperties<Data = any> = {
5
5
  isVisible: boolean;
6
+ isInteractive: 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 n=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),v=require("@kuma-ui/core"),P=require("react-dom"),$=require("../focus-trap-react-CcpTuiJi.js"),B=require("../icons/icon.js"),A=require("./text-button.js"),C=require("./decorators.js"),I=e.createContext({isVisible:!1}),{Provider:D}=I;function y(){return e.useContext(I)}function z(){const{close:o}=y(),c=e.useCallback(()=>{o==null||o()},[o]);return n.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2566044647",children:n.jsxRuntimeExports.jsx(A.default,{iconLeft:B.IconType.times,label:"Close",onClick:c})})}function G({root:o,outerDecorators:c=[],innerDecorators:u=[],label:x,maxWidth:r,className:m,isVisible:s,isFullWidth:l=!1,shouldCloseOnOutsideClick:a=!0,shouldCloseOnEscapePress:d=!0,showCloseButton:L=!0,onClose:k,children:S}){const E=e.useRef(null),R=e.useRef(null),[M,g]=e.useState(!1),[i,f]=e.useState(!1),h=e.useCallback(t=>{E.current=t,f(!1)},[]),j=e.useRef(null),b=e.useCallback(t=>{t&&(j.current=t)},[]),[w,T]=e.useState(s??!1),N=e.useMemo(()=>({isVisible:w,setInitialFocus:b,close:h}),[w,b,h]);e.useEffect(()=>{s&&(g(!0),T(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{f(!0)},100);return()=>{clearTimeout(t)}}f(!1)},[s]),e.useEffect(()=>{if(M&&!i){const t=setTimeout(()=>{k==null||k(E.current??void 0),T(!1)},370);return()=>{clearTimeout(t)}}},[M,i,k]),e.useEffect(()=>{const t=R.current;if(s&&a&&t){const p=F=>{t===F.target&&f(!1)};return t.addEventListener("click",p),()=>{t.removeEventListener("click",p)}}},[s,a]),e.useEffect(()=>{if(!s||!d)return;const t=p=>{p.key==="Escape"&&f(!1)};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[s,d]);const _=e.useMemo(()=>({initialFocus:()=>j.current??void 0,onActivate:()=>{var t;return(t=j.current)==null?void 0:t.focus()}}),[]),q=n.jsxRuntimeExports.jsx(C.default,{decorators:c,children:n.jsxRuntimeExports.jsx("div",{"aria-hidden":!i,style:{"--max-width":r?`${r}px`:void 0},className:v.cx("kakadu-components-4119461136",i&&"kakadu-components-2522346797",m),children:n.jsxRuntimeExports.jsx(C.default,{decorators:u,children:n.jsxRuntimeExports.jsx($.focusTrapReactExports.FocusTrap,{active:i,focusTrapOptions:_,children:n.jsxRuntimeExports.jsx("div",{ref:R,className:"kakadu-components-4011815997",children:n.jsxRuntimeExports.jsx("div",{role:"dialog","aria-modal":"true","aria-label":x??"Modal",className:v.cx("kakadu-components-3324483532",l&&"kakadu-components-3799971070",i&&"kakadu-components-968755580"),children:n.jsxRuntimeExports.jsxs(D,{value:N,children:[L?n.jsxRuntimeExports.jsx(z,{}):null,n.jsxRuntimeExports.jsx("div",{className:v.cx("kakadu-components-633990035",l&&"kakadu-components-171969824"),children:S})]})})})})})})});return o?P.createPortal(q,o):q}function H(o,c){const[u,x]=e.useState(!1),r=e.useRef(void 0),m=e.useCallback(async()=>(x(!0),new Promise(a=>{r.current=a})),[]),s=e.useCallback(a=>{var d;x(!1),(d=r.current)==null||d.call(r,a),r.current=void 0},[]),l=e.useMemo(()=>n.jsxRuntimeExports.jsx(o,{...c,isVisible:u,onClose:s}),[o,c,u,s]);return e.useMemo(()=>({isVisible:u,show:m,modal:l}),[u,m,l])}exports.default=G;exports.useModal=H;exports.useModalContext=y;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../jsx-runtime-BB_1_6y_.js"),e=require("react"),v=require("@kuma-ui/core"),P=require("react-dom"),$=require("../focus-trap-react-CcpTuiJi.js"),B=require("../icons/icon.js"),A=require("./text-button.js"),q=require("./decorators.js"),C=e.createContext({isVisible:!1,isInteractive:!1}),{Provider:D}=C;function y(){return e.useContext(C)}function z(){const{isInteractive:u,close:o}=y(),r=e.useCallback(()=>{o==null||o()},[o]);return n.jsxRuntimeExports.jsx("div",{className:"kakadu-components-2566044647",children:n.jsxRuntimeExports.jsx(A.default,{iconLeft:B.IconType.times,label:"Close",disabled:!u,onClick:r})})}function G({root:u,outerDecorators:o=[],innerDecorators:r=[],label:x,maxWidth:c,className:m,isVisible:s,isFullWidth:l=!1,shouldCloseOnOutsideClick:i=!0,shouldCloseOnEscapePress:d=!0,showCloseButton:L=!0,onClose:k,children:S}){const E=e.useRef(null),R=e.useRef(null),[M,g]=e.useState(!1),[a,f]=e.useState(!1),b=e.useCallback(t=>{E.current=t,f(!1)},[]),j=e.useRef(null),h=e.useCallback(t=>{t&&(j.current=t)},[]),[I,w]=e.useState(s??!1),N=e.useMemo(()=>({isVisible:I,isInteractive:a,setInitialFocus:h,close:b}),[I,a,h,b]);e.useEffect(()=>{s&&(g(!0),w(!0))},[s]),e.useEffect(()=>{if(s){const t=setTimeout(()=>{f(!0)},100);return()=>{clearTimeout(t)}}f(!1)},[s]),e.useEffect(()=>{if(M&&!a){const t=setTimeout(()=>{k==null||k(E.current??void 0),w(!1)},370);return()=>{clearTimeout(t)}}},[M,a,k]),e.useEffect(()=>{const t=R.current;if(s&&i&&t){const p=F=>{t===F.target&&f(!1)};return t.addEventListener("click",p),()=>{t.removeEventListener("click",p)}}},[s,i]),e.useEffect(()=>{if(!s||!d)return;const t=p=>{p.key==="Escape"&&f(!1)};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[s,d]);const _=e.useMemo(()=>({initialFocus:()=>j.current??void 0,onActivate:()=>{var t;return(t=j.current)==null?void 0:t.focus()}}),[]),T=n.jsxRuntimeExports.jsx(q.default,{decorators:o,children:n.jsxRuntimeExports.jsx("div",{"aria-hidden":!a,style:{"--max-width":c?`${c}px`:void 0},className:v.cx("kakadu-components-4119461136",a&&"kakadu-components-2522346797",m),children:n.jsxRuntimeExports.jsx(q.default,{decorators:r,children:n.jsxRuntimeExports.jsx($.focusTrapReactExports.FocusTrap,{active:a,focusTrapOptions:_,children:n.jsxRuntimeExports.jsx("div",{ref:R,className:"kakadu-components-4011815997",children:n.jsxRuntimeExports.jsx("div",{role:"dialog","aria-modal":"true","aria-label":x??"Modal",className:v.cx("kakadu-components-3324483532",l&&"kakadu-components-3799971070",a&&"kakadu-components-968755580"),children:n.jsxRuntimeExports.jsxs(D,{value:N,children:[L?n.jsxRuntimeExports.jsx(z,{}):null,n.jsxRuntimeExports.jsx("div",{className:v.cx("kakadu-components-633990035",l&&"kakadu-components-171969824"),children:S})]})})})})})})});return u?P.createPortal(T,u):T}function H(u,o){const[r,x]=e.useState(!1),c=e.useRef(void 0),m=e.useCallback(async()=>(x(!0),new Promise(i=>{c.current=i})),[]),s=e.useCallback(i=>{var d;x(!1),(d=c.current)==null||d.call(c,i),c.current=void 0},[]),l=e.useMemo(()=>n.jsxRuntimeExports.jsx(u,{...o,isVisible:r,onClose:s}),[u,o,r,s]);return e.useMemo(()=>({isVisible:r,show:m,modal:l}),[r,m,l])}exports.default=G;exports.useModal=H;exports.useModalContext=y;
@@ -1,13 +1,14 @@
1
1
  import { j as n } from "../jsx-runtime-B4hRZ52C.mjs";
2
- import { createContext as q, useRef as j, useState as h, useCallback as m, useMemo as w, useEffect as f, useContext as z } from "react";
3
- import { cx as I } from "@kuma-ui/core";
2
+ import { createContext as q, useRef as j, useState as h, useCallback as m, useMemo as I, useEffect as f, useContext as z } from "react";
3
+ import { cx as T } 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
8
  import g from "./decorators.mjs";
9
9
  const C = q({
10
- isVisible: !1
10
+ isVisible: !1,
11
+ isInteractive: !1
11
12
  }), {
12
13
  Provider: Q
13
14
  } = C;
@@ -16,38 +17,40 @@ function U() {
16
17
  }
17
18
  function V() {
18
19
  const {
19
- close: o
20
- } = U(), r = m(() => {
21
- o == null || o();
22
- }, [o]);
23
- return /* @__PURE__ */ n.jsx("div", { className: "kakadu-components-2566044647", children: /* @__PURE__ */ n.jsx(K, { iconLeft: J.times, label: "Close", onClick: r }) });
20
+ isInteractive: c,
21
+ close: s
22
+ } = U(), o = m(() => {
23
+ s == null || s();
24
+ }, [s]);
25
+ return /* @__PURE__ */ n.jsx("div", { className: "kakadu-components-2566044647", children: /* @__PURE__ */ n.jsx(K, { iconLeft: J.times, label: "Close", disabled: !c, onClick: o }) });
24
26
  }
25
27
  function ne({
26
- root: o,
27
- outerDecorators: r = [],
28
- innerDecorators: a = [],
28
+ root: c,
29
+ outerDecorators: s = [],
30
+ innerDecorators: o = [],
29
31
  label: k,
30
- maxWidth: s,
32
+ maxWidth: r,
31
33
  className: x,
32
34
  isVisible: t,
33
35
  isFullWidth: u = !1,
34
- shouldCloseOnOutsideClick: c = !0,
36
+ shouldCloseOnOutsideClick: i = !0,
35
37
  shouldCloseOnEscapePress: l = !0,
36
38
  showCloseButton: B = !0,
37
39
  onClose: p,
38
40
  children: P
39
41
  }) {
40
- const E = j(null), y = j(null), [L, A] = h(!1), [i, d] = h(!1), M = m((e) => {
42
+ const E = j(null), y = j(null), [L, A] = h(!1), [a, d] = h(!1), M = m((e) => {
41
43
  E.current = e, d(!1);
42
- }, []), T = j(null), R = m((e) => {
43
- e && (T.current = e);
44
- }, []), [N, b] = h(t ?? !1), D = w(() => ({
45
- isVisible: N,
44
+ }, []), w = j(null), R = m((e) => {
45
+ e && (w.current = e);
46
+ }, []), [b, N] = h(t ?? !1), D = I(() => ({
47
+ isVisible: b,
48
+ isInteractive: a,
46
49
  setInitialFocus: R,
47
50
  close: M
48
- }), [N, R, M]);
51
+ }), [b, a, R, M]);
49
52
  f(() => {
50
- t && (A(!0), b(!0));
53
+ t && (A(!0), N(!0));
51
54
  }, [t]), f(() => {
52
55
  if (t) {
53
56
  const e = setTimeout(() => {
@@ -59,17 +62,17 @@ function ne({
59
62
  }
60
63
  d(!1);
61
64
  }, [t]), f(() => {
62
- if (L && !i) {
65
+ if (L && !a) {
63
66
  const e = setTimeout(() => {
64
- p == null || p(E.current ?? void 0), b(!1);
67
+ p == null || p(E.current ?? void 0), N(!1);
65
68
  }, 370);
66
69
  return () => {
67
70
  clearTimeout(e);
68
71
  };
69
72
  }
70
- }, [L, i, p]), f(() => {
73
+ }, [L, a, p]), f(() => {
71
74
  const e = y.current;
72
- if (t && c && e) {
75
+ if (t && i && e) {
73
76
  const v = ($) => {
74
77
  e === $.target && d(!1);
75
78
  };
@@ -77,7 +80,7 @@ function ne({
77
80
  e.removeEventListener("click", v);
78
81
  };
79
82
  }
80
- }, [t, c]), f(() => {
83
+ }, [t, i]), f(() => {
81
84
  if (!t || !l)
82
85
  return;
83
86
  const e = (v) => {
@@ -87,35 +90,35 @@ function ne({
87
90
  window.removeEventListener("keydown", e);
88
91
  };
89
92
  }, [t, l]);
90
- const S = w(() => ({
91
- initialFocus: () => T.current ?? void 0,
93
+ const S = I(() => ({
94
+ initialFocus: () => w.current ?? void 0,
92
95
  onActivate: () => {
93
96
  var e;
94
- return (e = T.current) == null ? void 0 : e.focus();
97
+ return (e = w.current) == null ? void 0 : e.focus();
95
98
  }
96
- }), []), F = /* @__PURE__ */ n.jsx(g, { decorators: r, children: /* @__PURE__ */ n.jsx("div", { "aria-hidden": !i, style: {
97
- "--max-width": s ? `${s}px` : void 0
98
- }, className: I("kakadu-components-4119461136", i && "kakadu-components-2522346797", x), children: /* @__PURE__ */ n.jsx(g, { decorators: a, children: /* @__PURE__ */ n.jsx(H.FocusTrap, { active: i, focusTrapOptions: S, children: /* @__PURE__ */ n.jsx("div", { ref: y, className: "kakadu-components-4011815997", children: /* @__PURE__ */ n.jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": k ?? "Modal", className: I("kakadu-components-3324483532", u && "kakadu-components-3799971070", i && "kakadu-components-968755580"), children: /* @__PURE__ */ n.jsxs(Q, { value: D, children: [
99
+ }), []), F = /* @__PURE__ */ n.jsx(g, { decorators: s, children: /* @__PURE__ */ n.jsx("div", { "aria-hidden": !a, style: {
100
+ "--max-width": r ? `${r}px` : void 0
101
+ }, className: T("kakadu-components-4119461136", a && "kakadu-components-2522346797", x), children: /* @__PURE__ */ n.jsx(g, { decorators: o, children: /* @__PURE__ */ n.jsx(H.FocusTrap, { active: a, focusTrapOptions: S, children: /* @__PURE__ */ n.jsx("div", { ref: y, className: "kakadu-components-4011815997", children: /* @__PURE__ */ n.jsx("div", { role: "dialog", "aria-modal": "true", "aria-label": k ?? "Modal", className: T("kakadu-components-3324483532", u && "kakadu-components-3799971070", a && "kakadu-components-968755580"), children: /* @__PURE__ */ n.jsxs(Q, { value: D, children: [
99
102
  B ? /* @__PURE__ */ n.jsx(V, {}) : null,
100
- /* @__PURE__ */ n.jsx("div", { className: I("kakadu-components-633990035", u && "kakadu-components-171969824"), children: P })
103
+ /* @__PURE__ */ n.jsx("div", { className: T("kakadu-components-633990035", u && "kakadu-components-171969824"), children: P })
101
104
  ] }) }) }) }) }) }) });
102
- return o ? G(F, o) : F;
105
+ return c ? G(F, c) : F;
103
106
  }
104
- function oe(o, r) {
105
- const [a, k] = h(!1), s = j(void 0), x = m(async () => (k(!0), new Promise((c) => {
106
- s.current = c;
107
- })), []), t = m((c) => {
107
+ function se(c, s) {
108
+ const [o, k] = h(!1), r = j(void 0), x = m(async () => (k(!0), new Promise((i) => {
109
+ r.current = i;
110
+ })), []), t = m((i) => {
108
111
  var l;
109
- k(!1), (l = s.current) == null || l.call(s, c), s.current = void 0;
110
- }, []), u = w(() => /* @__PURE__ */ n.jsx(o, { ...r, isVisible: a, onClose: t }), [o, r, a, t]);
111
- return w(() => ({
112
- isVisible: a,
112
+ k(!1), (l = r.current) == null || l.call(r, i), r.current = void 0;
113
+ }, []), u = I(() => /* @__PURE__ */ n.jsx(c, { ...s, isVisible: o, onClose: t }), [c, s, o, t]);
114
+ return I(() => ({
115
+ isVisible: o,
113
116
  show: x,
114
117
  modal: u
115
- }), [a, x, u]);
118
+ }), [o, x, u]);
116
119
  }
117
120
  export {
118
121
  ne as default,
119
- oe as useModal,
122
+ se as useModal,
120
123
  U as useModalContext
121
124
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakadu/components",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "description": "Kakadu components library",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",