@openconsole/shadcn 0.2.4 → 0.2.6

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