-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add Sidebar Menu navigation #610
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a04253a
Base menu
dani-moreno c77b9d6
Merge branch 'main' into sidebar-navigation
dani-moreno 5cab6f9
styling
dani-moreno 4cf9f41
fixes
dani-moreno d651de8
Merge branch 'main' into sidebar-navigation
dani-moreno 0e8dd26
package
dani-moreno e9c75c1
Merge branch 'main' into sidebar-navigation
dani-moreno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
lib/experimental/Navigation/Sidebar/Menu/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { Meta, StoryObj } from "@storybook/react" | ||
import { Menu } from "." | ||
|
||
const meta = { | ||
component: Menu, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<div className="w-[240px] bg-f1-background-tertiary p-3"> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
tags: ["autodocs"], | ||
} satisfies Meta<typeof Menu> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = { | ||
args: { | ||
tree: [ | ||
{ | ||
title: "Root", | ||
items: [ | ||
{ label: "Home", icon: "Home", href: "/home", isActive: true }, | ||
{ | ||
label: "Inbox", | ||
icon: "Envelope", | ||
href: "/inbox", | ||
badge: 6, | ||
}, | ||
{ | ||
label: "Discover Factorial", | ||
icon: "UpgradePlan", | ||
href: "/discover", | ||
}, | ||
], | ||
isRoot: true, | ||
}, | ||
{ | ||
title: "You", | ||
items: [ | ||
{ label: "Me", icon: "Person", href: "/me" }, | ||
{ label: "Clock in", icon: "Clock", href: "/clock-in" }, | ||
{ label: "Time off", icon: "TimeOff", href: "/time-off" }, | ||
], | ||
isOpen: true, | ||
}, | ||
{ | ||
title: "Your company", | ||
items: [ | ||
{ label: "Organization", icon: "Manager", href: "/organization" }, | ||
{ label: "Calendar", icon: "Calendar", href: "/calendar" }, | ||
], | ||
isOpen: true, | ||
}, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { Counter } from "@/experimental/Information/Counter" | ||
import * as Icons from "@/icons" | ||
import { cn } from "@/lib/utils" | ||
import { | ||
Collapsible, | ||
CollapsibleContent, | ||
CollapsibleTrigger, | ||
} from "@/ui/collapsible" | ||
import { AnimatePresence, motion } from "framer-motion" | ||
import React from "react" | ||
|
||
type IconName = keyof typeof Icons | ||
|
||
interface MenuItem { | ||
label: string | ||
icon: IconName | ||
badge?: number | ||
href: string | ||
isActive?: boolean | ||
} | ||
|
||
interface MenuCategory { | ||
title: string | ||
items: MenuItem[] | ||
isRoot?: boolean | ||
isOpen?: boolean | ||
} | ||
|
||
interface MenuProps { | ||
tree: MenuCategory[] | ||
} | ||
|
||
const MenuItemContent = ({ item }: { item: MenuItem }) => { | ||
const IconComponent = Icons[item.icon] | ||
|
||
return ( | ||
<div className="flex w-full items-center justify-between"> | ||
<div className="flex items-center gap-1.5 font-medium text-f1-foreground"> | ||
<IconComponent | ||
className={cn( | ||
"h-5 w-5", | ||
item.isActive ? "text-f1-foreground" : "text-f1-icon" | ||
)} | ||
/> | ||
<span>{item.label}</span> | ||
</div> | ||
{item.badge && <Counter value={item.badge} size="sm" type="bold" />} | ||
</div> | ||
) | ||
} | ||
|
||
const MenuItem = ({ item }: { item: MenuItem }) => ( | ||
<a | ||
href={item.href} | ||
className={cn( | ||
"flex cursor-pointer items-center rounded py-1.5 pl-1.5 pr-2 no-underline transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-f1-ring focus-visible:ring-offset-1", | ||
item.isActive | ||
? "bg-f1-background-secondary-hover text-f1-foreground" | ||
: "hover:bg-f1-background-secondary-hover" | ||
)} | ||
> | ||
<MenuItemContent item={item} /> | ||
</a> | ||
) | ||
|
||
const CategoryItem = ({ category }: { category: MenuCategory }) => { | ||
const [isOpen, setIsOpen] = React.useState(category.isOpen !== false) | ||
|
||
if (category.isRoot) { | ||
return ( | ||
<div className="flex flex-col gap-1 pb-3"> | ||
{category.items.map((item, index) => ( | ||
<MenuItem key={index} item={item} /> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<Collapsible open={isOpen} onOpenChange={setIsOpen}> | ||
<CollapsibleTrigger className="flex w-full cursor-pointer items-center justify-between border-t border-dashed border-transparent border-t-f1-border px-1.5 pb-2 pt-4 text-sm font-semibold uppercase tracking-wide text-f1-foreground-secondary focus-visible:rounded-md focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-f1-ring focus-visible:ring-offset-1"> | ||
{category.title} | ||
<motion.div | ||
initial={false} | ||
animate={{ rotate: isOpen ? 180 : 0 }} | ||
transition={{ duration: 0.1 }} | ||
> | ||
<Icons.ChevronDown className="h-4 w-4" /> | ||
</motion.div> | ||
</CollapsibleTrigger> | ||
<CollapsibleContent | ||
forceMount | ||
className="flex flex-col gap-1 overflow-hidden pb-3" | ||
> | ||
<AnimatePresence initial={false}> | ||
{isOpen && ( | ||
<motion.div | ||
initial={{ opacity: 0, height: 0 }} | ||
animate={{ opacity: 1, height: "auto" }} | ||
exit={{ opacity: 0, height: 0 }} | ||
transition={{ duration: 0.15, ease: "easeInOut" }} | ||
className="flex flex-col gap-1 pb-3" | ||
> | ||
{category.items.map((item, index) => ( | ||
<MenuItem key={index} item={item} /> | ||
))} | ||
</motion.div> | ||
)} | ||
</AnimatePresence> | ||
</CollapsibleContent> | ||
</Collapsible> | ||
) | ||
} | ||
|
||
export function Menu({ tree }: MenuProps) { | ||
return ( | ||
<div className="min-h-screen w-full bg-transparent"> | ||
{tree.map((category, index) => ( | ||
<CategoryItem key={index} category={category} /> | ||
))} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use client" | ||
|
||
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible" | ||
|
||
const Collapsible = CollapsiblePrimitive.Root | ||
|
||
const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger | ||
|
||
const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent | ||
|
||
export { Collapsible, CollapsibleContent, CollapsibleTrigger } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat 🔥