@blips/ui 0.0.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/index.cjs +1347 -146
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +185 -6
  4. package/dist/index.d.ts +185 -6
  5. package/dist/index.js +1295 -148
  6. package/dist/index.js.map +1 -1
  7. package/package.json +25 -13
  8. package/src/components/accordion.tsx +12 -12
  9. package/src/components/alert-dialog.tsx +25 -24
  10. package/src/components/alert.tsx +11 -11
  11. package/src/components/aspect-ratio.tsx +3 -3
  12. package/src/components/avatar.tsx +11 -11
  13. package/src/components/badge.tsx +6 -6
  14. package/src/components/breadcrumb.tsx +23 -23
  15. package/src/components/button-group.tsx +83 -0
  16. package/src/components/button.tsx +11 -11
  17. package/src/components/calendar.tsx +21 -24
  18. package/src/components/card.tsx +15 -22
  19. package/src/components/carousel.tsx +72 -71
  20. package/src/components/chart.tsx +368 -0
  21. package/src/components/checkbox.tsx +7 -7
  22. package/src/components/collapsible.tsx +6 -6
  23. package/src/components/command.tsx +27 -26
  24. package/src/components/context-menu.tsx +33 -33
  25. package/src/components/dialog.tsx +22 -22
  26. package/src/components/drawer.tsx +21 -21
  27. package/src/components/dropdown-menu.tsx +34 -34
  28. package/src/components/form.tsx +178 -0
  29. package/src/components/hover-card.tsx +8 -8
  30. package/src/components/input-group.tsx +175 -0
  31. package/src/components/input-otp.tsx +16 -16
  32. package/src/components/input.tsx +6 -6
  33. package/src/components/kbd.tsx +28 -0
  34. package/src/components/label.tsx +9 -9
  35. package/src/components/menubar.tsx +36 -36
  36. package/src/components/navigation-menu.tsx +21 -21
  37. package/src/components/pagination.tsx +22 -21
  38. package/src/components/popover.tsx +8 -8
  39. package/src/components/progress.tsx +7 -7
  40. package/src/components/radio-group.tsx +11 -11
  41. package/src/components/resizable.tsx +14 -14
  42. package/src/components/scroll-area.tsx +8 -8
  43. package/src/components/select.tsx +23 -23
  44. package/src/components/separator.tsx +6 -6
  45. package/src/components/sheet.tsx +24 -24
  46. package/src/components/sidebar.tsx +774 -0
  47. package/src/components/skeleton.tsx +3 -3
  48. package/src/components/slider.tsx +6 -6
  49. package/src/components/sonner.tsx +9 -9
  50. package/src/components/spinner.tsx +16 -0
  51. package/src/components/switch.tsx +6 -6
  52. package/src/components/table.tsx +19 -19
  53. package/src/components/tabs.tsx +11 -11
  54. package/src/components/textarea.tsx +6 -6
  55. package/src/components/toggle-group.tsx +15 -14
  56. package/src/components/toggle.tsx +8 -8
  57. package/src/components/tooltip.tsx +10 -10
  58. package/src/globals.css +45 -0
  59. package/src/hooks/use-mobile.tsx +19 -0
  60. package/src/index.ts +78 -0
