import { useRef, useState, ReactElement } from 'react'; import { MuiGrow as Grow, MuiPopper as Popper, MuiPopperPlacementType as PopperPlacementType, } from '../mui'; import { styled } from '../styled'; import { ArrowRightIcon } from '@toeverything/components/icons'; import { Divider } from '../divider'; export interface CascaderItemProps { title: string; shortcut?: string; callback?: () => void; subItems?: CascaderItemProps[]; children?: ReactElement | Array; icon?: ReactElement; isDivide?: boolean; } interface ItemProps extends CascaderItemProps { onClose?: () => void; } interface CascaderProps { items: ItemProps[]; anchorEl: Element; placement: PopperPlacementType; open: boolean; onClose: () => void; children?: ReactElement | never[]; icon?: ReactElement; } function CascaderItem(props: ItemProps) { const { title, subItems, callback, onClose, children, icon, isDivide } = props; const item_ref = useRef(null); const [open, setOpen] = useState(false); if (isDivide) { return ; } const on_click_item = () => { if ((subItems && subItems.length > 0) || children) { return; } callback && callback(); onClose(); }; return ( setOpen(true)} onMouseLeave={() => setOpen(false)} onClick={() => on_click_item()} > {icon}
{title}
{children || (subItems && subItems.length > 0) ? ( ) : null}
{((subItems && subItems.length > 0) || children) && ( )}
); } export function Cascader(props: CascaderProps) { const { items, anchorEl, placement, open, onClose, children } = props; return ( {({ TransitionProps }) => ( {children ? children : null}
    {items.map(item => { return ( ); })}
)}
); } const MenuPaper = styled('div')(({ theme }) => ({ fontFamily: 'PingFang SC', background: '#FFF', boxShadow: '0px 1px 10px rgba(152, 172, 189, 0.6)', borderRadius: '10px 0px 10px 10px', color: '#4C6275', fontWeight: '400', padding: '4px 8px', })); const CascaderMenuItem = styled('li')(({ theme }) => ({ fontWeight: '400 !important', width: '268px', height: '32px', lineHeight: '32px', display: 'flex', fontSize: '14px', borderRadius: '5px', cursor: 'pointer', '&:hover': { backgroundColor: '#F5F7F8', }, })); const IconContainer = styled('div')(({ theme }) => ({ display: 'flex', height: '32px', margin: '0 8px', flexDirection: 'column', justifyContent: 'center', lineHeight: '32px', fontSize: '20px', '&, & > svg': { width: '20px', }, '& > svg': { height: '20px', }, })); const Triangle = styled('div')(({ theme }) => ({ display: 'flex', height: '32px', marginRight: '8px', flexDirection: 'column', justifyContent: 'center', lineHeight: '32px', fontSize: '20px', '&, & > svg': { width: '20px', }, '& > svg': { height: '20px', }, }));