Skip to content

Commit

Permalink
fix #113
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedElywa committed Feb 17, 2021
1 parent 012905e commit 1977d5a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/ui/src/Menu/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@ interface ItemProps {
currentPath: string;
}

const getExtras = (item: MenuItemType) => {
return {
customAfter: item.extras?.filter((x) => x.position === 'after').map((x) => x.content),
customBefore: item.extras?.filter((x) => x.position === 'before').map((x) => x.content),
};
};

const LinkContent: React.FC<{ item: MenuItemType }> = ({ item }) => {
const { customAfter, customBefore } = getExtras(item);
return (
<>
<ItemIcon icon={item.icon} className="menu-icon" />
{customBefore}
<span className="menu-title">{item.title}</span>
{customAfter}
</>
);
};
Expand Down Expand Up @@ -54,12 +64,16 @@ const Item: React.FC<ItemProps> = ({
toggleSubMenu(item);
};

const { customAfter, customBefore } = getExtras(item);

return (
<ItemStyle className={item.group ? 'menu-item menu-group' : 'menu-item'}>
{item.group ? (
<span>
<ItemIcon icon={item.icon} className="menu-icon" />
{customBefore}
{item.title}
{customAfter}
</span>
) : item.link && !item.children ? (
nextJs ? (
Expand Down Expand Up @@ -89,7 +103,9 @@ const Item: React.FC<ItemProps> = ({
className={item.selected ? 'active' : ''}
>
<ItemIcon icon={item.icon} className="menu-icon" />
{customBefore}
<span className="menu-title">{item.title}</span>
{customAfter}
<i className="chevron">
{item.expanded ? <Icon name="chevron-down-outline" /> : <Icon name="chevron-left-outline" />}
</i>
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface ItemType {
url: string;
link: { [k: string]: any };
group: boolean;
extras?: { position: 'after' | 'before'; content: any }[];
children: RequireOnlyOne<ItemType, 'url' | 'children' | 'link' | 'group'>[];
}

Expand Down

0 comments on commit 1977d5a

Please sign in to comment.