import{j as r,r as e}from"./iframe-p4aYZyoq.js";import{c as h}from"./index-Dx18ixSn.js";import{B as x}from"./button-BsNF7f-b.js";/* empty css                 */const k=({children:n,label:u,className:p,openOnHover:c=!1,...l})=>{const[a,s]=e.useState(!1),[i,m]=e.useState(),t=e.useRef(null),f=e.useRef(null),d=typeof n;e.useEffect(()=>{if(!a)return;const o=v=>{var y,b,g;!t.current||(b=(y=t.current)==null?void 0:y.parentElement)!=null&&b.contains(v.target)||d==="function"&&((g=f.current)!=null&&g.contains(v.target))||s(!1)};return window.document.addEventListener("mouseup",o),window.document.addEventListener("touchend",o),()=>{window.document.removeEventListener("mouseup",o),window.document.removeEventListener("touchend",o)}},[a,d]),e.useEffect(()=>{t.current&&a&&m(t.current.getBoundingClientRect())},[a]);const w=e.useMemo(()=>{if(!i)return;const o=window.innerHeight-i.bottom;return{top:i.height,maxHeight:o}},[i]);return r.jsxs("div",{className:"dropdown-container",onPointerEnter:c?()=>s(!0):void 0,onPointerLeave:c?()=>s(!1):void 0,children:[r.jsx(x,{className:h("dropdown",p),onClick:()=>s(o=>!o),ref:t,...l,children:u}),r.jsx("div",{className:h("dropdown-menu",{"dropdown-menu-open":a}),ref:f,style:w,children:a&&(typeof n=="function"?n(s):n)})]})},_=({visibleElement:n,expanded:u,children:p,className:c,"aria-haspopup":l,...a})=>r.jsxs("div",{className:h(c,"dropdown"),...a,"aria-expanded":u,"aria-haspopup":l||!0,children:[r.jsx(e.Fragment,{children:n},"visible"),r.jsx(e.Fragment,{children:u&&r.jsx("div",{className:"dropdown__content",children:p})},"content")]}),E=({visibleElement:n,propChangeToClose:u,className:p,"aria-haspopup":c,children:l,...a})=>{const[s,i]=e.useState(!1),m=e.useRef(null),t=e.useCallback(()=>i(!1),[]);e.useEffect(()=>{t()},[t,u]),e.useEffect(()=>{if(!s)return;const d=w=>{var o;!m.current||w.target&&((o=m.current)!=null&&o.contains(w.target))||t()};return window.document.addEventListener("mouseup",d,{passive:!0}),window.document.addEventListener("touchend",d,{passive:!0}),()=>{window.document.removeEventListener("mouseup",d),window.document.removeEventListener("touchend",d)}},[t,s]);const f=e.useCallback(()=>i(d=>!d),[]);return r.jsxs("div",{className:h(p,"dropdown"),...a,"aria-expanded":s,"aria-haspopup":c||!0,ref:m,children:[r.jsx(e.Fragment,{children:n(f)},"visible"),r.jsx(e.Fragment,{children:s&&r.jsx("div",{className:"dropdown__content",children:typeof l=="function"?l(t):l})},"content")]})};try{_.displayName="ControlledDropdown",_.__docgenInfo={description:"",displayName:"ControlledDropdown",props:{visibleElement:{defaultValue:null,description:"Element always visible used to open and close the dropdown",name:"visibleElement",required:!0,type:{name:"ReactElement<unknown, string | JSXElementConstructor<any>>"}},expanded:{defaultValue:null,description:"Whether the dropdown is open or closed",name:"expanded",required:!0,type:{name:"boolean"}}}}}catch{}try{E.displayName="Dropdown",E.__docgenInfo={description:"",displayName:"Dropdown",props:{propChangeToClose:{defaultValue:null,description:"Prop that, when it changes, will cause the dropdown to close",name:"propChangeToClose",required:!1,type:{name:"unknown"}},visibleElement:{defaultValue:null,description:"Render for element always visible used to open and close the dropdown",name:"visibleElement",required:!0,type:{name:"(onClick: () => unknown) => ReactElement<unknown, string | JSXElementConstructor<any>>"}},children:{defaultValue:null,description:"Close if a clickable element within is clicked",name:"children",required:!0,type:{name:"ReactNode | ((closeDropdown: () => unknown) => ReactNode)"}}}}}catch{}try{dropdownbutton.displayName="dropdownbutton",dropdownbutton.__docgenInfo={description:"",displayName:"dropdownbutton",props:{children:{defaultValue:null,description:"Content revealed on click.",name:"children",required:!0,type:{name:"ReactNode | ((showMenu: Dispatch<SetStateAction<boolean>>) => ReactNode)"}},label:{defaultValue:null,description:"Label to be display by the button",name:"label",required:!0,type:{name:"ReactNode"}},openOnHover:{defaultValue:{value:"false"},description:"Open on pointer over (useful for dropdowns in header)",name:"openOnHover",required:!1,type:{name:"boolean"}},type:{defaultValue:null,description:"Type to pass to the underlying <button></button>",name:"type",required:!1,type:{name:"enum",value:[{value:'"button"'},{value:'"submit"'},{value:'"reset"'}]}},className:{defaultValue:null,description:"Classnames to be added to the button",name:"className",required:!1,type:{name:"string"}},disabled:{defaultValue:null,description:"Flag to disable the button",name:"disabled",required:!1,type:{name:"boolean"}},variant:{defaultValue:null,description:"Variant of the button",name:"variant",required:!1,type:{name:"enum",value:[{value:'"primary"'},{value:'"secondary"'},{value:'"tertiary"'}]}}}}}catch{}export{_ as C,E as D,k as a};
