Closes https://github.com/twentyhq/core-team-issues/issues/1568 https://github.com/user-attachments/assets/a0fe6538-8405-4b52-a6ce-7afa846ee5f3
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { isNonEmptyString } from '@sniptt/guards';
|
|
|
|
import { useCommandMenuOnItemClick } from '@/command-menu/hooks/useCommandMenuOnItemClick';
|
|
import { isSelectedItemIdComponentFamilySelector } from '@/ui/layout/selectable-list/states/selectors/isSelectedItemIdComponentFamilySelector';
|
|
import { useRecoilComponentFamilyValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyValue';
|
|
import { type ReactNode } from 'react';
|
|
import { IconArrowUpRight, type IconComponent } from 'twenty-ui/display';
|
|
import { MenuItem } from 'twenty-ui/navigation';
|
|
|
|
export type CommandMenuItemProps = {
|
|
label: string;
|
|
description?: string;
|
|
to?: string;
|
|
id: string;
|
|
onClick?: () => void;
|
|
Icon?: IconComponent;
|
|
hotKeys?: string[];
|
|
RightComponent?: ReactNode;
|
|
};
|
|
|
|
export const CommandMenuItem = ({
|
|
label,
|
|
description,
|
|
to,
|
|
id,
|
|
onClick,
|
|
Icon,
|
|
hotKeys,
|
|
RightComponent,
|
|
}: CommandMenuItemProps) => {
|
|
const { onItemClick } = useCommandMenuOnItemClick();
|
|
|
|
if (isNonEmptyString(to) && !Icon) {
|
|
Icon = IconArrowUpRight;
|
|
}
|
|
|
|
const isSelectedItemId = useRecoilComponentFamilyValue(
|
|
isSelectedItemIdComponentFamilySelector,
|
|
id,
|
|
);
|
|
|
|
return (
|
|
<MenuItem
|
|
withIconContainer={true}
|
|
LeftIcon={Icon}
|
|
text={label}
|
|
contextualText={description}
|
|
hotKeys={hotKeys}
|
|
onClick={() =>
|
|
onItemClick({
|
|
onClick,
|
|
to,
|
|
})
|
|
}
|
|
focused={isSelectedItemId}
|
|
RightComponent={RightComponent}
|
|
/>
|
|
);
|
|
};
|