sidebar
draco-china-github/sidebarFreeComponent
shadcn/ui publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/draco-china/shadcn-pro/main/apps/docs/public/r/styles/radix-sera/sidebar.jsonSource
1"use client"23import * as React from "react"4import { cva, type VariantProps } from "class-variance-authority"5import { Slot } from "radix-ui"67import { useIsMobile } from "@/registry/radix-sera/hooks/use-mobile"8import { cn } from "@/registry/radix-sera/lib/utils"9import { Button } from "@/registry/radix-sera/ui/button"10import { Input } from "@/registry/radix-sera/ui/input"11import { Separator } from "@/registry/radix-sera/ui/separator"12import {13 Sheet,14 SheetContent,15 SheetDescription,16 SheetHeader,17 SheetTitle,18} from "@/registry/radix-sera/ui/sheet"19import { Skeleton } from "@/registry/radix-sera/ui/skeleton"20import {21 Tooltip,22 TooltipContent,23 TooltipTrigger,24} from "@/registry/radix-sera/ui/tooltip"25import { IconPlaceholder } from "@/app/(create)/components/icon-placeholder"2627const SIDEBAR_COOKIE_NAME = "sidebar_state"28const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 729const SIDEBAR_WIDTH = "16rem"30const SIDEBAR_WIDTH_MOBILE = "18rem"31const SIDEBAR_WIDTH_ICON = "3rem"32const SIDEBAR_KEYBOARD_SHORTCUT = "b"3334type SidebarContextProps = {35 state: "expanded" | "collapsed"36 open: boolean37 setOpen: (open: boolean) => void38 openMobile: boolean39 setOpenMobile: (open: boolean) => void40 isMobile: boolean41 toggleSidebar: () => void42}4344const SidebarContext = React.createContext<SidebarContextProps | null>(null)4546function useSidebar() {47 const context = React.useContext(SidebarContext)48 if (!context) {49 throw new Error("useSidebar must be used within a SidebarProvider.")50 }5152 return context53}5455function SidebarProvider({56 defaultOpen = true,57 open: openProp,58 onOpenChange: setOpenProp,59 className,60 style,61 children,62 ...props63}: React.ComponentProps<"div"> & {64 defaultOpen?: boolean65 open?: boolean66 onOpenChange?: (open: boolean) => void67}) {68 const isMobile = useIsMobile()69 const [openMobile, setOpenMobile] = React.useState(false)7071 // This is the internal state of the sidebar.72 // We use openProp and setOpenProp for control from outside the component.73 const [_open, _setOpen] = React.useState(defaultOpen)74 const open = openProp ?? _open75 const setOpen = React.useCallback(76 (value: boolean | ((value: boolean) => boolean)) => {77 const openState = typeof value === "function" ? value(open) : value78 if (setOpenProp) {79 setOpenProp(openState)80 } else {81 _setOpen(openState)82 }8384 // This sets the cookie to keep the sidebar state.85// … truncated
What it pulls in
Other registry items
Files it writes
More from shadcn/ui
All 201 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | shadcn/ui | Components | Free | no deps | |
| alertalert | shadcn/ui | Components | Free | no deps | |
| alert-dialogalert-dialog | shadcn/ui | Components | Free | no deps | |
| aspect-ratioaspect-ratio | shadcn/ui | Components | Free | no deps | |
| avataravatar | shadcn/ui | Components | Free | no deps | |
| badgebadge | shadcn/ui | Components | Free | no deps | |
| breadcrumbbreadcrumb | shadcn/ui | Components | Free | no deps | |
| buttonbutton | shadcn/ui | Components | Free | no deps |
