@aomi-labs/widget-lib 1.0.0 → 1.1.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 (76) hide show
  1. package/dist/accordion.json +18 -0
  2. package/dist/alert.json +17 -0
  3. package/dist/aomi-frame.json +24 -0
  4. package/dist/assistant-thread-list.json +22 -0
  5. package/dist/assistant-thread.json +27 -0
  6. package/dist/assistant-threadlist-sidebar.json +20 -0
  7. package/dist/assistant-tool-fallback.json +20 -0
  8. package/dist/avatar.json +17 -0
  9. package/dist/badge.json +17 -0
  10. package/dist/breadcrumb.json +17 -0
  11. package/dist/button.json +18 -0
  12. package/dist/card.json +15 -0
  13. package/dist/collapsible.json +17 -0
  14. package/dist/command.json +21 -0
  15. package/dist/dialog.json +18 -0
  16. package/dist/drawer.json +17 -0
  17. package/dist/input.json +15 -0
  18. package/dist/label.json +15 -0
  19. package/dist/notification.json +20 -0
  20. package/dist/popover.json +17 -0
  21. package/dist/registry.json +429 -0
  22. package/dist/separator.json +17 -0
  23. package/dist/sheet.json +18 -0
  24. package/dist/sidebar.json +18 -0
  25. package/dist/skeleton.json +15 -0
  26. package/dist/sonner.json +17 -0
  27. package/dist/tooltip.json +17 -0
  28. package/package.json +27 -85
  29. package/src/components/aomi-frame.tsx +221 -0
  30. package/src/components/assistant-ui/attachment.tsx +235 -0
  31. package/src/components/assistant-ui/markdown-text.tsx +228 -0
  32. package/src/components/assistant-ui/thread-list.tsx +106 -0
  33. package/src/components/assistant-ui/thread.tsx +476 -0
  34. package/src/components/assistant-ui/threadlist-sidebar.tsx +66 -0
  35. package/src/components/assistant-ui/tool-fallback.tsx +48 -0
  36. package/src/components/assistant-ui/tooltip-icon-button.tsx +42 -0
  37. package/src/components/control-bar/api-key-input.tsx +122 -0
  38. package/src/components/control-bar/index.tsx +58 -0
  39. package/src/components/control-bar/model-select.tsx +120 -0
  40. package/src/components/control-bar/namespace-select.tsx +117 -0
  41. package/src/components/control-bar/wallet-connect.tsx +75 -0
  42. package/src/components/test/ThreadContextTest.tsx +204 -0
  43. package/src/components/tools/example-tool/ExampleTool.tsx +102 -0
  44. package/src/components/ui/accordion.tsx +58 -0
  45. package/src/components/ui/alert.tsx +62 -0
  46. package/src/components/ui/avatar.tsx +53 -0
  47. package/src/components/ui/badge.tsx +37 -0
  48. package/src/components/ui/breadcrumb.tsx +109 -0
  49. package/src/components/ui/button.tsx +59 -0
  50. package/src/components/ui/card.tsx +86 -0
  51. package/src/components/ui/collapsible.tsx +12 -0
  52. package/src/components/ui/command.tsx +156 -0
  53. package/src/components/ui/dialog.tsx +143 -0
  54. package/src/components/ui/drawer.tsx +118 -0
  55. package/src/components/ui/input.tsx +21 -0
  56. package/src/components/ui/label.tsx +20 -0
  57. package/src/components/ui/notification.tsx +57 -0
  58. package/src/components/ui/popover.tsx +33 -0
  59. package/src/components/ui/separator.tsx +28 -0
  60. package/src/components/ui/sheet.tsx +139 -0
  61. package/src/components/ui/sidebar.tsx +827 -0
  62. package/src/components/ui/skeleton.tsx +15 -0
  63. package/src/components/ui/sonner.tsx +29 -0
  64. package/src/components/ui/tooltip.tsx +61 -0
  65. package/src/hooks/use-mobile.ts +21 -0
  66. package/src/index.ts +26 -0
  67. package/src/registry.ts +218 -0
  68. package/{dist/styles.css → src/themes/default.css} +21 -3
  69. package/src/themes/tokens.config.ts +39 -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,827 @@
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)",
265
+ className,
266
+ )}
267
+ {...props}
268
+ >
269
+ <div
270
+ data-sidebar="sidebar"
271
+ data-slot="sidebar-inner"
272
+ className="
273
+ bg-sidebar
274
+ dark:bg-sidebar
275
+ group-data-[variant=floating]:border-sidebar-border
276
+ flex h-full w-full flex-col
277
+ group-data-[variant=floating]:rounded-lg
278
+ group-data-[variant=floating]:border
279
+ group-data-[variant=floating]:shadow-sm"
280
+ >
281
+ {children}
282
+ </div>
283
+ </div>
284
+ </div>
285
+ );
286
+ }
287
+
288
+ function SidebarTrigger({
289
+ className,
290
+ onClick,
291
+ ...props
292
+ }: React.ComponentProps<typeof Button>) {
293
+ const { toggleSidebar } = useSidebar();
294
+
295
+ return (
296
+ <Button
297
+ data-sidebar="trigger"
298
+ data-slot="sidebar-trigger"
299
+ variant="ghost"
300
+ size="icon"
301
+ className={cn("size-7", className)}
302
+ onClick={(event) => {
303
+ onClick?.(event);
304
+ toggleSidebar();
305
+ }}
306
+ {...props}
307
+ >
308
+ <PanelLeftIcon />
309
+ <span className="sr-only">Toggle Sidebar</span>
310
+ </Button>
311
+ );
312
+ }
313
+
314
+ function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
315
+ const { toggleSidebar, sidebarWidth, setSidebarWidth, setOpen } =
316
+ useSidebar();
317
+ const isDraggingRef = React.useRef(false);
318
+ const startXRef = React.useRef(0);
319
+ const startWidthRef = React.useRef(0);
320
+ const hasDraggedRef = React.useRef(false);
321
+ const rafRef = React.useRef<number | null>(null);
322
+
323
+ const handleMouseDown = React.useCallback(
324
+ (e: React.MouseEvent) => {
325
+ e.preventDefault();
326
+ isDraggingRef.current = true;
327
+ hasDraggedRef.current = false;
328
+ startXRef.current = e.clientX;
329
+ startWidthRef.current = sidebarWidth;
330
+ document.body.style.cursor = "ew-resize";
331
+ document.body.style.userSelect = "none";
332
+ },
333
+ [sidebarWidth],
334
+ );
335
+
336
+ React.useEffect(() => {
337
+ const handleMouseMove = (e: MouseEvent) => {
338
+ if (!isDraggingRef.current) return;
339
+
340
+ // Cancel any pending RAF
341
+ if (rafRef.current) {
342
+ cancelAnimationFrame(rafRef.current);
343
+ }
344
+
345
+ rafRef.current = requestAnimationFrame(() => {
346
+ const deltaX = e.clientX - startXRef.current;
347
+ if (Math.abs(deltaX) > 5) {
348
+ hasDraggedRef.current = true;
349
+ }
350
+
351
+ const rawWidth = startWidthRef.current + deltaX;
352
+
353
+ if (rawWidth < SIDEBAR_MIN_WIDTH) {
354
+ setOpen(false);
355
+ } else {
356
+ setOpen(true);
357
+ setSidebarWidth(Math.min(SIDEBAR_MAX_WIDTH, rawWidth));
358
+ }
359
+ });
360
+ };
361
+
362
+ const handleMouseUp = () => {
363
+ if (!isDraggingRef.current) return;
364
+ isDraggingRef.current = false;
365
+ document.body.style.cursor = "";
366
+ document.body.style.userSelect = "";
367
+ if (rafRef.current) {
368
+ cancelAnimationFrame(rafRef.current);
369
+ }
370
+ };
371
+
372
+ document.addEventListener("mousemove", handleMouseMove);
373
+ document.addEventListener("mouseup", handleMouseUp);
374
+
375
+ return () => {
376
+ document.removeEventListener("mousemove", handleMouseMove);
377
+ document.removeEventListener("mouseup", handleMouseUp);
378
+ };
379
+ }, [setSidebarWidth, setOpen]);
380
+
381
+ const handleClick = React.useCallback(() => {
382
+ if (!hasDraggedRef.current) {
383
+ toggleSidebar();
384
+ }
385
+ }, [toggleSidebar]);
386
+
387
+ return (
388
+ <button
389
+ data-sidebar="rail"
390
+ data-slot="sidebar-rail"
391
+ aria-label="Toggle Sidebar"
392
+ tabIndex={-1}
393
+ onMouseDown={handleMouseDown}
394
+ onClick={handleClick}
395
+ title="Drag to resize, click to toggle"
396
+ className={cn(
397
+ "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",
398
+ "cursor-ew-resize",
399
+ "hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
400
+ "[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
401
+ "[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
402
+ className,
403
+ )}
404
+ {...props}
405
+ />
406
+ );
407
+ }
408
+
409
+ function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
410
+ return (
411
+ <main
412
+ data-slot="sidebar-inset"
413
+ className={cn(
414
+ "bg-background relative flex w-full flex-1 flex-col",
415
+ className,
416
+ )}
417
+ {...props}
418
+ />
419
+ );
420
+ }
421
+
422
+ function SidebarInput({
423
+ className,
424
+ ...props
425
+ }: React.ComponentProps<typeof Input>) {
426
+ return (
427
+ <Input
428
+ data-slot="sidebar-input"
429
+ data-sidebar="input"
430
+ className={cn("bg-background h-8 w-full shadow-none", className)}
431
+ {...props}
432
+ />
433
+ );
434
+ }
435
+
436
+ function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
437
+ return (
438
+ <div
439
+ data-slot="sidebar-header"
440
+ data-sidebar="header"
441
+ className={cn("flex flex-col gap-2 p-2", className)}
442
+ {...props}
443
+ />
444
+ );
445
+ }
446
+
447
+ function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
448
+ return (
449
+ <div
450
+ data-slot="sidebar-footer"
451
+ data-sidebar="footer"
452
+ className={cn("mr-2 flex flex-col gap-2 p-2", className)}
453
+ {...props}
454
+ />
455
+ );
456
+ }
457
+
458
+ function SidebarSeparator({
459
+ className,
460
+ ...props
461
+ }: React.ComponentProps<typeof Separator>) {
462
+ return (
463
+ <Separator
464
+ data-slot="sidebar-separator"
465
+ data-sidebar="separator"
466
+ className={cn("bg-sidebar-border mx-2 w-auto", className)}
467
+ {...props}
468
+ />
469
+ );
470
+ }
471
+
472
+ function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
473
+ return (
474
+ <div
475
+ data-slot="sidebar-content"
476
+ data-sidebar="content"
477
+ className={cn(
478
+ "mr-2 flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
479
+ className,
480
+ )}
481
+ {...props}
482
+ />
483
+ );
484
+ }
485
+
486
+ function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
487
+ return (
488
+ <div
489
+ data-slot="sidebar-group"
490
+ data-sidebar="group"
491
+ className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
492
+ {...props}
493
+ />
494
+ );
495
+ }
496
+
497
+ function SidebarGroupLabel({
498
+ className,
499
+ asChild = false,
500
+ ...props
501
+ }: React.ComponentProps<"div"> & { asChild?: boolean }) {
502
+ const Comp = asChild ? Slot : "div";
503
+
504
+ return (
505
+ <Comp
506
+ data-slot="sidebar-group-label"
507
+ data-sidebar="group-label"
508
+ className={cn(
509
+ "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",
510
+ "group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
511
+ className,
512
+ )}
513
+ {...props}
514
+ />
515
+ );
516
+ }
517
+
518
+ function SidebarGroupAction({
519
+ className,
520
+ asChild = false,
521
+ ...props
522
+ }: React.ComponentProps<"button"> & { asChild?: boolean }) {
523
+ const Comp = asChild ? Slot : "button";
524
+
525
+ return (
526
+ <Comp
527
+ data-slot="sidebar-group-action"
528
+ data-sidebar="group-action"
529
+ className={cn(
530
+ "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",
531
+ // Increases the hit area of the button on mobile.
532
+ "after:absolute after:-inset-2 md:after:hidden",
533
+ "group-data-[collapsible=icon]:hidden",
534
+ className,
535
+ )}
536
+ {...props}
537
+ />
538
+ );
539
+ }
540
+
541
+ function SidebarGroupContent({
542
+ className,
543
+ ...props
544
+ }: React.ComponentProps<"div">) {
545
+ return (
546
+ <div
547
+ data-slot="sidebar-group-content"
548
+ data-sidebar="group-content"
549
+ className={cn("w-full text-sm", className)}
550
+ {...props}
551
+ />
552
+ );
553
+ }
554
+
555
+ function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
556
+ return (
557
+ <ul
558
+ data-slot="sidebar-menu"
559
+ data-sidebar="menu"
560
+ className={cn("flex w-full min-w-0 list-none flex-col gap-1", className)}
561
+ {...props}
562
+ />
563
+ );
564
+ }
565
+
566
+ function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
567
+ return (
568
+ <li
569
+ data-slot="sidebar-menu-item"
570
+ data-sidebar="menu-item"
571
+ className={cn("group/menu-item relative", className)}
572
+ {...props}
573
+ />
574
+ );
575
+ }
576
+
577
+ const sidebarMenuButtonVariants = cva(
578
+ "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",
579
+ {
580
+ variants: {
581
+ variant: {
582
+ default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
583
+ outline:
584
+ "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))]",
585
+ },
586
+ size: {
587
+ default: "h-8 text-sm",
588
+ sm: "h-7 text-xs",
589
+ lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
590
+ },
591
+ },
592
+ defaultVariants: {
593
+ variant: "default",
594
+ size: "default",
595
+ },
596
+ },
597
+ );
598
+
599
+ function SidebarMenuButton({
600
+ asChild = false,
601
+ isActive = false,
602
+ variant = "default",
603
+ size = "default",
604
+ tooltip,
605
+ className,
606
+ ...props
607
+ }: React.ComponentProps<"button"> & {
608
+ asChild?: boolean;
609
+ isActive?: boolean;
610
+ tooltip?: string | React.ComponentProps<typeof TooltipContent>;
611
+ } & VariantProps<typeof sidebarMenuButtonVariants>) {
612
+ const Comp = asChild ? Slot : "button";
613
+ const { isMobile, state } = useSidebar();
614
+
615
+ const button = (
616
+ <Comp
617
+ data-slot="sidebar-menu-button"
618
+ data-sidebar="menu-button"
619
+ data-size={size}
620
+ data-active={isActive}
621
+ className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
622
+ {...props}
623
+ />
624
+ );
625
+
626
+ if (!tooltip) {
627
+ return button;
628
+ }
629
+
630
+ if (typeof tooltip === "string") {
631
+ tooltip = {
632
+ children: tooltip,
633
+ };
634
+ }
635
+
636
+ return (
637
+ <Tooltip>
638
+ <TooltipTrigger asChild>{button}</TooltipTrigger>
639
+ <TooltipContent
640
+ side="right"
641
+ align="center"
642
+ hidden={state !== "collapsed" || isMobile}
643
+ {...tooltip}
644
+ />
645
+ </Tooltip>
646
+ );
647
+ }
648
+
649
+ function SidebarMenuAction({
650
+ className,
651
+ asChild = false,
652
+ showOnHover = false,
653
+ ...props
654
+ }: React.ComponentProps<"button"> & {
655
+ asChild?: boolean;
656
+ showOnHover?: boolean;
657
+ }) {
658
+ const Comp = asChild ? Slot : "button";
659
+
660
+ return (
661
+ <Comp
662
+ data-slot="sidebar-menu-action"
663
+ data-sidebar="menu-action"
664
+ className={cn(
665
+ "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",
666
+ // Increases the hit area of the button on mobile.
667
+ "after:absolute after:-inset-2 md:after:hidden",
668
+ "peer-data-[size=sm]/menu-button:top-1",
669
+ "peer-data-[size=default]/menu-button:top-1.5",
670
+ "peer-data-[size=lg]/menu-button:top-2.5",
671
+ "group-data-[collapsible=icon]:hidden",
672
+ showOnHover &&
673
+ "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",
674
+ className,
675
+ )}
676
+ {...props}
677
+ />
678
+ );
679
+ }
680
+
681
+ function SidebarMenuBadge({
682
+ className,
683
+ ...props
684
+ }: React.ComponentProps<"div">) {
685
+ return (
686
+ <div
687
+ data-slot="sidebar-menu-badge"
688
+ data-sidebar="menu-badge"
689
+ className={cn(
690
+ "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",
691
+ "peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
692
+ "peer-data-[size=sm]/menu-button:top-1",
693
+ "peer-data-[size=default]/menu-button:top-1.5",
694
+ "peer-data-[size=lg]/menu-button:top-2.5",
695
+ "group-data-[collapsible=icon]:hidden",
696
+ className,
697
+ )}
698
+ {...props}
699
+ />
700
+ );
701
+ }
702
+
703
+ function SidebarMenuSkeleton({
704
+ className,
705
+ showIcon = false,
706
+ ...props
707
+ }: React.ComponentProps<"div"> & {
708
+ showIcon?: boolean;
709
+ }) {
710
+ // Random width between 50 to 90%.
711
+ const width = React.useMemo(() => {
712
+ return `${Math.floor(Math.random() * 40) + 50}%`;
713
+ }, []);
714
+
715
+ return (
716
+ <div
717
+ data-slot="sidebar-menu-skeleton"
718
+ data-sidebar="menu-skeleton"
719
+ className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
720
+ {...props}
721
+ >
722
+ {showIcon && (
723
+ <Skeleton
724
+ className="size-4 rounded-md"
725
+ data-sidebar="menu-skeleton-icon"
726
+ />
727
+ )}
728
+ <Skeleton
729
+ className="max-w-(--skeleton-width) h-4 flex-1"
730
+ data-sidebar="menu-skeleton-text"
731
+ style={
732
+ {
733
+ "--skeleton-width": width,
734
+ } as React.CSSProperties
735
+ }
736
+ />
737
+ </div>
738
+ );
739
+ }
740
+
741
+ function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
742
+ return (
743
+ <ul
744
+ data-slot="sidebar-menu-sub"
745
+ data-sidebar="menu-sub"
746
+ className={cn(
747
+ "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",
748
+ "group-data-[collapsible=icon]:hidden",
749
+ className,
750
+ )}
751
+ {...props}
752
+ />
753
+ );
754
+ }
755
+
756
+ function SidebarMenuSubItem({
757
+ className,
758
+ ...props
759
+ }: React.ComponentProps<"li">) {
760
+ return (
761
+ <li
762
+ data-slot="sidebar-menu-sub-item"
763
+ data-sidebar="menu-sub-item"
764
+ className={cn("group/menu-sub-item relative", className)}
765
+ {...props}
766
+ />
767
+ );
768
+ }
769
+
770
+ function SidebarMenuSubButton({
771
+ asChild = false,
772
+ size = "md",
773
+ isActive = false,
774
+ className,
775
+ ...props
776
+ }: React.ComponentProps<"a"> & {
777
+ asChild?: boolean;
778
+ size?: "sm" | "md";
779
+ isActive?: boolean;
780
+ }) {
781
+ const Comp = asChild ? Slot : "a";
782
+
783
+ return (
784
+ <Comp
785
+ data-slot="sidebar-menu-sub-button"
786
+ data-sidebar="menu-sub-button"
787
+ data-size={size}
788
+ data-active={isActive}
789
+ className={cn(
790
+ "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",
791
+ "data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
792
+ size === "sm" && "text-xs",
793
+ size === "md" && "text-sm",
794
+ "group-data-[collapsible=icon]:hidden",
795
+ className,
796
+ )}
797
+ {...props}
798
+ />
799
+ );
800
+ }
801
+
802
+ export {
803
+ Sidebar,
804
+ SidebarContent,
805
+ SidebarFooter,
806
+ SidebarGroup,
807
+ SidebarGroupAction,
808
+ SidebarGroupContent,
809
+ SidebarGroupLabel,
810
+ SidebarHeader,
811
+ SidebarInput,
812
+ SidebarInset,
813
+ SidebarMenu,
814
+ SidebarMenuAction,
815
+ SidebarMenuBadge,
816
+ SidebarMenuButton,
817
+ SidebarMenuItem,
818
+ SidebarMenuSkeleton,
819
+ SidebarMenuSub,
820
+ SidebarMenuSubButton,
821
+ SidebarMenuSubItem,
822
+ SidebarProvider,
823
+ SidebarRail,
824
+ SidebarSeparator,
825
+ SidebarTrigger,
826
+ useSidebar,
827
+ };