Sidebar nav
Sidebar nav with pixel icons and count badges, a hover block and an active bar that slides to the current item.
Playground
Change a prop and the component re-renders. Props marked remounts set an initial value, so the component starts over.
<PxNav
items={[
{
href: "#home",
label: "Home",
icon: "home"
},
{
href: "#chats",
label: "Chats",
icon: "chat",
badge: "3"
},
{
href: "#projects",
label: "Projects",
icon: "folder"
},
{
href: "#usage",
label: "Usage",
icon: "chart"
},
{
href: "#team",
label: "Team",
icon: "users"
},
{
href: "#settings",
label: "Settings",
icon: "gear"
}
]}
defaultValue="#home"
/>Installation
pnpm dlx shadcn@latest add @lumesec/px-navFirst timeRegister the @lumesec registry once, or install by URL+
Adds @lumesec to your components.json:
pnpm dlx shadcn@latest registry add @lumesec=https://elements.lumesec.ai/r/{name}.jsonOr skip the setup and install by URL:
npx shadcn@latest add https://elements.lumesec.ai/r/px-nav.jsonUsage
import { PxNav } from "@/components/lumesec/px-nav";
export function Example() {
return (
<PxNav
aria-label="Main"
items={[
{ href: "#home", label: "Home", icon: "home" },
{ href: "#chats", label: "Chats", icon: "chat", badge: "3" },
{ href: "#settings", label: "Settings", icon: "gear" },
]}
/>
);
}Behaviour
Takes a list of links and adds pixel icons, count badges, a soft hover block and an active bar that slides to the current item.
API reference
Props
Also accepts every prop of <nav> (React.ComponentProps<"nav">), spread onto the root element.
valueTypestringControlled href of the current item. Use with onValueChange.
defaultValueTypestringDefaultfirst itemhref of the initially current item when uncontrolled.
itemsTypereadonly PxNavItem[]The links: { href: string; label: string; icon?: PxNavIcon; badge?: string }. href also identifies the item in value.
onValueChangeType(value: string) => voidCalled with the href of a link the user clicks, when it is not already current.
Ref
ref points at the root HTMLElement.
Accessibility
- Links are native
<a>elements inside a<nav>; passaria-labelto name the nav. - The current link has
aria-current="page". - Icons are drawn on an
aria-hiddencanvas. A badge is text inside its link, so assistive technology reads it as part of the link's name. - Focusing a link shows the same hover block as the pointer.
- Reduced motion: the active bar and the hover block jump instead of springing.
Theming
Styled with Tailwind classes on your shadcn theme tokens, so light and dark follow your theme. The accent comes from --lumesec. See Theming.
This component reads --lumesec, --foreground, --muted-foreground, --destructive and --lumesec-foreground.
Notes
iconpicks a built-in icon:home,chat,folder,chart,gear,usersorbell.badgeshows a small badge with that text at the end of the row, in the mono font: red, or accent on the current item.- Clicking a link whose
hrefstarts with#does not navigate; other links navigate as usual after being marked current. To route on the client, handleonValueChangeor replace the<a>with your router's link.
Related
Was this page helpful?