@aomi-labs/widget-lib 1.0.0 → 1.1.0

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