import { MouseEventHandler, ReactNode, useState } from 'react'; import type { MenuProps as MuiMenuProps } from '@mui/material/Menu'; import { ASSETS_URL } from '../../../consts/common'; import { ButtonProps } from '../../button'; import { LinkProps } from '../link'; import { StyledLearnMoreItem, StyledLearnMoreLink, StyledButton, StyledMenu } from './styles'; export interface LearnMoreMenuButtonProps { /** * Will be rendered inside the menu as Link components. */ links: (LinkProps & { text?: string })[]; /** * The text of the button. */ buttonText: ReactNode; /** * Props forwarded to the Button component. */ buttonProps?: ButtonProps; /** * Props forwarded to the MuiMenu component. */ menuProps?: MuiMenuProps; } const LearnMoreMenuButton = ({ links, buttonProps, buttonText, menuProps }: LearnMoreMenuButtonProps) => { const [anchorEl, setAnchorEl] = useState(); const handleClose = () => setAnchorEl(undefined); const handleOpen: MouseEventHandler = e => { setAnchorEl(e.currentTarget); if (buttonProps?.onClick) buttonProps.onClick(e); }; return ( <> {buttonText} {links.map((linkProps, index) => { const { children, id, text, ...otherProps } = linkProps; return ( {text || children} ); })} ); }; export default LearnMoreMenuButton;