Sidebar
glasswave/sidebarFreeComponent
Collapsible glass sidebar shell with context state.
Live preview
live · rendered by the registry
Rendered by glasswave on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://glasswave.denizisik.com/r/sidebar.jsonSource
1"use client";23import { PanelLeft } from "lucide-react";4import {5 createContext,6 type ReactNode,7 useCallback,8 useContext,9 useMemo,10 useState,11} from "react";12import { cn } from "@/lib/utils";13import { glass } from "@/lib/glass";14import { buttonVariants } from "@/components/ui/button";1516type SidebarContextValue = {17 open: boolean;18 setOpen: (open: boolean) => void;19 toggle: () => void;20};2122const SidebarContext = createContext<SidebarContextValue | null>(null);2324export function useSidebar() {25 const ctx = useContext(SidebarContext);26 if (!ctx) {27 throw new Error("useSidebar must be used within SidebarProvider");28 }29 return ctx;30}3132export function SidebarProvider({33 children,34 defaultOpen = true,35}: {36 children: ReactNode;37 defaultOpen?: boolean;38}) {39 const [open, setOpen] = useState(defaultOpen);40 const toggle = useCallback(() => setOpen((o) => !o), []);41 const value = useMemo(() => ({ open, setOpen, toggle }), [open]);4243 return (44 <SidebarContext.Provider value={value}>{children}</SidebarContext.Provider>45 );46}4748export function Sidebar({49 className,50 children,51 ...props52}: React.ComponentProps<"aside">) {53 const { open } = useSidebar();54 return (55 <aside56 data-slot="sidebar"57 data-state={open ? "expanded" : "collapsed"}58 className={cn(59 glass,60 "flex h-full min-h-[320px] flex-col overflow-hidden transition-[width] duration-300 ease-out",61 open ? "w-64" : "w-[4.25rem]",62 className,63 )}64 {...props}65 >66 {children}67 </aside>68 );69}7071export function SidebarHeader({72 className,73 ...props74}: React.ComponentProps<"div">) {75 return (76 <div77 data-slot="sidebar-header"78 className={cn(79 "flex h-14 shrink-0 items-center gap-2 border-b border-black/[0.08] dark:border-white/10 px-3",80 className,81 )}82 {...props}83 />84 );85}8687export function SidebarContent({88 className,89 ...props90}: React.ComponentProps<"div">) {91 return (92 <div93 data-slot="sidebar-content"94 className={cn(95 "flex flex-1 flex-col gap-1 overflow-y-auto p-2",96 className,97 )}98 {...props}99 />100 );101}102103export function SidebarFooter({104 className,105 ...props106}: React.ComponentProps<"div">) {107 return (108 <div109 data-slot="sidebar-footer"110 className={cn(111 "mt-auto flex shrink-0 flex-col gap-1 border-t border-black/[0.08] dark:border-white/10 p-2",112 className,113 )}114 {...props}115 />116 );117}118119// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from glasswave
All 60 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | glasswave | Components | Free | 2 deps | |
| Alertalert | glasswave | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | glasswave | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | glasswave | Components | Free | 1 dep | |
| Avataravatar | glasswave | Components | Free | 1 dep | |
| Badgebadge | glasswave | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | glasswave | Components | Free | 2 deps | |
| Buttonbutton | glasswave | Components | Free | 2 deps |
