BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/sidcn/sidebar

Sidebar

sidcn/sidebar
FreeComponent

A beautiful sidebar component

Live preview

live · rendered by the registry
Rendered by sidcn on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://ui.siddhesh.cc/r/sidebar.json

Source

registry/new-york/components/sidebar.tsxui.siddhesh.cc/r/sidebar.json · first 6 KB
1import { cva, type VariantProps } from 'class-variance-authority'
2import Cookies from 'js-cookie'
3import { PanelLeftIcon } from 'lucide-react'
4import { Slot } from 'radix-ui'
5import * as React from 'react'
6import { Button } from '@/components/ui/button'
7import { Input } from '@/components/ui/input'
8import { Separator } from '@/components/ui/separator'
9import {
10 Sheet,
11 SheetContent,
12 SheetDescription,
13 SheetHeader,
14 SheetTitle,
15} from '@/components/ui/sheet'
16import { Skeleton } from '@/components/ui/skeleton'
17import {
18 Tooltip,
19 TooltipContent,
20 TooltipProvider,
21 TooltipTrigger,
22} from '@/components/ui/tooltip'
23import { useIsMobile } from '@/hooks/use-mobile'
24import { cn } from '@/lib/utils'
25
26const SIDEBAR_COOKIE_NAME = 'sidebar_state'
27const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
28const SIDEBAR_WIDTH = '16rem'
29const SIDEBAR_WIDTH_MOBILE = '18rem'
30const SIDEBAR_WIDTH_ICON = '3rem'
31const SIDEBAR_KEYBOARD_SHORTCUT = 'b'
32
33type SidebarContextProps = {
34 state: 'expanded' | 'collapsed'
35 open: boolean
36 setOpen: (open: boolean) => void
37 openMobile: boolean
38 setOpenMobile: (open: boolean) => void
39 isMobile: boolean
40 toggleSidebar: () => void
41}
42
43const SidebarContext = React.createContext<SidebarContextProps | null>(null)
44
45function useSidebar() {
46 const context = React.useContext(SidebarContext)
47 if (!context) {
48 throw new Error('useSidebar must be used within a SidebarProvider.')
49 }
50
51 return context
52}
53
54function SidebarProvider({
55 defaultOpen = true,
56 open: openProp,
57 onOpenChange: setOpenProp,
58 className,
59 style,
60 children,
61 ...props
62}: React.ComponentProps<'div'> & {
63 defaultOpen?: boolean
64 open?: boolean
65 onOpenChange?: (open: boolean) => void
66}) {
67 const isMobile = useIsMobile()
68 const [openMobile, setOpenMobile] = React.useState(false)
69
70 // This is the internal state of the sidebar.
71 // We use openProp and setOpenProp for control from outside the component.
72 const [_open, _setOpen] = React.useState(defaultOpen)
73 const open = openProp ?? _open
74 const setOpen = React.useCallback(
75 (value: boolean | ((value: boolean) => boolean)) => {
76 const openState = typeof value === 'function' ? value(open) : value
77 if (setOpenProp) {
78 setOpenProp(openState)
79 } else {
80 _setOpen(openState)
81 }
82
83 // This sets the cookie to keep the sidebar state.
84 Cookies.set(SIDEBAR_COOKIE_NAME, `${openState}`, {
85// … truncated

What it pulls in

npm packages

  • lucide-react
  • radix-ui
  • js-cookie

Other registry items

  • https://ui.siddhesh.cc/r/button.json

Files it writes

  • registry/new-york/components/sidebar.tsx

Facts

Registry
sidcn
Type
registry:component
Access
Free
Files written
1
Licence
the repository states none
First indexed
2026-08-01
Last confirmed
2 days ago

Go to the source

Docs on sidcn ui.siddhesh.cc Siddhesh-Agarwal/sid-cn on GitHub Raw registry item This item as JSON

More from sidcn

All 14 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
BadgebadgesidcnComponentsFree3 deps
ButtonbuttonsidcnComponentsFree2 deps
Data Tabledata-tablesidcnComponentsFree2 deps
Date Inputdate-inputsidcnComponentsFree1 dep
Date Time Inputdate-time-inputsidcnComponentsFree2 deps
IconsiconssidcnComponentsFreeno deps
Package Manager Commandpackage-manager-commandsidcnComponentsFreeno deps
SonnersonnersidcnComponentsFree2 deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex