UNPKG

@bothub-chat/ui

Version:

Bothub UI Components

2 lines (1 loc) 1.19 kB
import{__rest as e}from"tslib";import{jsx as r,jsxs as t}from"react/jsx-runtime";import{useState as n,useRef as i,useCallback as c,useEffect as o}from"react";import{useTransition as s}from"@react-spring/web";import{MenuIcon as l}from"../../icons/menu/index.js";import{CloseIcon as d}from"../../icons/close/index.js";import{MenuDropdownProvider as m}from"./context.js";import{MenuDropdownStyled as a,MenuDropdownToggleButton as p,MenuDropdownBlock as f,MenuDropdownBlockScrollbarWrapper as u,MenuDropdownBlockContent as h}from"./styled.js";const b=b=>{var{children:j,disabled:v=!1}=b,x=e(b,["children","disabled"]);const[y,g]=n(!1),k=i(null),O=c(()=>{g(!y)},[y]),E=y?d:l;o(()=>{const e=e=>{const r=k.current;null!==r&&(r.contains(e.target)||g(!1))};return document.addEventListener("click",e),()=>{document.removeEventListener("click",e)}},[]);const L=s(y,{from:{scale:.85,opacity:0},enter:{opacity:1,scale:1},leave:{scale:.85,opacity:0},config:{duration:135}});return r(m,{isOpen:y,setIsOpen:g,children:t(a,Object.assign({},x,{ref:k,children:[r(p,{disabled:v,onClick:O,children:r(E,{})}),L((e,t)=>t&&r(f,{style:e,children:r(u,{children:r(h,{children:j})})}))]}))})};export{b as MenuDropdown};