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