Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: GenericMenu logic to add gap #29751

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/meteor/client/components/GenericMenu/GenericMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const GenericMenu = ({ title, icon = 'menu', onAction, ...props }: GenericMenuPr
const disabledKeys = itemsList.filter(({ disabled }) => disabled).map(({ id }) => id);
const handleAction = useHandleMenuAction(itemsList || []);

const hasIcon = itemsList.some(({ icon }) => icon);
const handleItems = (items: GenericMenuItemProps[]) => (hasIcon ? items.map((item) => ({ ...item, gap: !item.icon })) : items);

return (
<>
{sections && (
Expand All @@ -50,7 +53,11 @@ const GenericMenu = ({ title, icon = 'menu', onAction, ...props }: GenericMenuPr
{...props}
>
{sections.map(({ title, items }, key) => (
<MenuSection title={typeof title === 'string' && t.has(title) ? t(title) : title} items={items} key={`${title}-${key}`}>
<MenuSection
title={typeof title === 'string' && t.has(title) ? t(title) : title}
items={handleItems(items)}
key={`${title}-${key}`}
>
{(item) => (
<MenuItem key={item.id}>
<GenericMenuItem {...item} />
Expand All @@ -68,7 +75,7 @@ const GenericMenu = ({ title, icon = 'menu', onAction, ...props }: GenericMenuPr
{...(disabledKeys && { disabledKeys })}
{...props}
>
{items.map((item) => (
{handleItems(items).map((item) => (
<MenuItem key={item.id}>
<GenericMenuItem {...item} />
</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export type GenericMenuItemProps = {
status?: ReactNode;
disabled?: boolean;
description?: ReactNode;
gap?: boolean;
};

const GenericMenuItem = ({ icon, content, addon, status }: GenericMenuItemProps) => (
const GenericMenuItem = ({ icon, content, addon, status, gap }: GenericMenuItemProps) => (
<>
{gap && <MenuItemColumn />}
{icon && <MenuItemIcon name={icon} />}
{status && <MenuItemColumn>{status}</MenuItemColumn>}
{content && <MenuItemContent>{content}</MenuItemContent>}
Expand Down