Sidebar Light
inferencesh/sidebar-lightFreeBlock
Lightweight sidebar navigation with nested items and active state.
Live preview
live · rendered by the registry
Rendered by inferencesh on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.inference.sh/r/sidebar-light.jsonSource
1"use client"23import * as React from "react"4import Link from "next/link"5import { usePathname } from "next/navigation"6import { cn } from "@/lib/utils"78export interface NavItem {9 title: string10 href: string11 icon?: React.ComponentType<{ className?: string }>12 items?: NavItem[]13}1415interface SidebarLightProps {16 items: NavItem[]17 className?: string18}1920interface NavItemRendererProps {21 item: NavItem22 pathname: string23 depth: number24}2526function NavItemRenderer({ item, pathname, depth }: NavItemRendererProps) {27 const hasChildren = item.items && item.items.length > 028 const isActive = pathname === item.href2930 // Parent item with children (section header)31 if (hasChildren) {32 return (33 <div className="space-y-1">34 <div35 className={cn(36 "flex items-center gap-2 text-sm",37 depth === 0 && "px-3 py-2 font-semibold text-foreground",38 depth > 0 && "px-3 py-1.5 font-medium text-muted-foreground"39 )}40 >41 {item.icon && <item.icon className={cn(depth === 0 ? "h-4 w-4" : "h-3.5 w-3.5")} />}42 {item.title}43 </div>44 <div className={cn("ml-4 space-y-1 border-l border-border pl-2")}>45 {item.items!.map((subItem, index) => (46 <NavItemRenderer47 key={subItem.href !== "#" ? subItem.href : `${subItem.title}-${index}`}48 item={subItem}49 pathname={pathname}50 depth={depth + 1}51 />52 ))}53 </div>54 </div>55 )56 }5758 // Leaf item (link)59 return (60 <Link61 href={item.href}62 className={cn(63 "flex items-center gap-2 text-sm rounded-md transition-colors",64 depth === 0 && "px-3 py-2",65 depth > 0 && "px-3 py-1.5",66 isActive67 ? "bg-muted font-medium text-foreground"68 : "text-muted-foreground hover:text-foreground hover:bg-muted/50"69 )}70 >71 {item.icon && <item.icon className={cn(depth === 0 ? "h-4 w-4" : "h-3.5 w-3.5")} />}72 {item.title}73 </Link>74 )75}7677function SidebarLight({ items, className }: SidebarLightProps) {78 const pathname = usePathname()7980 return (81 <aside className={cn("w-full", className)}>82 <nav className="space-y-1">83 {items.map((item, index) => (84 <NavItemRenderer85 key={item.href !== "#" ? item.href : `${item.title}-${index}`}86 item={item}87 pathname={pathname}88 depth={0}89 />90 ))}91 </nav>92// … truncated
Files it writes
More from inferencesh
All 14 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Agent Chatagent | inferencesh | Blocks | Free | 1 dep | |
| Chat UI Primitiveschat | inferencesh | Blocks | Free | 1 dep · 15 files | |
| Code Blockcode-block | inferencesh | Blocks | Free | no deps · 7 files | |
| Markdown Renderer (legacy)markdown | inferencesh | Blocks | Free | 2 deps · 2 files | |
| pretext-mdpretext-md | inferencesh | Blocks | Free | 4 deps · 10 files | |
| Stepssteps | inferencesh | Blocks | Free | no deps · 2 files | |
| Table of Contentstable-of-contents | inferencesh | Blocks | Free | no deps | |
| Tasktask | inferencesh | Blocks | Free | 1 dep · 9 files |
