-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
155f475
commit 771928d
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...wenty-front/src/modules/ui/navigation/menu-item/components/MenuItemWithOptionDropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { SelectHotkeyScope } from '@/ui/input/types/SelectHotkeyScope'; | ||
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown'; | ||
import { useTheme } from '@emotion/react'; | ||
import { FunctionComponent, MouseEvent, ReactElement, ReactNode } from 'react'; | ||
import { | ||
IconChevronRight, | ||
IconComponent, | ||
IconDotsVertical, | ||
LightIconButton, | ||
LightIconButtonProps, | ||
MenuItemAccent, | ||
MenuItemLeftContent, | ||
StyledHoverableMenuItemBase, | ||
StyledMenuItemLeftContent, | ||
} from 'twenty-ui'; | ||
|
||
export type MenuItemIconButton = { | ||
Wrapper?: FunctionComponent<{ iconButton: ReactElement }>; | ||
Icon: IconComponent; | ||
accent?: LightIconButtonProps['accent']; | ||
onClick?: (event: MouseEvent<any>) => void; | ||
}; | ||
|
||
export type MenuItemWithOptionDropdownProps = { | ||
accent?: MenuItemAccent; | ||
className?: string; | ||
dropdownContent: ReactNode; | ||
dropdownId: string; | ||
isIconDisplayedOnHoverOnly?: boolean; | ||
isTooltipOpen?: boolean; | ||
LeftIcon?: IconComponent | null; | ||
RightIcon?: IconComponent | null; | ||
onClick?: (event: MouseEvent<HTMLDivElement>) => void; | ||
onMouseEnter?: (event: MouseEvent<HTMLDivElement>) => void; | ||
onMouseLeave?: (event: MouseEvent<HTMLDivElement>) => void; | ||
testId?: string; | ||
text: ReactNode; | ||
hasSubMenu?: boolean; | ||
}; | ||
|
||
// TODO: refactor this | ||
export const MenuItemWithOptionDropdown = ({ | ||
accent = 'default', | ||
className, | ||
isIconDisplayedOnHoverOnly = true, | ||
dropdownContent, | ||
dropdownId, | ||
LeftIcon, | ||
RightIcon, | ||
onClick, | ||
onMouseEnter, | ||
onMouseLeave, | ||
testId, | ||
text, | ||
hasSubMenu = false, | ||
}: MenuItemWithOptionDropdownProps) => { | ||
const theme = useTheme(); | ||
|
||
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"> | ||
<Dropdown | ||
clickableComponent={ | ||
<LightIconButton | ||
Icon={RightIcon ?? IconDotsVertical} | ||
size="small" | ||
/> | ||
} | ||
dropdownComponents={dropdownContent} | ||
dropdownId={dropdownId} | ||
dropdownHotkeyScope={{ scope: SelectHotkeyScope.Select }} | ||
disableBlur | ||
/> | ||
</div> | ||
{hasSubMenu && ( | ||
<IconChevronRight | ||
size={theme.icon.size.sm} | ||
color={theme.font.color.tertiary} | ||
/> | ||
)} | ||
</StyledHoverableMenuItemBase> | ||
); | ||
}; |