This PR was created by [GitStart](https://gitstart.com/) to address the requirements from this ticket: [TWNTY-7536](https://clients.gitstart.com/twenty/5449/tickets/TWNTY-7536). --- ### Description Migrate all menu items components to twenty ui and update imports. ```typescript MenuItem MenuItemAvata MenuItemCommand MenuItemCommandHotKeys MenuItemDraggable MenuItemMultiSelect MenuItemMultiSelectAvatar MenuItemMultiSelectTag MenuItemNavigate MenuItemSelect MenuItemSelectAvatar MenuItemSelectColor MenuItemSelectTag MenuItemSuggestion MenuItemToggle ``` \ Also migrate all other dependent components and utilities like `Checkbox` & `Toggle`\ \ Fixes twentyhq/private-issues#82 --------- Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: gitstart-twenty <140154534+gitstart-twenty@users.noreply.github.com> Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
87 lines
2.6 KiB
TypeScript
87 lines
2.6 KiB
TypeScript
import { useTheme } from '@emotion/react';
|
|
import { IconChevronRight, IconComponent } from '@ui/display';
|
|
import { LightIconButtonProps } from '@ui/input/button/components/LightIconButton';
|
|
import { LightIconButtonGroup } from '@ui/input/button/components/LightIconButtonGroup';
|
|
import { FunctionComponent, MouseEvent, ReactElement, ReactNode } from 'react';
|
|
|
|
import { MenuItemLeftContent } from '../internals/components/MenuItemLeftContent';
|
|
import {
|
|
StyledHoverableMenuItemBase,
|
|
StyledMenuItemLeftContent,
|
|
} from '../internals/components/StyledMenuItemBase';
|
|
import { MenuItemAccent } from '../types/MenuItemAccent';
|
|
|
|
export type MenuItemIconButton = {
|
|
Wrapper?: FunctionComponent<{ iconButton: ReactElement }>;
|
|
Icon: IconComponent;
|
|
accent?: LightIconButtonProps['accent'];
|
|
onClick?: (event: MouseEvent<any>) => void;
|
|
};
|
|
|
|
export type MenuItemProps = {
|
|
accent?: MenuItemAccent;
|
|
className?: string;
|
|
iconButtons?: MenuItemIconButton[];
|
|
isIconDisplayedOnHoverOnly?: boolean;
|
|
isTooltipOpen?: boolean;
|
|
LeftIcon?: IconComponent | null;
|
|
onClick?: (event: MouseEvent<HTMLDivElement>) => void;
|
|
onMouseEnter?: (event: MouseEvent<HTMLDivElement>) => void;
|
|
onMouseLeave?: (event: MouseEvent<HTMLDivElement>) => void;
|
|
testId?: string;
|
|
text: ReactNode;
|
|
hasSubMenu?: boolean;
|
|
};
|
|
|
|
export const MenuItem = ({
|
|
accent = 'default',
|
|
className,
|
|
iconButtons,
|
|
isIconDisplayedOnHoverOnly = true,
|
|
LeftIcon,
|
|
onClick,
|
|
onMouseEnter,
|
|
onMouseLeave,
|
|
testId,
|
|
text,
|
|
hasSubMenu = false,
|
|
}: MenuItemProps) => {
|
|
const theme = useTheme();
|
|
const showIconButtons = Array.isArray(iconButtons) && iconButtons.length > 0;
|
|
|
|
const handleMenuItemClick = (event: MouseEvent<HTMLDivElement>) => {
|
|
if (!onClick) return;
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
|
|
onClick?.(event);
|
|
};
|
|
|
|
return (
|
|
<StyledHoverableMenuItemBase
|
|
data-testid={testId ?? undefined}
|
|
onClick={handleMenuItemClick}
|
|
className={className}
|
|
accent={accent}
|
|
isIconDisplayedOnHoverOnly={isIconDisplayedOnHoverOnly}
|
|
onMouseEnter={onMouseEnter}
|
|
onMouseLeave={onMouseLeave}
|
|
>
|
|
<StyledMenuItemLeftContent>
|
|
<MenuItemLeftContent LeftIcon={LeftIcon ?? undefined} text={text} />
|
|
</StyledMenuItemLeftContent>
|
|
<div className="hoverable-buttons">
|
|
{showIconButtons && (
|
|
<LightIconButtonGroup iconButtons={iconButtons} size="small" />
|
|
)}
|
|
</div>
|
|
{hasSubMenu && (
|
|
<IconChevronRight
|
|
size={theme.icon.size.sm}
|
|
color={theme.font.color.tertiary}
|
|
/>
|
|
)}
|
|
</StyledHoverableMenuItemBase>
|
|
);
|
|
};
|