@@ -0,0 +1,774 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Slot } from "@radix-ui/react-slot"
5
+ import { cva, type VariantProps } from "class-variance-authority"
6
+ import { PanelLeft } from "lucide-react"
7
+
8
+ import { useIsMobile } from "@/hooks/use-mobile"
9
+ import { cn } from "@/lib/utils"
10
+ import { Button } from "@/components/button"
11
+ import { Input } from "@/components/input"
12
+ import { Separator } from "@/components/separator"
13
+ import {
14
+ Sheet,
15
+ SheetContent,
16
+ SheetDescription,
17
+ SheetHeader,
18
+ SheetTitle,
19
+ } from "@/components/sheet"
20
+ import { Skeleton } from "@/components/skeleton"
21
+ import {
22
+ Tooltip,
23
+ TooltipContent,
24
+ TooltipProvider,
25
+ TooltipTrigger,
26
+ } from "@/components/tooltip"
27
+
28
+ const SIDEBAR_COOKIE_NAME = "sidebar_state"
29
+ const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
30
+ const SIDEBAR_WIDTH = "16rem"
31
+ const SIDEBAR_WIDTH_MOBILE = "18rem"
32
+ const SIDEBAR_WIDTH_ICON = "3rem"
33
+ const SIDEBAR_KEYBOARD_SHORTCUT = "b"
34
+
35
+ type SidebarContextProps = {
36
+ state: "expanded" | "collapsed"
37
+ open: boolean
38
+ setOpen: (open: boolean) => void
39
+ openMobile: boolean
40
+ setOpenMobile: (open: boolean) => void
41
+ isMobile: boolean
42
+ toggleSidebar: () => void
43
+ }
44
+
45
+ const SidebarContext = React.createContext<SidebarContextProps | null>(null)
46
+
47
+ function useSidebar() {
48
+ const context = React.useContext(SidebarContext)
49
+ if (!context) {
50
+ throw new Error("useSidebar must be used within a SidebarProvider.")
51
+ }
52
+
53
+ return context
54
+ }
55
+
56
+ const SidebarProvider = React.forwardRef<
57
+ HTMLDivElement,
58
+ React.ComponentProps<"div"> & {
59
+ defaultOpen?: boolean
60
+ open?: boolean
61
+ onOpenChange?: (open: boolean) => void
62
+ }
63
+ >(
64
+ (
65
+ {
66
+ defaultOpen = true,
67
+ open: openProp,
68
+ onOpenChange: setOpenProp,
69
+ className,
70
+ style,
71
+ children,
72
+ ...props
73
+ },
74
+ ref
75
+ ) => {
76
+ const isMobile = useIsMobile()
77
+ const [openMobile, setOpenMobile] = React.useState(false)
78
+
79
+ // This is the internal state of the sidebar.
80
+ // We use openProp and setOpenProp for control from outside the component.
81
+ const [_open, _setOpen] = React.useState(defaultOpen)
82
+ const open = openProp ?? _open
83
+ const setOpen = React.useCallback(
84
+ (value: boolean | ((value: boolean) => boolean)) => {
85
+ const openState = typeof value === "function" ? value(open) : value
86
+ if (setOpenProp) {
87
+ setOpenProp(openState)
88
+ } else {
89
+ _setOpen(openState)
90
+ }
91
+
92
+ // This sets the cookie to keep the sidebar state.
93
+ // biome-ignore lint/suspicious/noDocumentCookie: shadcn/ui pattern for sidebar state persistence
94
+ document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
95
+ },
96
+ [setOpenProp, open]
97
+ )
98
+
99
+ // Helper to toggle the sidebar.
100
+ const toggleSidebar = React.useCallback(() => {
101
+ return isMobile
102
+ ? setOpenMobile((open) => !open)
103
+ : setOpen((open) => !open)
104
+ }, [isMobile, setOpen])
105
+
106
+ // Adds a keyboard shortcut to toggle the sidebar.
107
+ React.useEffect(() => {
108
+ const handleKeyDown = (event: KeyboardEvent) => {
109
+ if (
110
+ event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
111
+ (event.metaKey || event.ctrlKey)
112
+ ) {
113
+ event.preventDefault()
114
+ toggleSidebar()
115
+ }
116
+ }
117
+
118
+ window.addEventListener("keydown", handleKeyDown)
119
+ return () => window.removeEventListener("keydown", handleKeyDown)
120
+ }, [toggleSidebar])
121
+
122
+ // We add a state so that we can do data-state="expanded" or "collapsed".
123
+ // This makes it easier to style the sidebar with Tailwind classes.
124
+ const state = open ? "expanded" : "collapsed"
125
+
126
+ const contextValue = React.useMemo<SidebarContextProps>(
127
+ () => ({
128
+ state,
129
+ open,
130
+ setOpen,
131
+ isMobile,
132
+ openMobile,
133
+ setOpenMobile,
134
+ toggleSidebar,
135
+ }),
136
+ [state, open, setOpen, isMobile, openMobile, toggleSidebar]
137
+ )
138
+
139
+ return (
140
+ <SidebarContext.Provider value={contextValue}>
141
+ <TooltipProvider delayDuration={0}>
142
+ <div
143
+ style={
144
+ {
145
+ "--sidebar-width": SIDEBAR_WIDTH,
146
+ "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
147
+ ...style,
148
+ } as React.CSSProperties
149
+ }
150
+ className={cn(
151
+ "group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",
152
+ className
153
+ )}
154
+ ref={ref}
155
+ {...props}
156
+ >
157
+ {children}
158
+ </div>
159
+ </TooltipProvider>
160
+ </SidebarContext.Provider>
161
+ )
162
+ }
163
+ )
164
+ SidebarProvider.displayName = "SidebarProvider"
165
+
166
+ const Sidebar = React.forwardRef<
167
+ HTMLDivElement,
168
+ React.ComponentProps<"div"> & {
169
+ side?: "left" | "right"
170
+ variant?: "sidebar" | "floating" | "inset"
171
+ collapsible?: "offcanvas" | "icon" | "none"
172
+ }
173
+ >(
174
+ (
175
+ {
176
+ side = "left",
177
+ variant = "sidebar",
178
+ collapsible = "offcanvas",
179
+ className,
180
+ children,
181
+ ...props
182
+ },
183
+ ref
184
+ ) => {
185
+ const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
186
+
187
+ if (collapsible === "none") {
188
+ return (
189
+ <div
190
+ className={cn(
191
+ "flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",
192
+ className
193
+ )}
194
+ ref={ref}
195
+ {...props}
196
+ >
197
+ {children}
198
+ </div>
199
+ )
200
+ }
201
+
202
+ if (isMobile) {
203
+ return (
204
+ <Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
205
+ <SheetContent
206
+ data-sidebar="sidebar"
207
+ data-mobile="true"
208
+ className="w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
209
+ style={
210
+ {
211
+ "--sidebar-width": SIDEBAR_WIDTH_MOBILE,
212
+ } as React.CSSProperties
213
+ }
214
+ side={side}
215
+ >
216
+ <SheetHeader className="sr-only">
217
+ <SheetTitle>Sidebar</SheetTitle>
218
+ <SheetDescription>Displays the mobile sidebar.</SheetDescription>
219
+ </SheetHeader>
220
+ <div className="flex h-full w-full flex-col">{children}</div>
221
+ </SheetContent>
222
+ </Sheet>
223
+ )
224
+ }
225
+
226
+ return (
227
+ <div
228
+ ref={ref}
229
+ className="group peer hidden text-sidebar-foreground md:block"
230
+ data-state={state}
231
+ data-collapsible={state === "collapsed" ? collapsible : ""}
232
+ data-variant={variant}
233
+ data-side={side}
234
+ >
235
+ {/* This is what handles the sidebar gap on desktop */}
236
+ <div
237
+ className={cn(
238
+ "relative w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear",
239
+ "group-data-[collapsible=offcanvas]:w-0",
240
+ "group-data-[side=right]:rotate-180",
241
+ variant === "floating" || variant === "inset"
242
+ ? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]"
243
+ : "group-data-[collapsible=icon]:w-[--sidebar-width-icon]"
244
+ )}
245
+ />
246
+ <div
247
+ className={cn(
248
+ "fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex",
249
+ side === "left"
250
+ ? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
251
+ : "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
252
+ // Adjust the padding for floating and inset variants.
253
+ variant === "floating" || variant === "inset"
254
+ ? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]"
255
+ : "group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",
256
+ className
257
+ )}
258
+ {...props}
259
+ >
260
+ <div
261
+ data-sidebar="sidebar"
262
+ className="flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow"
263
+ >
264
+ {children}
265
+ </div>
266
+ </div>
267
+ </div>
268
+ )
269
+ }
270
+ )
271
+ Sidebar.displayName = "Sidebar"
272
+
273
+ const SidebarTrigger = React.forwardRef<
274
+ React.ElementRef<typeof Button>,
275
+ React.ComponentProps<typeof Button>
276
+ >(({ className, onClick, ...props }, ref) => {
277
+ const { toggleSidebar } = useSidebar()
278
+
279
+ return (
280
+ <Button
281
+ ref={ref}
282
+ data-sidebar="trigger"
283
+ variant="ghost"
284
+ size="icon"
285
+ className={cn("h-7 w-7", className)}
286
+ onClick={(event) => {
287
+ onClick?.(event)
288
+ toggleSidebar()
289
+ }}
290
+ {...props}
291
+ >
292
+ <PanelLeft />
293
+ <span className="sr-only">Toggle Sidebar</span>
294
+ </Button>
295
+ )
296
+ })
297
+ SidebarTrigger.displayName = "SidebarTrigger"
298
+
299
+ const SidebarRail = React.forwardRef<
300
+ HTMLButtonElement,
301
+ React.ComponentProps<"button">
302
+ >(({ className, ...props }, ref) => {
303
+ const { toggleSidebar } = useSidebar()
304
+
305
+ return (
306
+ <button
307
+ ref={ref}
308
+ data-sidebar="rail"
309
+ aria-label="Toggle Sidebar"
310
+ tabIndex={-1}
311
+ onClick={toggleSidebar}
312
+ title="Toggle Sidebar"
313
+ className={cn(
314
+ "absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex",
315
+ "[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize",
316
+ "[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
317
+ "group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar",
318
+ "[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
319
+ "[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
320
+ className
321
+ )}
322
+ {...props}
323
+ />
324
+ )
325
+ })
326
+ SidebarRail.displayName = "SidebarRail"
327
+
328
+ const SidebarInset = React.forwardRef<
329
+ HTMLDivElement,
330
+ React.ComponentProps<"main">
331
+ >(({ className, ...props }, ref) => {
332
+ return (
333
+ <main
334
+ ref={ref}
335
+ className={cn(
336
+ "relative flex w-full flex-1 flex-col bg-background",
337
+ "md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",
338
+ className
339
+ )}
340
+ {...props}
341
+ />
342
+ )
343
+ })
344
+ SidebarInset.displayName = "SidebarInset"
345
+
346
+ const SidebarInput = React.forwardRef<
347
+ React.ElementRef<typeof Input>,
348
+ React.ComponentProps<typeof Input>
349
+ >(({ className, ...props }, ref) => {
350
+ return (
351
+ <Input
352
+ ref={ref}
353
+ data-sidebar="input"
354
+ className={cn(
355
+ "h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",
356
+ className
357
+ )}
358
+ {...props}
359
+ />
360
+ )
361
+ })
362
+ SidebarInput.displayName = "SidebarInput"
363
+
364
+ const SidebarHeader = React.forwardRef<
365
+ HTMLDivElement,
366
+ React.ComponentProps<"div">
367
+ >(({ className, ...props }, ref) => {
368
+ return (
369
+ <div
370
+ ref={ref}
371
+ data-sidebar="header"
372
+ className={cn("flex flex-col gap-2 p-2", className)}
373
+ {...props}
374
+ />
375
+ )
376
+ })
377
+ SidebarHeader.displayName = "SidebarHeader"
378
+
379
+ const SidebarFooter = React.forwardRef<
380
+ HTMLDivElement,
381
+ React.ComponentProps<"div">
382
+ >(({ className, ...props }, ref) => {
383
+ return (
384
+ <div
385
+ ref={ref}
386
+ data-sidebar="footer"
387
+ className={cn("flex flex-col gap-2 p-2", className)}
388
+ {...props}
389
+ />
390
+ )
391
+ })
392
+ SidebarFooter.displayName = "SidebarFooter"
393
+
394
+ const SidebarSeparator = React.forwardRef<
395
+ React.ElementRef<typeof Separator>,
396
+ React.ComponentProps<typeof Separator>
397
+ >(({ className, ...props }, ref) => {
398
+ return (
399
+ <Separator
400
+ ref={ref}
401
+ data-sidebar="separator"
402
+ className={cn("mx-2 w-auto bg-sidebar-border", className)}
403
+ {...props}
404
+ />
405
+ )
406
+ })
407
+ SidebarSeparator.displayName = "SidebarSeparator"
408
+
409
+ const SidebarContent = React.forwardRef<
410
+ HTMLDivElement,
411
+ React.ComponentProps<"div">
412
+ >(({ className, ...props }, ref) => {
413
+ return (
414
+ <div
415
+ ref={ref}
416
+ data-sidebar="content"
417
+ className={cn(
418
+ "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
419
+ className
420
+ )}
421
+ {...props}
422
+ />
423
+ )
424
+ })
425
+ SidebarContent.displayName = "SidebarContent"
426
+
427
+ const SidebarGroup = React.forwardRef<
428
+ HTMLDivElement,
429
+ React.ComponentProps<"div">
430
+ >(({ className, ...props }, ref) => {
431
+ return (
432
+ <div
433
+ ref={ref}
434
+ data-sidebar="group"
435
+ className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
436
+ {...props}
437
+ />
438
+ )
439
+ })
440
+ SidebarGroup.displayName = "SidebarGroup"
441
+
442
+ const SidebarGroupLabel = React.forwardRef<
443
+ HTMLDivElement,
444
+ React.ComponentProps<"div"> & { asChild?: boolean }
445
+ >(({ className, asChild = false, ...props }, ref) => {
446
+ const Comp = asChild ? Slot : "div"
447
+
448
+ return (
449
+ <Comp
450
+ ref={ref}
451
+ data-sidebar="group-label"
452
+ className={cn(
453
+ "flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
454
+ "group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
455
+ className
456
+ )}
457
+ {...props}
458
+ />
459
+ )
460
+ })
461
+ SidebarGroupLabel.displayName = "SidebarGroupLabel"
462
+
463
+ const SidebarGroupAction = React.forwardRef<
464
+ HTMLButtonElement,
465
+ React.ComponentProps<"button"> & { asChild?: boolean }
466
+ >(({ className, asChild = false, ...props }, ref) => {
467
+ const Comp = asChild ? Slot : "button"
468
+
469
+ return (
470
+ <Comp
471
+ ref={ref}
472
+ data-sidebar="group-action"
473
+ className={cn(
474
+ "absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
475
+ // Increases the hit area of the button on mobile.
476
+ "after:absolute after:-inset-2 after:md:hidden",
477
+ "group-data-[collapsible=icon]:hidden",
478
+ className
479
+ )}
480
+ {...props}
481
+ />
482
+ )
483
+ })
484
+ SidebarGroupAction.displayName = "SidebarGroupAction"
485
+
486
+ const SidebarGroupContent = React.forwardRef<
487
+ HTMLDivElement,
488
+ React.ComponentProps<"div">
489
+ >(({ className, ...props }, ref) => (
490
+ <div
491
+ ref={ref}
492
+ data-sidebar="group-content"
493
+ className={cn("w-full text-sm", className)}
494
+ {...props}
495
+ />
496
+ ))
497
+ SidebarGroupContent.displayName = "SidebarGroupContent"
498
+
499
+ const SidebarMenu = React.forwardRef<
500
+ HTMLUListElement,
501
+ React.ComponentProps<"ul">
502
+ >(({ className, ...props }, ref) => (
503
+ <ul
504
+ ref={ref}
505
+ data-sidebar="menu"
506
+ className={cn("flex w-full min-w-0 flex-col gap-1", className)}
507
+ {...props}
508
+ />
509
+ ))
510
+ SidebarMenu.displayName = "SidebarMenu"
511
+
512
+ const SidebarMenuItem = React.forwardRef<
513
+ HTMLLIElement,
514
+ React.ComponentProps<"li">
515
+ >(({ className, ...props }, ref) => (
516
+ <li
517
+ ref={ref}
518
+ data-sidebar="menu-item"
519
+ className={cn("group/menu-item relative", className)}
520
+ {...props}
521
+ />
522
+ ))
523
+ SidebarMenuItem.displayName = "SidebarMenuItem"
524
+
525
+ const sidebarMenuButtonVariants = cva(
526
+ "peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
527
+ {
528
+ variants: {
529
+ variant: {
530
+ default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
531
+ outline:
532
+ "bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
533
+ },
534
+ size: {
535
+ default: "h-8 text-sm",
536
+ sm: "h-7 text-xs",
537
+ lg: "h-12 text-sm group-data-[collapsible=icon]:!p-0",
538
+ },
539
+ },
540
+ defaultVariants: {
541
+ variant: "default",
542
+ size: "default",
543
+ },
544
+ }
545
+ )
546
+
547
+ const SidebarMenuButton = React.forwardRef<
548
+ HTMLButtonElement,
549
+ React.ComponentProps<"button"> & {
550
+ asChild?: boolean
551
+ isActive?: boolean
552
+ tooltip?: string | React.ComponentProps<typeof TooltipContent>
553
+ } & VariantProps<typeof sidebarMenuButtonVariants>
554
+ >(
555
+ (
556
+ {
557
+ asChild = false,
558
+ isActive = false,
559
+ variant = "default",
560
+ size = "default",
561
+ tooltip,
562
+ className,
563
+ ...props
564
+ },
565
+ ref
566
+ ) => {
567
+ const Comp = asChild ? Slot : "button"
568
+ const { isMobile, state } = useSidebar()
569
+
570
+ const button = (
571
+ <Comp
572
+ ref={ref}
573
+ data-sidebar="menu-button"
574
+ data-size={size}
575
+ data-active={isActive}
576
+ className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
577
+ {...props}
578
+ />
579
+ )
580
+
581
+ if (!tooltip) {
582
+ return button
583
+ }
584
+
585
+ if (typeof tooltip === "string") {
586
+ tooltip = {
587
+ children: tooltip,
588
+ }
589
+ }
590
+
591
+ return (
592
+ <Tooltip>
593
+ <TooltipTrigger asChild>{button}</TooltipTrigger>
594
+ <TooltipContent
595
+ side="right"
596
+ align="center"
597
+ hidden={state !== "collapsed" || isMobile}
598
+ {...tooltip}
599
+ />
600
+ </Tooltip>
601
+ )
602
+ }
603
+ )
604
+ SidebarMenuButton.displayName = "SidebarMenuButton"
605
+
606
+ const SidebarMenuAction = React.forwardRef<
607
+ HTMLButtonElement,
608
+ React.ComponentProps<"button"> & {
609
+ asChild?: boolean
610
+ showOnHover?: boolean
611
+ }
612
+ >(({ className, asChild = false, showOnHover = false, ...props }, ref) => {
613
+ const Comp = asChild ? Slot : "button"
614
+
615
+ return (
616
+ <Comp
617
+ ref={ref}
618
+ data-sidebar="menu-action"
619
+ className={cn(
620
+ "absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0",
621
+ // Increases the hit area of the button on mobile.
622
+ "after:absolute after:-inset-2 after:md:hidden",
623
+ "peer-data-[size=sm]/menu-button:top-1",
624
+ "peer-data-[size=default]/menu-button:top-1.5",
625
+ "peer-data-[size=lg]/menu-button:top-2.5",
626
+ "group-data-[collapsible=icon]:hidden",
627
+ showOnHover &&
628
+ "group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",
629
+ className
630
+ )}
631
+ {...props}
632
+ />
633
+ )
634
+ })
635
+ SidebarMenuAction.displayName = "SidebarMenuAction"
636
+
637
+ const SidebarMenuBadge = React.forwardRef<
638
+ HTMLDivElement,
639
+ React.ComponentProps<"div">
640
+ >(({ className, ...props }, ref) => (
641
+ <div
642
+ ref={ref}
643
+ data-sidebar="menu-badge"
644
+ className={cn(
645
+ "pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground",
646
+ "peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
647
+ "peer-data-[size=sm]/menu-button:top-1",
648
+ "peer-data-[size=default]/menu-button:top-1.5",
649
+ "peer-data-[size=lg]/menu-button:top-2.5",
650
+ "group-data-[collapsible=icon]:hidden",
651
+ className
652
+ )}
653
+ {...props}
654
+ />
655
+ ))
656
+ SidebarMenuBadge.displayName = "SidebarMenuBadge"
657
+
658
+ const SidebarMenuSkeleton = React.forwardRef<
659
+ HTMLDivElement,
660
+ React.ComponentProps<"div"> & {
661
+ showIcon?: boolean
662
+ }
663
+ >(({ className, showIcon = false, ...props }, ref) => {
664
+ // Random width between 50 to 90%.
665
+ const width = React.useMemo(() => {
666
+ return `${Math.floor(Math.random() * 40) + 50}%`
667
+ }, [])
668
+
669
+ return (
670
+ <div
671
+ ref={ref}
672
+ data-sidebar="menu-skeleton"
673
+ className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
674
+ {...props}
675
+ >
676
+ {showIcon && (
677
+ <Skeleton
678
+ className="size-4 rounded-md"
679
+ data-sidebar="menu-skeleton-icon"
680
+ />
681
+ )}
682
+ <Skeleton
683
+ className="h-4 max-w-[--skeleton-width] flex-1"
684
+ data-sidebar="menu-skeleton-text"
685
+ style={
686
+ {
687
+ "--skeleton-width": width,
688
+ } as React.CSSProperties
689
+ }
690
+ />
691
+ </div>
692
+ )
693
+ })
694
+ SidebarMenuSkeleton.displayName = "SidebarMenuSkeleton"
695
+
696
+ const SidebarMenuSub = React.forwardRef<
697
+ HTMLUListElement,
698
+ React.ComponentProps<"ul">
699
+ >(({ className, ...props }, ref) => (
700
+ <ul
701
+ ref={ref}
702
+ data-sidebar="menu-sub"
703
+ className={cn(
704
+ "mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5",
705
+ "group-data-[collapsible=icon]:hidden",
706
+ className
707
+ )}
708
+ {...props}
709
+ />
710
+ ))
711
+ SidebarMenuSub.displayName = "SidebarMenuSub"
712
+
713
+ const SidebarMenuSubItem = React.forwardRef<
714
+ HTMLLIElement,
715
+ React.ComponentProps<"li">
716
+ >(({ ...props }, ref) => <li ref={ref} {...props} />)
717
+ SidebarMenuSubItem.displayName = "SidebarMenuSubItem"
718
+
719
+ const SidebarMenuSubButton = React.forwardRef<
720
+ HTMLAnchorElement,
721
+ React.ComponentProps<"a"> & {
722
+ asChild?: boolean
723
+ size?: "sm" | "md"
724
+ isActive?: boolean
725
+ }
726
+ >(({ asChild = false, size = "md", isActive, className, ...props }, ref) => {
727
+ const Comp = asChild ? Slot : "a"
728
+
729
+ return (
730
+ <Comp
731
+ ref={ref}
732
+ data-sidebar="menu-sub-button"
733
+ data-size={size}
734
+ data-active={isActive}
735
+ className={cn(
736
+ "flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",
737
+ "data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
738
+ size === "sm" && "text-xs",
739
+ size === "md" && "text-sm",
740
+ "group-data-[collapsible=icon]:hidden",
741
+ className
742
+ )}
743
+ {...props}
744
+ />
745
+ )
746
+ })
747
+ SidebarMenuSubButton.displayName = "SidebarMenuSubButton"
748
+
749
+ export {
750
+ Sidebar,
751
+ SidebarContent,
752
+ SidebarFooter,
753
+ SidebarGroup,
754
+ SidebarGroupAction,
755
+ SidebarGroupContent,
756
+ SidebarGroupLabel,
757
+ SidebarHeader,
758
+ SidebarInput,
759
+ SidebarInset,
760
+ SidebarMenu,
761
+ SidebarMenuAction,
762
+ SidebarMenuBadge,
763
+ SidebarMenuButton,
764
+ SidebarMenuItem,
765
+ SidebarMenuSkeleton,
766
+ SidebarMenuSub,
767
+ SidebarMenuSubButton,
768
+ SidebarMenuSubItem,
769
+ SidebarProvider,
770
+ SidebarRail,
771
+ SidebarSeparator,
772
+ SidebarTrigger,
773
+ useSidebar,
774
+ }