UNPKG

@bothub-chat/ui

Version:

Bothub UI Components

2 lines (1 loc) 1.33 kB
import{jsxs as e,Fragment as o,jsx as n}from"react/jsx-runtime";import{useState as r,useRef as l,useEffect as t}from"react";import{createPortal as c}from"react-dom";import{Overlay as d,Component as i,Header as s,Title as u,CloseButton as m,Content as a}from"./styled.js";import{CloseIcon as p}from"../../icons/close/index.js";const v=({title:v,open:y,onClose:L,children:f})=>{const[h,k]=r(!1),[b,w]=r(!1),x=l(null),_=l(null);t((()=>{h||k(!0)}),[h]),t((()=>{const e=e=>{"Escape"===e.key&&w(!1)};return window.addEventListener("keyup",e),()=>{window.removeEventListener("keyup",e)}}),[]),t((()=>{w(y)}),[y]),t((()=>{var e,o,n,r;let l=null;return b?(null===(e=_.current)||void 0===e||e.classList.add("_opened"),null===(o=x.current)||void 0===o||o.classList.add("_opened"),document.body.classList.add("lock-scroll")):(null===(n=_.current)||void 0===n||n.classList.remove("_opened"),null===(r=x.current)||void 0===r||r.classList.remove("_opened"),document.body.classList.remove("lock-scroll"),l=setTimeout((()=>{null==L||L()}),200)),()=>{l&&clearTimeout(l)}}),[b,L]);const j=()=>{w(!1)};return y?c(e(o,{children:[n(d,{ref:x,onClick:j}),e(i,{ref:_,children:[e(s,{children:[v&&n(u,{variant:"body-xl-semibold",children:v}),n(m,{onClick:j,type:"button",children:n(p,{})})]}),n(a,{children:f})]})]}),document.body):null};export{v as Drawer};