# Introduction closes https://github.com/twentyhq/core-team-issues/issues/591 Same than for `twenty-shared` made in https://github.com/twentyhq/twenty/pull/11083. ## TODO - [x] Manual migrate twenty-website twenty-ui imports ## What's next: - Generate barrel and migration script factorization within own package + tests - Refactoring using preconstruct ? TimeBox - Lint circular dependencies - Lint import from barrel and forbid them ### Preconstruct We need custom rollup plugins addition, but preconstruct does not expose its rollup configuration. It might be possible to handle this using the babel overrides. But was a big tunnel. We could give it a try afterwards ! ( allowing cjs interop and stuff like that ) Stuck to vite lib app Closed related PRs: - https://github.com/twentyhq/twenty/pull/11294 - https://github.com/twentyhq/twenty/pull/11203
108 lines
3.0 KiB
TypeScript
108 lines
3.0 KiB
TypeScript
import { SelectHotkeyScope } from '@/ui/input/types/SelectHotkeyScope';
|
|
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
|
|
import { useTheme } from '@emotion/react';
|
|
import { Placement } from '@floating-ui/react';
|
|
import { FunctionComponent, MouseEvent, ReactElement, ReactNode } from 'react';
|
|
import {
|
|
IconChevronRight,
|
|
IconComponent,
|
|
IconDotsVertical,
|
|
} from 'twenty-ui/display';
|
|
import { LightIconButton, LightIconButtonProps } from 'twenty-ui/input';
|
|
import {
|
|
MenuItemAccent,
|
|
MenuItemLeftContent,
|
|
StyledHoverableMenuItemBase,
|
|
StyledMenuItemLeftContent,
|
|
} from 'twenty-ui/navigation';
|
|
|
|
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;
|
|
dropdownPlacement?: Placement;
|
|
};
|
|
|
|
// TODO: refactor this
|
|
export const MenuItemWithOptionDropdown = ({
|
|
accent = 'default',
|
|
className,
|
|
isIconDisplayedOnHoverOnly = true,
|
|
dropdownContent,
|
|
dropdownId,
|
|
LeftIcon,
|
|
RightIcon,
|
|
onClick,
|
|
onMouseEnter,
|
|
onMouseLeave,
|
|
testId,
|
|
text,
|
|
hasSubMenu = false,
|
|
dropdownPlacement = 'bottom-end',
|
|
}: 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"
|
|
accent="tertiary"
|
|
/>
|
|
}
|
|
dropdownPlacement={dropdownPlacement}
|
|
dropdownComponents={dropdownContent}
|
|
dropdownId={dropdownId}
|
|
dropdownHotkeyScope={{ scope: SelectHotkeyScope.Select }}
|
|
/>
|
|
</div>
|
|
{hasSubMenu && (
|
|
<IconChevronRight
|
|
size={theme.icon.size.sm}
|
|
color={theme.font.color.tertiary}
|
|
/>
|
|
)}
|
|
</StyledHoverableMenuItemBase>
|
|
);
|
|
};
|