Skip to content

Commit

Permalink
feat: allow MenuItems to be router links
Browse files Browse the repository at this point in the history
  • Loading branch information
haideralsh committed Dec 4, 2024
1 parent 0436e06 commit 5f3139d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/TopBar/TopBar.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const Overlay = styled(motion(DialogOverlay))(({ theme }) => ({
backgroundColor: transparentize(0.85, theme.colors.white),
}));

const TileLink = styled(motion.a)(({ theme }) => ({
const TileLink = styled.a(({ theme }) => ({
backgroundColor: transparentize(0.15)(theme.colors.blackBlue),
borderRadius: theme.radii.large,
display: "flex",
Expand All @@ -138,7 +138,7 @@ const TileLink = styled(motion.a)(({ theme }) => ({
textOverflow: "hidden",
}));

const StyledMenuItem = styled.li(({ theme }) => ({
const StyledMenuItem = styled(motion.li)(({ theme }) => ({
"&:only-child": {
[`@media (min-width: ${theme.breakpoints.medium})`]: {
gridColumn: "span 2",
Expand Down
13 changes: 3 additions & 10 deletions src/TopBar/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,11 @@ interface MenuItemProps extends ComponentProps<typeof TileLink> {

export function MenuItem({ description, title, icon, ...props }: MenuItemProps) {
return (
<StyledMenuItem>
<TileLink initial="hidden" animate="visible" exit="hidden" variants={fadeInVariants} {...props}>
<StyledMenuItem initial="hidden" animate="visible" exit="hidden" variants={fadeInVariants}>
<TileLink {...props}>
<Icon icon={icon} size="x3" />
<Flex flexDirection="column" justifyContent="center">
<MotionText
// maxWidth="14ch"
// textOverflow="ellipsis"
// overflow="hidden"
fontWeight="medium"
fontSize="md"
lineHeight="base"
>
<MotionText fontWeight="medium" fontSize="md" lineHeight="base">
{title}
</MotionText>
<MotionText fontSize="xs">{description}</MotionText>
Expand Down
15 changes: 15 additions & 0 deletions src/TopBar/stories/TopBar.menu.story.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import { Link, BrowserRouter } from "react-router-dom";
import { TopBar } from "../TopBar";
import { menuItems } from "./fixtures";

Expand Down Expand Up @@ -56,3 +57,17 @@ export const WithThreeItems = () => (
</TopBar.Menu>
</TopBar.Root>
);

export const WithRouterLinks = () => (
<TopBar.Root>
<TopBar.BackLink href="#">Cycle counts</TopBar.BackLink>
<TopBar.PageTitle>Cycle count #3992</TopBar.PageTitle>
<TopBar.Menu defaultOpened>
<BrowserRouter>
{[{ ...menuItems[0], as: Link, to: "/home" }].map((props) => (
<TopBar.MenuItem key={props.title} {...props} />
))}
</BrowserRouter>
</TopBar.Menu>
</TopBar.Root>
);
9 changes: 3 additions & 6 deletions src/TopBar/stories/fixtures.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { ReactRouterLink } from "react-router-dom";
import { MenuItems } from "../components/MenuItem";

export const menuItems: MenuItems = [
{
title: "Home",
description: "Go to the home page",
icon: "home",
as: ReactRouterLink,
to: "/home",
href: "/home",
},
{
title: "Historical orders",
Expand All @@ -18,13 +16,12 @@ export const menuItems: MenuItems = [
{
title: "Pallet inspection",
icon: "barcode",
to: "/pallet-inspection",
as: ReactRouterLink,
href: "/historical-orders",
},
{
title: "Pick Schedule",
icon: "calendarToday",
href: "#",
href: "/pick-schedule",
},
{
title: "Settings",
Expand Down

0 comments on commit 5f3139d

Please sign in to comment.