import { Box, Typography, styled, ButtonBase, SwipeableDrawer } from '@linagora/twake-mui' import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown' import React, { forwardRef, useImperativeHandle, useState } from 'react' export interface MobileSelectorHandle { open: boolean onClose: () => void } const StyledSwipeableDrawer = styled(SwipeableDrawer)(({ theme }) => ({ zIndex: theme.zIndex.modal + 100 })) const SelectorButton = styled(ButtonBase)(({ theme }) => ({ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: theme.spacing(1.5, 2), border: `1px solid ${theme.palette.divider}`, borderRadius: theme.shape.borderRadius, backgroundColor: theme.palette.background.paper, color: theme.palette.text.secondary, textAlign: 'left', cursor: 'pointer', transition: 'border-color 0.2s', '&:hover': { borderColor: theme.palette.text.primary } })) interface MobileSelectorProps { displayText: string children?: React.ReactNode bottomSheetRef?: React.RefObject paperRef?: React.RefObject bottomSheetChildren?: (props: { open: boolean onClose: () => void }) => React.ReactNode } export const MobileSelector = forwardRef< MobileSelectorHandle, MobileSelectorProps >( ( { displayText, children, bottomSheetRef, paperRef, bottomSheetChildren }, ref ) => { const [open, setOpen] = useState(false) const onClose = (): void => { setOpen(false) } useImperativeHandle(ref, () => ({ open, onClose })) return ( <> setOpen(true)}> {displayText} {children ? ( {}} disableAutoFocus slotProps={{ paper: { ref: paperRef, sx: { maxHeight: '90dvh' } } }} > {children} ) : ( bottomSheetChildren?.({ open, onClose }) )} ) } ) MobileSelector.displayName = 'MobileSelector'