sidebar
neobrutalism/sidebarFreeComponent
neobrutalism publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by neobrutalism on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://neobrutalism.com/r/sidebar.jsonSource
1"use client"23import * as React from "react"4import { mergeProps } from "@base-ui/react/merge-props"5import { useRender } from "@base-ui/react/use-render"6import { cva, type VariantProps } from "class-variance-authority"7import { PanelLeftIcon } from "lucide-react"89import { cn } from "@/lib/utils"10import { useIsMobile } from "@/hooks/use-mobile"11import { Button } from "@/components/ui/button"12import { Input } from "@/components/ui/input"13import { Separator } from "@/components/ui/separator"14import {15 Sheet,16 SheetContent,17 SheetDescription,18 SheetHeader,19 SheetTitle,20} from "@/components/ui/sheet"21import { Skeleton } from "@/components/ui/skeleton"22import {23 Tooltip,24 TooltipContent,25 TooltipProvider,26 TooltipTrigger,27} from "@/components/ui/tooltip"2829const SIDEBAR_COOKIE_NAME = "sidebar_state"30const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 731const SIDEBAR_WIDTH = "16rem"32const SIDEBAR_WIDTH_MOBILE = "18rem"33const SIDEBAR_WIDTH_ICON = "3rem"34const SIDEBAR_KEYBOARD_SHORTCUT = "b"3536type SidebarContextProps = {37 state: "expanded" | "collapsed"38 open: boolean39 setOpen: (open: boolean) => void40 openMobile: boolean41 setOpenMobile: (open: boolean) => void42 isMobile: boolean43 toggleSidebar: () => void44}4546const SidebarContext = React.createContext<SidebarContextProps | null>(null)4748function useSidebar() {49 const context = React.useContext(SidebarContext)50 if (!context) {51 throw new Error("useSidebar must be used within a SidebarProvider.")52 }5354 return context55}5657function SidebarProvider({58 defaultOpen = true,59 open: openProp,60 onOpenChange: setOpenProp,61 className,62 style,63 children,64 ...props65}: React.ComponentProps<"div"> & {66 defaultOpen?: boolean67 open?: boolean68 onOpenChange?: (open: boolean) => void69}) {70 const isMobile = useIsMobile()71 const [openMobile, setOpenMobile] = React.useState(false)7273 // This is the internal state of the sidebar.74 // We use openProp and setOpenProp for control from outside the component.75 const [_open, _setOpen] = React.useState(defaultOpen)76 const open = openProp ?? _open77 const setOpen = React.useCallback(78 (value: boolean | ((value: boolean) => boolean)) => {79 const openState = typeof value === "function" ? value(open) : value80 if (setOpenProp) {81 setOpenProp(openState)82 } else {83 _setOpen(openState)84 }8586 // This sets the cookie to keep the sidebar state.87// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from neobrutalism
All 54 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | neobrutalism | Components | Free | 2 deps | |
| alertalert | neobrutalism | Components | Free | 2 deps | |
| alert-dialogalert-dialog | neobrutalism | Components | Free | 1 dep | |
| aspect-ratioaspect-ratio | neobrutalism | Components | Free | 1 dep | |
| avataravatar | neobrutalism | Components | Free | 1 dep | |
| badgebadge | neobrutalism | Components | Free | 2 deps | |
| breadcrumbbreadcrumb | neobrutalism | Components | Free | 2 deps | |
| buttonbutton | neobrutalism | Components | Free | 2 deps |
