@anoki/fse-ui
Version:
FSE UI components library
3 lines (2 loc) • 2.02 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./components/ui/ActionsPopup/ActionsPopup.css');const c=require("./index.cjs237.js"),a=require("react"),g=require("./index.cjs238.js");;/* empty css */const w=({isOpen:o=!1,onClickCloseBtn:i,className:p="",actions:f=[],children:x,parentRef:u})=>{const n=a.useRef(null),m=a.useRef(null),[d,v]=a.useState({top:"0.4rem",left:"-17rem",right:"auto"}),l=()=>{if(!n.current)return;const t=n.current.getBoundingClientRect(),r=window.innerWidth,s=window.innerHeight;let e={...d};if(u!=null&&u.current){const h=u.current.getBoundingClientRect();e={top:"1rem",left:"-2rem",right:"auto"},h.right+t.width-30>r&&(e={top:"1rem",left:"auto",right:"0"}),h.bottom+t.height>s&&(e.top=`-${t.height}px`)}else t.right>r&&(e.left="auto",e.right="0"),t.bottom>s&&(e.top=`-${t.height}px`);v(e)};return a.useEffect(()=>{var s;const t=e=>{e.key==="Escape"&&o&&(i==null||i())},r=e=>{n.current&&!n.current.contains(e.target)&&o&&(i==null||i())};return o?(m.current=document.activeElement,(s=n.current)==null||s.focus(),document.addEventListener("keydown",t),document.addEventListener("mousedown",r),l(),window.addEventListener("resize",l)):m.current&&m.current.focus(),()=>{document.removeEventListener("keydown",t),document.removeEventListener("mousedown",r),window.removeEventListener("resize",l)}},[o,i]),o?c.jsxRuntimeExports.jsx("div",{className:g.clsx("popupContainerActions",o?"open":"close",p),onClick:t=>{t.stopPropagation()},style:{position:"absolute",right:0},children:c.jsxRuntimeExports.jsx("div",{ref:n,role:"dialog","aria-modal":"true",className:g.clsx("dialogActions"),tabIndex:-1,style:{top:d.top,left:d.left,right:d.right},children:c.jsxRuntimeExports.jsxs("div",{className:"contentActions",children:[c.jsxRuntimeExports.jsx("ul",{className:"actionsList",children:f.map((t,r)=>c.jsxRuntimeExports.jsx("li",{className:"actionsListItem",children:t},r))}),x]})})}):null};exports.ActionsPopup=w;
//# sourceMappingURL=index.cjs20.js.map