Skip to content

Commit

Permalink
feat: add action slot to menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
abelflopes committed Jul 9, 2024
1 parent 6bae06c commit f4d8109
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/components/_provisional/src/menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export interface MenuItemProps<T extends HTMLTag = "li">
ConsumerPolymorphicProps<T> {
skin?: "default" | "primary" | "secondary";
disabled?: boolean;
icon?: NonNullable<React.ReactNode>;
icon?: React.ReactNode;
action?: React.ReactNode;
}

export const MenuItem = <T extends HTMLTag>({
Expand All @@ -23,6 +24,7 @@ export const MenuItem = <T extends HTMLTag>({
disabled,
className,
children,
action,
...otherProps
}: Readonly<MenuItemProps<T>>): React.ReactElement => {
const menuContext = useContext(MenuContext);
Expand All @@ -42,6 +44,8 @@ export const MenuItem = <T extends HTMLTag>({
}}>
{icon}
{children}

{action ? <span className={styles.action}>{action}</span> : null}
</PolymorphicComponent>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@
justify-content: center;
}
}

.action {
margin-left: auto;
}
17 changes: 16 additions & 1 deletion packages/docs/stories/src/menu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Menu } from "@react-ck/provisional/src";
import { Icon } from "@react-ck/icon/src";
import { faker } from "@faker-js/faker";
import { IconUserCircle } from "@react-ck/icon/icons/IconUserCircle";
import { IconVerticalDots } from "@react-ck/icon/icons/IconVerticalDots";
import { Button } from "@react-ck/button/src";

type Story = StoryObj<typeof Menu>;

Expand Down Expand Up @@ -65,7 +67,20 @@ const children = (
{faker.person.firstName()}
</Menu.Item>
<Menu.Divider />
<Menu.Item>{faker.animal.type()}</Menu.Item>
<Menu.Item
action={
<Button
skin="ghost"
size="s"
icon={
<Icon>
<IconVerticalDots />
</Icon>
}
/>
}>
{faker.animal.type()}
</Menu.Item>
<Menu.Item disabled>{faker.animal.type()}</Menu.Item>
<Menu.Item>{faker.animal.type()}</Menu.Item>
<Menu.Divider>Companies</Menu.Divider>
Expand Down

0 comments on commit f4d8109

Please sign in to comment.