@sito/ui 0.3.2 → 0.3.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.
@@ -28,6 +28,9 @@ type DialogBaseProps = {
28
28
  mobileFullScreen?: boolean;
29
29
  containerClassName?: string;
30
30
  className?: string;
31
+ headerClassName?: string;
32
+ titleClassName?: string;
33
+ closeButtonClassName?: string;
31
34
  closeLabel?: string;
32
35
  closeIcon?: ReactNode;
33
36
  showCloseButton?: boolean;
@@ -17,3 +17,19 @@ export declare const getFocusableElements: (element: HTMLElement) => HTMLElement
17
17
  * @returns Active HTMLElement, or null when unavailable.
18
18
  */
19
19
  export declare const getActiveElement: () => HTMLElement | null;
20
+ /**
21
+ * Registers an interactive dialog as the topmost dialog.
22
+ * @param dialogStackId Stable internal identifier for the dialog instance.
23
+ */
24
+ export declare const registerDialog: (dialogStackId: symbol) => void;
25
+ /**
26
+ * Removes a dialog from the interactive dialog stack.
27
+ * @param dialogStackId Stable internal identifier for the dialog instance.
28
+ */
29
+ export declare const unregisterDialog: (dialogStackId: symbol) => void;
30
+ /**
31
+ * Checks whether a dialog is currently the topmost interactive dialog.
32
+ * @param dialogStackId Stable internal identifier for the dialog instance.
33
+ * @returns Whether the dialog is at the top of the stack.
34
+ */
35
+ export declare const isTopmostDialog: (dialogStackId: symbol) => boolean;
package/dist/ui.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime"),n=require("react-dom");var r=(...e)=>e.filter(Boolean).join(` `),i={DEFAULT:`default`,PRIMARY:`primary`,SECONDARY:`secondary`,ERROR:`error`,WARNING:`warning`,SUCCESS:`success`,INFO:`info`},a={TEXT:`text`,SUBMIT:`submit`,OUTLINED:`outlined`},o={SM:`sm`,MD:`md`,LG:`lg`},s=(0,e.forwardRef)(function(e,n){let{color:s=i.DEFAULT,size:c=o.MD,type:l=`button`,variant:u=a.TEXT,loading:d=!1,loadingIndicator:f,loadingLabel:p=`Loading`,disabled:m,className:h,children:g,..._}=e,v=r(`sito-ui-button`,`sito-ui-button--${u}`,`sito-ui-button--${s}`,`sito-ui-button--${c}`,d&&`sito-ui-button--loading`,h),y=f===void 0?(0,t.jsx)(`span`,{className:`sito-ui-button__spinner`,"aria-hidden":`true`,"data-sito-ui":`button-spinner`}):f;return(0,t.jsxs)(`button`,{"data-sito-ui":`button`,..._,type:l,ref:n,disabled:m||d,"aria-busy":d||_[`aria-busy`],className:v,children:[d?(0,t.jsxs)(t.Fragment,{children:[y,(0,t.jsx)(`span`,{className:`sito-ui-button__loading-label`,children:p})]}):null,g]})}),c={SM:`sm`,MD:`md`,LG:`lg`},l=e=>{if(e!==void 0)return typeof e==`number`?`${e}px`:e},u=(0,e.forwardRef)(function(e,n){let{children:i,icon:a,iconClassName:o,type:u=`button`,variant:d=`text`,color:f=`default`,loading:p=!1,size:m=c.MD,iconSize:h,className:g,style:_,...v}=e,y=i!=null&&typeof i!=`boolean`,b=l(h),x=b===void 0?_:{..._,"--sito-ui-icon-button-icon-size":b},S=r(`sito-ui-icon-button`,`sito-ui-icon-button--${m}`,y&&`sito-ui-icon-button--with-content`,g);return(0,t.jsxs)(s,{...v,ref:n,type:u,variant:d,color:f,size:m,loading:p,"data-sito-ui":`icon-button`,className:S,style:x,children:[p?null:(0,t.jsx)(`span`,{className:r(`sito-ui-icon-button__icon`,o),"aria-hidden":`true`,children:a}),i]})}),d=`input:not([type="hidden"]):not([disabled]), textarea:not([disabled]), select:not([disabled])`,f=`button[type="submit"]:not([disabled]), input[type="submit"]:not([disabled])`,p=[`a[href]`,`button:not([disabled])`,`textarea:not([disabled])`,`input:not([disabled])`,`select:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`),m=0,h=null,g=()=>typeof document<`u`&&!!document.body,_=()=>{g()&&(m===0&&(h=document.body.style.overflow,document.body.style.overflow=`hidden`),m+=1)},v=()=>{!g()||m===0||(--m,m===0&&(document.body.style.overflow=h??``,h=null))},y=e=>Array.from(e.querySelectorAll(p)).filter(e=>e.getAttribute(`aria-disabled`)!==`true`),b=()=>typeof document>`u`?null:document.activeElement instanceof HTMLElement?document.activeElement:null,x=typeof window>`u`?e.useEffect:e.useLayoutEffect,S=i=>{let a=(0,e.useId)(),o=(0,e.useRef)(null),s=(0,e.useRef)(null),c=(0,e.useRef)(null),l=(0,e.useRef)(void 0),{dialogId:p,title:m,ariaLabel:h,children:g,onClose:S,initialFocus:C=`none`,closeOnBackdropClick:w=!1,closeOnEscape:T=!0,lockBodyScroll:E=!0,onSubmit:D,open:O=!1,mobileFullScreen:k=!1,containerClassName:A,className:j,closeLabel:M=`Close dialog`,closeIcon:N=`x`,showCloseButton:P=!0,portalContainer:F,exitDurationMs:I=0,onExitComplete:L}=i,[R,z]=(0,e.useState)(O),[B,V]=(0,e.useState)(!1),H=m?`${p??a}-title`:void 0,U=B?`closing`:`open`,W=O&&!B;(0,e.useEffect)(()=>{l.current=L},[L]);let G=(0,e.useCallback)(()=>{c.current!==null&&(window.clearTimeout(c.current),c.current=null)},[]),K=(0,e.useCallback)(()=>{z(!1),V(!1),l.current?.(),c.current=null},[]);x(()=>{if(O){G(),z(!0),V(!1);return}if(!R)return;let e=Math.max(0,I);if(e===0){G(),K();return}V(!0),G(),c.current=window.setTimeout(K,e)},[G,I,K,O,R]),(0,e.useEffect)(()=>()=>{G()},[G]);let q=(0,e.useCallback)(e=>{if(e.key===`Escape`&&W&&T){S();return}if(e.key!==`Tab`||!W)return;let t=o.current;if(!t)return;let n=y(t);if(n.length===0){e.preventDefault(),t.focus();return}let r=n[0],i=n[n.length-1],a=b(),s=!a||!t.contains(a);if(e.shiftKey&&(s||a===r)){e.preventDefault(),i.focus();return}!e.shiftKey&&(s||a===i)&&(e.preventDefault(),r.focus())},[T,W,S]);(0,e.useEffect)(()=>{if(!(!W||typeof window>`u`))return window.addEventListener(`keydown`,q),()=>{window.removeEventListener(`keydown`,q)}},[q,W]),x(()=>{if(O)return s.current=b(),()=>{s.current?.isConnected&&s.current.focus(),s.current=null}},[O]),x(()=>{if(!O)return;let e=o.current;if(e){if(C===`first-input`){let t=e.querySelector(d);if(t){t.focus();return}}if(C===`submit`){let t=e.querySelector(f);if(t){t.focus();return}}e.focus()}},[C,O]),(0,e.useEffect)(()=>{if(!(!R||!E))return _(),()=>{v()}},[E,R]);let J=(0,e.useCallback)(e=>{W&&w&&e.target===e.currentTarget&&S()},[w,W,S]),Y=(0,e.useCallback)(e=>{e.preventDefault(),D?.(e)},[D]);if(!R||typeof document>`u`)return null;let X=D?(0,t.jsx)(`form`,{onSubmit:Y,children:g}):g,Z=typeof N==`string`?(0,t.jsx)(`span`,{"aria-hidden":`true`,children:N}):N;return(0,n.createPortal)((0,t.jsx)(`div`,{id:p?`backdrop-${p}`:void 0,"data-sito-ui":`dialog-backdrop`,"data-state":U,onClick:J,className:r(`sito-ui-dialog-backdrop`,`sito-ui-dialog-backdrop--${U}`,A),children:(0,t.jsxs)(`div`,{id:p,ref:o,role:`dialog`,"aria-modal":`true`,"aria-label":m?void 0:h,"aria-labelledby":H,tabIndex:-1,"data-sito-ui":`dialog`,"data-state":U,className:r(`sito-ui-dialog`,`sito-ui-dialog--${U}`,k&&`sito-ui-dialog--mobile-full-screen`,j),children:[(0,t.jsxs)(`div`,{className:`sito-ui-dialog__header`,children:[m?(0,t.jsx)(`h3`,{id:H,className:`sito-ui-dialog__title`,children:m}):null,P?(0,t.jsx)(u,{icon:Z,disabled:!W,"aria-disabled":!W,onClick:S,variant:`text`,color:`error`,className:`sito-ui-dialog__close`,"aria-label":M}):null]}),X]})}),F??document.body)},C=e=>{let{primaryText:n,cancelText:i,onPrimaryClick:a,onCancel:o,isLoading:c=!1,loadingIndicator:l,disabled:u=!1,primaryType:d=`submit`,containerClassName:f,primaryClassName:p,cancelClassName:m,alignEnd:h=!1,primaryName:g,primaryAriaLabel:_,cancelName:v,cancelAriaLabel:y,extraActions:b=[]}=e;return(0,t.jsxs)(`div`,{"data-sito-ui":`dialog-actions`,className:r(`sito-ui-dialog-actions`,h&&`sito-ui-dialog-actions--end`,f),children:[(0,t.jsx)(s,{type:d,color:`primary`,variant:`submit`,className:p,disabled:u,loading:c,loadingIndicator:l,onClick:a,name:g,"aria-label":_,children:n}),b.map(({id:e,...n})=>(0,t.jsx)(s,{...n},e)),(0,t.jsx)(s,{type:`button`,variant:`outlined`,className:m,disabled:u||c,onClick:o,name:v,"aria-label":y,children:i})]})},w=(t=!1)=>{let[n,r]=(0,e.useState)(t);return{open:n,setOpen:r,handleClose:()=>r(!1),handleOpen:()=>r(!0)}};exports.Button=s,exports.Dialog=S,exports.DialogActions=C,exports.IconButton=u,exports.useDialog=w;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime"),n=require("react-dom");var r=(...e)=>e.filter(Boolean).join(` `),i={DEFAULT:`default`,PRIMARY:`primary`,SECONDARY:`secondary`,ERROR:`error`,WARNING:`warning`,SUCCESS:`success`,INFO:`info`},a={TEXT:`text`,SUBMIT:`submit`,OUTLINED:`outlined`},o={SM:`sm`,MD:`md`,LG:`lg`},s=(0,e.forwardRef)(function(e,n){let{color:s=i.DEFAULT,size:c=o.MD,type:l=`button`,variant:u=a.TEXT,loading:d=!1,loadingIndicator:f,loadingLabel:p=`Loading`,disabled:m,className:h,children:g,..._}=e,v=r(`sito-ui-button`,`sito-ui-button--${u}`,`sito-ui-button--${s}`,`sito-ui-button--${c}`,d&&`sito-ui-button--loading`,h),y=f===void 0?(0,t.jsx)(`span`,{className:`sito-ui-button__spinner`,"aria-hidden":`true`,"data-sito-ui":`button-spinner`}):f;return(0,t.jsxs)(`button`,{"data-sito-ui":`button`,..._,type:l,ref:n,disabled:m||d,"aria-busy":d||_[`aria-busy`],className:v,children:[d?(0,t.jsxs)(t.Fragment,{children:[y,(0,t.jsx)(`span`,{className:`sito-ui-button__loading-label`,children:p})]}):null,g]})}),c={SM:`sm`,MD:`md`,LG:`lg`},l=e=>{if(e!==void 0)return typeof e==`number`?`${e}px`:e},u=(0,e.forwardRef)(function(e,n){let{children:i,icon:a,iconClassName:o,type:u=`button`,variant:d=`text`,color:f=`default`,loading:p=!1,size:m=c.MD,iconSize:h,className:g,style:_,...v}=e,y=i!=null&&typeof i!=`boolean`,b=l(h),x=b===void 0?_:{..._,"--sito-ui-icon-button-icon-size":b},S=r(`sito-ui-icon-button`,`sito-ui-icon-button--${m}`,y&&`sito-ui-icon-button--with-content`,g);return(0,t.jsxs)(s,{...v,ref:n,type:u,variant:d,color:f,size:m,loading:p,"data-sito-ui":`icon-button`,className:S,style:x,children:[p?null:(0,t.jsx)(`span`,{className:r(`sito-ui-icon-button__icon`,o),"aria-hidden":`true`,children:a}),i]})}),d=`input:not([type="hidden"]):not([disabled]), textarea:not([disabled]), select:not([disabled])`,f=`button[type="submit"]:not([disabled]), input[type="submit"]:not([disabled])`,p=[`a[href]`,`button:not([disabled])`,`textarea:not([disabled])`,`input:not([disabled])`,`select:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`),m=0,h=null,g=[],_=()=>typeof document<`u`&&!!document.body,v=()=>{_()&&(m===0&&(h=document.body.style.overflow,document.body.style.overflow=`hidden`),m+=1)},y=()=>{!_()||m===0||(--m,m===0&&(document.body.style.overflow=h??``,h=null))},b=e=>Array.from(e.querySelectorAll(p)).filter(e=>e.getAttribute(`aria-disabled`)!==`true`),x=()=>typeof document>`u`?null:document.activeElement instanceof HTMLElement?document.activeElement:null,S=e=>{let t=g.indexOf(e);t>=0&&g.splice(t,1),g.push(e)},ee=e=>{let t=g.indexOf(e);t>=0&&g.splice(t,1)},C=e=>g[g.length-1]===e,w=typeof window>`u`?e.useEffect:e.useLayoutEffect,T=i=>{let a=(0,e.useId)(),o=(0,e.useRef)(Symbol(`sito-ui-dialog`)),s=(0,e.useRef)(null),c=(0,e.useRef)(null),l=(0,e.useRef)(null),p=(0,e.useRef)(void 0),{dialogId:m,title:h,ariaLabel:g,children:_,onClose:T,initialFocus:E=`none`,closeOnBackdropClick:D=!1,closeOnEscape:O=!0,lockBodyScroll:k=!0,onSubmit:A,open:j=!1,mobileFullScreen:M=!1,containerClassName:N,className:P,headerClassName:F,titleClassName:I,closeButtonClassName:L,closeLabel:R=`Close dialog`,closeIcon:z=`x`,showCloseButton:B=!0,portalContainer:te,exitDurationMs:V=0,onExitComplete:H}=i,[U,W]=(0,e.useState)(j),[G,K]=(0,e.useState)(!1),q=h?`${m??a}-title`:void 0,J=G?`closing`:`open`,Y=j&&!G,X=o.current;(0,e.useEffect)(()=>{p.current=H},[H]);let Z=(0,e.useCallback)(()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},[]),Q=(0,e.useCallback)(()=>{W(!1),K(!1),p.current?.(),l.current=null},[]);w(()=>{if(j){Z(),W(!0),K(!1);return}if(!U)return;let e=Math.max(0,V);if(e===0){Z(),Q();return}K(!0),Z(),l.current=window.setTimeout(Q,e)},[Z,V,Q,j,U]),(0,e.useEffect)(()=>()=>{Z()},[Z]);let $=(0,e.useCallback)(e=>{if(!C(X))return;if(e.key===`Escape`&&Y&&O){T();return}if(e.key!==`Tab`||!Y)return;let t=s.current;if(!t)return;let n=b(t);if(n.length===0){e.preventDefault(),t.focus();return}let r=n[0],i=n[n.length-1],a=x(),o=!a||!t.contains(a);if(e.shiftKey&&(o||a===r)){e.preventDefault(),i.focus();return}!e.shiftKey&&(o||a===i)&&(e.preventDefault(),r.focus())},[O,X,Y,T]);(0,e.useEffect)(()=>{if(!(!Y||typeof window>`u`))return window.addEventListener(`keydown`,$),()=>{window.removeEventListener(`keydown`,$)}},[$,Y]),w(()=>{if(j)return c.current=x(),S(X),()=>{let e=C(X);ee(X),e&&c.current?.isConnected&&c.current.focus(),c.current=null}},[X,j]),w(()=>{if(!j)return;let e=s.current;if(e){if(E===`first-input`){let t=e.querySelector(d);if(t){t.focus();return}}if(E===`submit`){let t=e.querySelector(f);if(t){t.focus();return}}e.focus()}},[E,j]),(0,e.useEffect)(()=>{if(!(!U||!k))return v(),()=>{y()}},[k,U]);let ne=(0,e.useCallback)(e=>{C(X)&&Y&&D&&e.target===e.currentTarget&&T()},[D,X,Y,T]),re=(0,e.useCallback)(e=>{e.preventDefault(),A?.(e)},[A]);if(!U||typeof document>`u`)return null;let ie=A?(0,t.jsx)(`form`,{onSubmit:re,children:_}):_,ae=typeof z==`string`?(0,t.jsx)(`span`,{"aria-hidden":`true`,children:z}):z;return(0,n.createPortal)((0,t.jsx)(`div`,{id:m?`backdrop-${m}`:void 0,"data-sito-ui":`dialog-backdrop`,"data-state":J,onClick:ne,className:r(`sito-ui-dialog-backdrop`,`sito-ui-dialog-backdrop--${J}`,N),children:(0,t.jsxs)(`div`,{id:m,ref:s,role:`dialog`,"aria-modal":`true`,"aria-label":h?void 0:g,"aria-labelledby":q,tabIndex:-1,"data-sito-ui":`dialog`,"data-state":J,className:r(`sito-ui-dialog`,`sito-ui-dialog--${J}`,M&&`sito-ui-dialog--mobile-full-screen`,P),children:[(0,t.jsxs)(`div`,{className:r(`sito-ui-dialog__header`,F),children:[h?(0,t.jsx)(`h3`,{id:q,className:r(`sito-ui-dialog__title`,I),children:h}):null,B?(0,t.jsx)(u,{icon:ae,disabled:!Y,"aria-disabled":!Y,onClick:T,variant:`text`,color:`error`,className:r(`sito-ui-dialog__close`,L),"aria-label":R}):null]}),ie]})}),te??document.body)},E=e=>{let{primaryText:n,cancelText:i,onPrimaryClick:a,onCancel:o,isLoading:c=!1,loadingIndicator:l,disabled:u=!1,primaryType:d=`submit`,containerClassName:f,primaryClassName:p,cancelClassName:m,alignEnd:h=!1,primaryName:g,primaryAriaLabel:_,cancelName:v,cancelAriaLabel:y,extraActions:b=[]}=e;return(0,t.jsxs)(`div`,{"data-sito-ui":`dialog-actions`,className:r(`sito-ui-dialog-actions`,h&&`sito-ui-dialog-actions--end`,f),children:[(0,t.jsx)(s,{type:d,color:`primary`,variant:`submit`,className:p,disabled:u,loading:c,loadingIndicator:l,onClick:a,name:g,"aria-label":_,children:n}),b.map(({id:e,...n})=>(0,t.jsx)(s,{...n},e)),(0,t.jsx)(s,{type:`button`,variant:`outlined`,className:m,disabled:u||c,onClick:o,name:v,"aria-label":y,children:i})]})},D=(t=!1)=>{let[n,r]=(0,e.useState)(t);return{open:n,setOpen:r,handleClose:()=>r(!1),handleOpen:()=>r(!0)}};exports.Button=s,exports.Dialog=T,exports.DialogActions=E,exports.IconButton=u,exports.useDialog=D;
package/dist/ui.js CHANGED
@@ -72,50 +72,57 @@ var d = (...e) => e.filter(Boolean).join(" "), f = {
72
72
  "input:not([disabled])",
73
73
  "select:not([disabled])",
74
74
  "[tabindex]:not([tabindex=\"-1\"])"
75
- ].join(","), S = 0, C = null, w = () => typeof document < "u" && !!document.body, T = () => {
76
- w() && (S === 0 && (C = document.body.style.overflow, document.body.style.overflow = "hidden"), S += 1);
77
- }, E = () => {
78
- !w() || S === 0 || (--S, S === 0 && (document.body.style.overflow = C ?? "", C = null));
79
- }, D = (e) => Array.from(e.querySelectorAll(x)).filter((e) => e.getAttribute("aria-disabled") !== "true"), O = () => typeof document > "u" ? null : document.activeElement instanceof HTMLElement ? document.activeElement : null, k = typeof window > "u" ? n : i, A = (e) => {
80
- let i = r(), s = a(null), f = a(null), p = a(null), m = a(void 0), { dialogId: h, title: g, ariaLabel: _, children: x, onClose: S, initialFocus: C = "none", closeOnBackdropClick: w = !1, closeOnEscape: A = !0, lockBodyScroll: j = !0, onSubmit: M, open: N = !1, mobileFullScreen: P = !1, containerClassName: F, className: I, closeLabel: L = "Close dialog", closeIcon: R = "x", showCloseButton: z = !0, portalContainer: B, exitDurationMs: V = 0, onExitComplete: H } = e, [U, W] = o(N), [G, K] = o(!1), q = g ? `${h ?? i}-title` : void 0, J = G ? "closing" : "open", Y = N && !G;
75
+ ].join(","), S = 0, C = null, w = [], T = () => typeof document < "u" && !!document.body, E = () => {
76
+ T() && (S === 0 && (C = document.body.style.overflow, document.body.style.overflow = "hidden"), S += 1);
77
+ }, D = () => {
78
+ !T() || S === 0 || (--S, S === 0 && (document.body.style.overflow = C ?? "", C = null));
79
+ }, ee = (e) => Array.from(e.querySelectorAll(x)).filter((e) => e.getAttribute("aria-disabled") !== "true"), O = () => typeof document > "u" ? null : document.activeElement instanceof HTMLElement ? document.activeElement : null, te = (e) => {
80
+ let t = w.indexOf(e);
81
+ t >= 0 && w.splice(t, 1), w.push(e);
82
+ }, ne = (e) => {
83
+ let t = w.indexOf(e);
84
+ t >= 0 && w.splice(t, 1);
85
+ }, k = (e) => w[w.length - 1] === e, A = typeof window > "u" ? n : i, j = (e) => {
86
+ let i = r(), s = a(Symbol("sito-ui-dialog")), f = a(null), p = a(null), m = a(null), h = a(void 0), { dialogId: g, title: _, ariaLabel: x, children: S, onClose: C, initialFocus: w = "none", closeOnBackdropClick: T = !1, closeOnEscape: j = !0, lockBodyScroll: M = !0, onSubmit: N, open: P = !1, mobileFullScreen: F = !1, containerClassName: I, className: L, headerClassName: R, titleClassName: z, closeButtonClassName: re, closeLabel: ie = "Close dialog", closeIcon: B = "x", showCloseButton: ae = !0, portalContainer: oe, exitDurationMs: V = 0, onExitComplete: H } = e, [U, W] = o(P), [G, K] = o(!1), q = _ ? `${g ?? i}-title` : void 0, J = G ? "closing" : "open", Y = P && !G, X = s.current;
81
87
  n(() => {
82
- m.current = H;
88
+ h.current = H;
83
89
  }, [H]);
84
- let X = t(() => {
85
- p.current !== null && (window.clearTimeout(p.current), p.current = null);
86
- }, []), Z = t(() => {
87
- W(!1), K(!1), m.current?.(), p.current = null;
90
+ let Z = t(() => {
91
+ m.current !== null && (window.clearTimeout(m.current), m.current = null);
92
+ }, []), Q = t(() => {
93
+ W(!1), K(!1), h.current?.(), m.current = null;
88
94
  }, []);
89
- k(() => {
90
- if (N) {
91
- X(), W(!0), K(!1);
95
+ A(() => {
96
+ if (P) {
97
+ Z(), W(!0), K(!1);
92
98
  return;
93
99
  }
94
100
  if (!U) return;
95
101
  let e = Math.max(0, V);
96
102
  if (e === 0) {
97
- X(), Z();
103
+ Z(), Q();
98
104
  return;
99
105
  }
100
- K(!0), X(), p.current = window.setTimeout(Z, e);
106
+ K(!0), Z(), m.current = window.setTimeout(Q, e);
101
107
  }, [
102
- X,
103
- V,
104
108
  Z,
105
- N,
109
+ V,
110
+ Q,
111
+ P,
106
112
  U
107
113
  ]), n(() => () => {
108
- X();
109
- }, [X]);
110
- let Q = t((e) => {
111
- if (e.key === "Escape" && Y && A) {
112
- S();
114
+ Z();
115
+ }, [Z]);
116
+ let $ = t((e) => {
117
+ if (!k(X)) return;
118
+ if (e.key === "Escape" && Y && j) {
119
+ C();
113
120
  return;
114
121
  }
115
122
  if (e.key !== "Tab" || !Y) return;
116
- let t = s.current;
123
+ let t = f.current;
117
124
  if (!t) return;
118
- let n = D(t);
125
+ let n = ee(t);
119
126
  if (n.length === 0) {
120
127
  e.preventDefault(), t.focus();
121
128
  return;
@@ -127,30 +134,32 @@ var d = (...e) => e.filter(Boolean).join(" "), f = {
127
134
  }
128
135
  !e.shiftKey && (o || a === i) && (e.preventDefault(), r.focus());
129
136
  }, [
130
- A,
137
+ j,
138
+ X,
131
139
  Y,
132
- S
140
+ C
133
141
  ]);
134
142
  n(() => {
135
- if (!(!Y || typeof window > "u")) return window.addEventListener("keydown", Q), () => {
136
- window.removeEventListener("keydown", Q);
143
+ if (!(!Y || typeof window > "u")) return window.addEventListener("keydown", $), () => {
144
+ window.removeEventListener("keydown", $);
137
145
  };
138
- }, [Q, Y]), k(() => {
139
- if (N) return f.current = O(), () => {
140
- f.current?.isConnected && f.current.focus(), f.current = null;
146
+ }, [$, Y]), A(() => {
147
+ if (P) return p.current = O(), te(X), () => {
148
+ let e = k(X);
149
+ ne(X), e && p.current?.isConnected && p.current.focus(), p.current = null;
141
150
  };
142
- }, [N]), k(() => {
143
- if (!N) return;
144
- let e = s.current;
151
+ }, [X, P]), A(() => {
152
+ if (!P) return;
153
+ let e = f.current;
145
154
  if (e) {
146
- if (C === "first-input") {
155
+ if (w === "first-input") {
147
156
  let t = e.querySelector(y);
148
157
  if (t) {
149
158
  t.focus();
150
159
  return;
151
160
  }
152
161
  }
153
- if (C === "submit") {
162
+ if (w === "submit") {
154
163
  let t = e.querySelector(b);
155
164
  if (t) {
156
165
  t.focus();
@@ -159,65 +168,66 @@ var d = (...e) => e.filter(Boolean).join(" "), f = {
159
168
  }
160
169
  e.focus();
161
170
  }
162
- }, [C, N]), n(() => {
163
- if (!(!U || !j)) return T(), () => {
164
- E();
171
+ }, [w, P]), n(() => {
172
+ if (!(!U || !M)) return E(), () => {
173
+ D();
165
174
  };
166
- }, [j, U]);
167
- let $ = t((e) => {
168
- Y && w && e.target === e.currentTarget && S();
175
+ }, [M, U]);
176
+ let se = t((e) => {
177
+ k(X) && Y && T && e.target === e.currentTarget && C();
169
178
  }, [
170
- w,
179
+ T,
180
+ X,
171
181
  Y,
172
- S
173
- ]), ee = t((e) => {
174
- e.preventDefault(), M?.(e);
175
- }, [M]);
182
+ C
183
+ ]), ce = t((e) => {
184
+ e.preventDefault(), N?.(e);
185
+ }, [N]);
176
186
  if (!U || typeof document > "u") return null;
177
- let te = M ? /* @__PURE__ */ c("form", {
178
- onSubmit: ee,
179
- children: x
180
- }) : x, ne = typeof R == "string" ? /* @__PURE__ */ c("span", {
187
+ let le = N ? /* @__PURE__ */ c("form", {
188
+ onSubmit: ce,
189
+ children: S
190
+ }) : S, ue = typeof B == "string" ? /* @__PURE__ */ c("span", {
181
191
  "aria-hidden": "true",
182
- children: R
183
- }) : R;
192
+ children: B
193
+ }) : B;
184
194
  return u(/* @__PURE__ */ c("div", {
185
- id: h ? `backdrop-${h}` : void 0,
195
+ id: g ? `backdrop-${g}` : void 0,
186
196
  "data-sito-ui": "dialog-backdrop",
187
197
  "data-state": J,
188
- onClick: $,
189
- className: d("sito-ui-dialog-backdrop", `sito-ui-dialog-backdrop--${J}`, F),
198
+ onClick: se,
199
+ className: d("sito-ui-dialog-backdrop", `sito-ui-dialog-backdrop--${J}`, I),
190
200
  children: /* @__PURE__ */ l("div", {
191
- id: h,
192
- ref: s,
201
+ id: g,
202
+ ref: f,
193
203
  role: "dialog",
194
204
  "aria-modal": "true",
195
- "aria-label": g ? void 0 : _,
205
+ "aria-label": _ ? void 0 : x,
196
206
  "aria-labelledby": q,
197
207
  tabIndex: -1,
198
208
  "data-sito-ui": "dialog",
199
209
  "data-state": J,
200
- className: d("sito-ui-dialog", `sito-ui-dialog--${J}`, P && "sito-ui-dialog--mobile-full-screen", I),
210
+ className: d("sito-ui-dialog", `sito-ui-dialog--${J}`, F && "sito-ui-dialog--mobile-full-screen", L),
201
211
  children: [/* @__PURE__ */ l("div", {
202
- className: "sito-ui-dialog__header",
203
- children: [g ? /* @__PURE__ */ c("h3", {
212
+ className: d("sito-ui-dialog__header", R),
213
+ children: [_ ? /* @__PURE__ */ c("h3", {
204
214
  id: q,
205
- className: "sito-ui-dialog__title",
206
- children: g
207
- }) : null, z ? /* @__PURE__ */ c(v, {
208
- icon: ne,
215
+ className: d("sito-ui-dialog__title", z),
216
+ children: _
217
+ }) : null, ae ? /* @__PURE__ */ c(v, {
218
+ icon: ue,
209
219
  disabled: !Y,
210
220
  "aria-disabled": !Y,
211
- onClick: S,
221
+ onClick: C,
212
222
  variant: "text",
213
223
  color: "error",
214
- className: "sito-ui-dialog__close",
215
- "aria-label": L
224
+ className: d("sito-ui-dialog__close", re),
225
+ "aria-label": ie
216
226
  }) : null]
217
- }), te]
227
+ }), le]
218
228
  })
219
- }), B ?? document.body);
220
- }, j = (e) => {
229
+ }), oe ?? document.body);
230
+ }, M = (e) => {
221
231
  let { primaryText: t, cancelText: n, onPrimaryClick: r, onCancel: i, isLoading: a = !1, loadingIndicator: o, disabled: s = !1, primaryType: u = "submit", containerClassName: f, primaryClassName: p, cancelClassName: m, alignEnd: g = !1, primaryName: _, primaryAriaLabel: v, cancelName: y, cancelAriaLabel: b, extraActions: x = [] } = e;
222
232
  return /* @__PURE__ */ l("div", {
223
233
  "data-sito-ui": "dialog-actions",
@@ -249,7 +259,7 @@ var d = (...e) => e.filter(Boolean).join(" "), f = {
249
259
  })
250
260
  ]
251
261
  });
252
- }, M = (e = !1) => {
262
+ }, N = (e = !1) => {
253
263
  let [t, n] = o(e);
254
264
  return {
255
265
  open: t,
@@ -259,4 +269,4 @@ var d = (...e) => e.filter(Boolean).join(" "), f = {
259
269
  };
260
270
  };
261
271
  //#endregion
262
- export { h as Button, A as Dialog, j as DialogActions, v as IconButton, M as useDialog };
272
+ export { h as Button, j as Dialog, M as DialogActions, v as IconButton, N as useDialog };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sito/ui",
3
3
  "private": false,
4
- "version": "0.3.2",
4
+ "version": "0.3.3",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@10.34.4",
7
7
  "files": [