@lanaco/lnc-react-ui
Version:
React component library
8 lines (7 loc) • 2.34 kB
JavaScript
"use strict";const n=require("react/jsx-runtime"),o=require("react"),C=require("./emotion-styled.browser.esm-DwHBgTPn.cjs"),z=require("./Button.cjs"),B=require("./utils-BK6B_Y9X.cjs"),F=require("./ThemeProvider.cjs"),U=require("./Popover.cjs"),Y=require("./PopoverTrigger.cjs"),$=require("./PopoverContent.cjs"),K=require("./motion-B_VPZaJq.cjs"),L=C.styled.div``,A=C.styled(K.motion.div)`
gap: 0.25rem;
display: flex;
flex-direction: column;
${t=>t.widthfitcontent==!1&&"min-width: 12.5rem"};
background-color: ${t=>B.getColorRgbaValue(t.theme,"Dropdown",t.color,"enabled","background")};
`,G=o.forwardRef((t,s)=>{const{control:i,offsetValue:I=9,placement:S,widthFitContent:T=!1,closeOnItemSelect:q=!0,zIndex:R,onFocus:p=()=>{},onBlur:m=()=>{},onClick:f=()=>{},onKeyDown:d=()=>{},onMouseEnter:y=()=>{},onMouseLeave:E=()=>{},onItemSelected:v=()=>{},animation:M={animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},initial:{opacity:0,height:0},transition:{type:"tween",duration:.15,opacity:{duration:.15,ease:"easeOut"},height:{duration:.15}}},className:N="",color:r="primary",size:a="small",contentClassName:P="",children:j,...D}=t,h=o.useRef(),{theme:b}=F.useTheme(),g=o.useRef(),_=o.useRef(),[O,l]=o.useState(!1),x=(e,u,c)=>{v(e,u,c),q==!0&&l(!1)},k=o.Children.map(j,(e,u)=>{var c,w;return o.isValidElement(e)&&(e.props.__TYPE__=="MENU_ITEM"||((c=e==null?void 0:e.type)==null?void 0:c.displayName)==="MENU_ITEM"||e.props.__TYPE__=="NESTED_ITEM"||((w=e==null?void 0:e.type)==null?void 0:w.displayName)==="NESTED_ITEM")?u==0?(e.props.ref&&(_.current=s),o.cloneElement(e,{ref:s||_,color:e.props.color?e.props.color:r,size:a,onItemSelected:x,animation:M})):o.cloneElement(e,{color:e.props.color?e.props.color:r,size:a,onItemSelected:x}):e}),V=()=>typeof i=="string"||i instanceof String?n.jsx(z,{text:i,onClick:f,onMouseEnter:y,onMouseLeave:E,onBlur:m,onFocus:p,ref:g,onKeyDown:d,trailingIcon:"angle-down",color:r,size:a}):o.cloneElement(i,{color:r,size:a,ref:g,onClick:f,onMouseEnter:y,onMouseLeave:E,onBlur:m,onFocus:p,onKeyDown:d});return n.jsx(L,{ref:s,className:N,...D,children:n.jsxs(U,{open:O,onOpenChange:l,placement:S,offsetValue:I,children:[n.jsx(Y,{onClick:()=>l(e=>!e),children:V()}),n.jsx($,{zIndex:R,children:n.jsx(A,{ref:h,widthfitcontent:T,color:r,theme:b,className:P,children:k})})]})})});module.exports=G;