-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update
Nav
component and use everywhere (#203)
- Loading branch information
Showing
14 changed files
with
1,208 additions
and
1,234 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
"namesake": minor | ||
--- | ||
|
||
Display statuses in main navigation, improve nav display |
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
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
Large diffs are not rendered by default.
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
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
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
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
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 |
---|---|---|
@@ -1,43 +1,88 @@ | ||
import type { RemixiconComponentType } from "@remixicon/react"; | ||
import { type LinkProps, useMatchRoute } from "@tanstack/react-router"; | ||
import { Header } from "react-aria-components"; | ||
import { tv } from "tailwind-variants"; | ||
import { Badge } from "../Badge"; | ||
import { Link } from "../Link"; | ||
import { focusRing } from "../utils"; | ||
|
||
interface NavProps { | ||
routes: { | ||
icon: RemixiconComponentType; | ||
href: LinkProps; | ||
label: string; | ||
}[]; | ||
interface NavItemProps { | ||
href: LinkProps; | ||
icon?: RemixiconComponentType; | ||
className?: string; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const styles = tv({ | ||
const navItemStyles = tv({ | ||
extend: focusRing, | ||
base: "rounded-lg no-underline flex items-center gap-2 text-gray-dim hover:text-gray-normal py-1.5 aria-current:font-semibold aria-current:text-gray-normal", | ||
base: "rounded-md no-underline flex items-center text-sm gap-1.5 hover:bg-gray-3 dark:hover:bg-graydark-3 h-8 px-2 -mx-2 aria-current:font-semibold aria-current:text-gray-normal", | ||
variants: { | ||
isActive: { | ||
true: "bg-gray-3 dark:bg-graydark-3", | ||
}, | ||
}, | ||
}); | ||
|
||
const iconStyles = tv({ | ||
base: "text-gray-dim", | ||
variants: { | ||
isActive: { | ||
true: "text-gray-normal", | ||
}, | ||
}, | ||
}); | ||
|
||
export const Nav = ({ routes }: NavProps) => { | ||
export const NavItem = ({ | ||
icon: Icon, | ||
href, | ||
className, | ||
children, | ||
}: NavItemProps) => { | ||
const matchRoute = useMatchRoute(); | ||
const current = matchRoute({ ...href, fuzzy: true }); | ||
|
||
return ( | ||
<Link | ||
href={{ ...href }} | ||
className={({ isFocusVisible }) => | ||
navItemStyles({ | ||
isFocusVisible, | ||
isActive: !!current, | ||
class: className, | ||
}) | ||
} | ||
aria-current={current ? "true" : null} | ||
> | ||
{Icon && ( | ||
<Icon size={20} className={iconStyles({ isActive: !!current })} /> | ||
)} | ||
{children} | ||
</Link> | ||
); | ||
}; | ||
|
||
interface NavGroupProps { | ||
label: string; | ||
children: React.ReactNode; | ||
count?: number; | ||
} | ||
|
||
export const NavGroup = ({ label, children, count }: NavGroupProps) => { | ||
return ( | ||
<div> | ||
{routes.map(({ href, label, icon }) => { | ||
const current = matchRoute({ ...href, fuzzy: true }); | ||
const Icon = icon; | ||
|
||
return ( | ||
<Link | ||
key={href.to} | ||
href={{ ...href }} | ||
className={styles()} | ||
aria-current={current ? "true" : null} | ||
> | ||
<Icon /> | ||
{label} | ||
</Link> | ||
); | ||
})} | ||
<div className="flex flex-col gap-0.5 [&:not(:first-child)]:mt-4"> | ||
<Header className="text-sm h-8 font-semibold text-gray-dim border-b border-gray-4 dark:border-graydark-4 flex justify-start items-center gap-1.5"> | ||
{label} | ||
{count && <Badge size="xs">{count}</Badge>} | ||
</Header> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
interface NavProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
export const Nav = ({ children }: NavProps) => { | ||
return <nav className="flex flex-col gap-0.5">{children}</nav>; | ||
}; |
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.