sidebar
ora-ui/sidebarFreeComponent
ora-ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by ora-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ora-ui.com/r/sidebar.jsonSource
1'use client';23import * as React from 'react';4import { Slot } from '@radix-ui/react-slot';56import { cn } from '@/registry/lib/utils';78/* ---------- Context ---------- */910interface SidebarContextValue {11 collapsed: boolean;12 setCollapsed: (collapsed: boolean) => void;13}1415const SidebarContext = React.createContext<SidebarContextValue | null>(null);1617function useSidebar() {18 const context = React.useContext(SidebarContext);19 if (!context) {20 throw new Error('useSidebar must be used within a SidebarProvider');21 }22 return context;23}2425/* ---------- Provider ---------- */2627interface SidebarProviderProps {28 children: React.ReactNode;29 defaultCollapsed?: boolean;30}3132function SidebarProvider({ children, defaultCollapsed = false }: SidebarProviderProps) {33 const [collapsed, setCollapsed] = React.useState(defaultCollapsed);3435 return (36 <SidebarContext.Provider value={{ collapsed, setCollapsed }}>37 {children}38 </SidebarContext.Provider>39 );40}4142/* ---------- Sidebar ---------- */4344interface SidebarProps extends React.HTMLAttributes<HTMLElement> {45 children: React.ReactNode;46}4748function Sidebar({ className, children, ...props }: SidebarProps) {49 const { collapsed } = useSidebar();5051 return (52 <aside53 data-slot="sidebar"54 data-collapsed={collapsed}55 className={cn(56 'flex h-full w-64 shrink-0 flex-col border-r border-line-subtle bg-background',57 collapsed && 'w-0 overflow-hidden',58 className59 )}60 {...props}61 >62 {children}63 </aside>64 );65}6667/* ---------- SidebarHeader ---------- */6869function SidebarHeader({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {70 return (71 <div72 data-slot="sidebar-header"73 className={cn('flex shrink-0 flex-col gap-2 px-3 py-4', className)}74 {...props}75 />76 );77}7879/* ---------- SidebarContent ---------- */8081function SidebarContent({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {82 return (83 <div84 data-slot="sidebar-content"85 className={cn('flex flex-1 flex-col gap-1 overflow-y-auto px-7 py-5', className)}86 {...props}87 />88 );89}9091/* ---------- SidebarFooter ---------- */9293function SidebarFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {94 return (95 <div96 data-slot="sidebar-footer"97 className={cn(98 'flex shrink-0 flex-col gap-2 border-t border-line-subtle px-3 py-4',99 className100 )}101 {...props}102 />103 );104}105106// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from ora-ui
All 31 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | ora-ui | Components | Free | 2 deps | |
| alert-dialogalert-dialog | ora-ui | Components | Free | 1 dep | |
| avataravatar | ora-ui | Components | Free | 1 dep | |
| avatar-groupavatar-group | ora-ui | Components | Free | no deps | |
| badgebadge | ora-ui | Components | Free | 2 deps | |
| buttonbutton | ora-ui | Components | Free | 2 deps | |
| button-groupbutton-group | ora-ui | Components | Free | 2 deps | |
| checkboxcheckbox | ora-ui | Components | Free | 3 deps |
