3 lines
1.9 KiB
JavaScript
3 lines
1.9 KiB
JavaScript
import{r as l,av as N,j as t,I as g}from"./index-BTPmxtwM.js";let c=0;function w(){c+=1,document.body.style.overflow="hidden"}function R(){c=Math.max(0,c-1),c===0&&(document.body.style.overflow="")}const j='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function L({open:d=!0,title:i,subtitle:u,size:p,footer:f,onClose:s,children:E}){const m=l.useRef(null),x=l.useRef(null),n=l.useCallback(()=>s==null?void 0:s(),[s]);return l.useEffect(()=>{var a,b;if(!d)return;x.current=document.activeElement,w();const r=m.current;(b=(a=(r==null?void 0:r.querySelector(j))??r)==null?void 0:a.focus)==null||b.call(a);const v=e=>{if(e.key==="Escape"){e.stopPropagation(),n();return}if(e.key!=="Tab"||!r)return;const o=Array.from(r.querySelectorAll(j)).filter(k=>k.offsetParent!==null);if(!o.length)return;const h=o[0],y=o[o.length-1];e.shiftKey&&document.activeElement===h?(e.preventDefault(),y.focus()):!e.shiftKey&&document.activeElement===y&&(e.preventDefault(),h.focus())};return document.addEventListener("keydown",v,!0),()=>{var e,o;document.removeEventListener("keydown",v,!0),R(),(o=(e=x.current)==null?void 0:e.focus)==null||o.call(e)}},[d,n]),d?N.createPortal(t.jsxs("div",{className:"modal-root open",children:[t.jsx("div",{className:"modal-backdrop",onClick:n}),t.jsxs("div",{className:`modal ${p||""}`,role:"dialog","aria-modal":"true","aria-label":typeof i=="string"?i:void 0,tabIndex:-1,ref:m,children:[t.jsxs("div",{className:"modal-head",children:[t.jsxs("div",{children:[t.jsx("h2",{children:i}),u&&t.jsx("p",{children:u})]}),t.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:t.jsx(g,{name:"x"})})]}),t.jsx("div",{className:"modal-body",children:E}),f&&t.jsx("div",{className:"modal-foot",children:f})]})]}),document.body):null}export{L as M};
|
|
//# sourceMappingURL=Modal-B8aWFZt2.js.map
|