@djangocfg/ui-nextjs 1.4.45

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 (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +152 -0
  3. package/package.json +110 -0
  4. package/src/animations/AnimatedBackground.tsx +645 -0
  5. package/src/animations/index.ts +2 -0
  6. package/src/blocks/ArticleCard.tsx +94 -0
  7. package/src/blocks/ArticleList.tsx +95 -0
  8. package/src/blocks/CTASection.tsx +136 -0
  9. package/src/blocks/FeatureSection.tsx +104 -0
  10. package/src/blocks/Hero.tsx +102 -0
  11. package/src/blocks/NewsletterSection.tsx +119 -0
  12. package/src/blocks/StatsSection.tsx +103 -0
  13. package/src/blocks/SuperHero.tsx +328 -0
  14. package/src/blocks/TestimonialSection.tsx +122 -0
  15. package/src/blocks/index.ts +9 -0
  16. package/src/components/README.md +2018 -0
  17. package/src/components/breadcrumb-navigation.tsx +127 -0
  18. package/src/components/breadcrumb.tsx +132 -0
  19. package/src/components/button-download.tsx +275 -0
  20. package/src/components/dropdown-menu.tsx +219 -0
  21. package/src/components/index.ts +86 -0
  22. package/src/components/markdown/MarkdownMessage.tsx +338 -0
  23. package/src/components/markdown/index.ts +5 -0
  24. package/src/components/menubar.tsx +274 -0
  25. package/src/components/multi-select-pro/async.tsx +608 -0
  26. package/src/components/multi-select-pro/helpers.tsx +84 -0
  27. package/src/components/multi-select-pro/index.tsx +622 -0
  28. package/src/components/navigation-menu.tsx +153 -0
  29. package/src/components/pagination-static.tsx +348 -0
  30. package/src/components/pagination.tsx +138 -0
  31. package/src/components/phone-input.tsx +276 -0
  32. package/src/components/sidebar.tsx +866 -0
  33. package/src/components/sonner.tsx +31 -0
  34. package/src/components/ssr-pagination.tsx +237 -0
  35. package/src/hooks/index.ts +19 -0
  36. package/src/hooks/useCfgRouter.ts +153 -0
  37. package/src/hooks/useLocalStorage.ts +221 -0
  38. package/src/hooks/useQueryParams.ts +73 -0
  39. package/src/hooks/useSessionStorage.ts +188 -0
  40. package/src/hooks/useTheme.ts +57 -0
  41. package/src/index.ts +24 -0
  42. package/src/lib/index.ts +2 -0
  43. package/src/styles/index.css +2 -0
  44. package/src/theme/ForceTheme.tsx +115 -0
  45. package/src/theme/ThemeProvider.tsx +82 -0
  46. package/src/theme/ThemeToggle.tsx +52 -0
  47. package/src/theme/index.ts +3 -0
  48. package/src/tools/JsonForm/JsonSchemaForm.tsx +199 -0
  49. package/src/tools/JsonForm/examples/BotConfigExample.tsx +245 -0
  50. package/src/tools/JsonForm/examples/RealBotConfigExample.tsx +157 -0
  51. package/src/tools/JsonForm/index.ts +46 -0
  52. package/src/tools/JsonForm/templates/ArrayFieldItemTemplate.tsx +46 -0
  53. package/src/tools/JsonForm/templates/ArrayFieldTemplate.tsx +73 -0
  54. package/src/tools/JsonForm/templates/BaseInputTemplate.tsx +106 -0
  55. package/src/tools/JsonForm/templates/ErrorListTemplate.tsx +34 -0
  56. package/src/tools/JsonForm/templates/FieldTemplate.tsx +61 -0
  57. package/src/tools/JsonForm/templates/ObjectFieldTemplate.tsx +43 -0
  58. package/src/tools/JsonForm/templates/index.ts +12 -0
  59. package/src/tools/JsonForm/types.ts +83 -0
  60. package/src/tools/JsonForm/utils.ts +212 -0
  61. package/src/tools/JsonForm/widgets/CheckboxWidget.tsx +36 -0
  62. package/src/tools/JsonForm/widgets/NumberWidget.tsx +88 -0
  63. package/src/tools/JsonForm/widgets/SelectWidget.tsx +100 -0
  64. package/src/tools/JsonForm/widgets/SwitchWidget.tsx +34 -0
  65. package/src/tools/JsonForm/widgets/TextWidget.tsx +95 -0
  66. package/src/tools/JsonForm/widgets/index.ts +12 -0
  67. package/src/tools/JsonTree/index.tsx +252 -0
  68. package/src/tools/LottiePlayer/LottiePlayer.client.tsx +212 -0
  69. package/src/tools/LottiePlayer/index.tsx +54 -0
  70. package/src/tools/LottiePlayer/types.ts +108 -0
  71. package/src/tools/LottiePlayer/useLottie.ts +163 -0
  72. package/src/tools/Mermaid/Mermaid.client.tsx +341 -0
  73. package/src/tools/Mermaid/index.tsx +40 -0
  74. package/src/tools/OpenapiViewer/components/EndpointInfo.tsx +144 -0
  75. package/src/tools/OpenapiViewer/components/EndpointsLibrary.tsx +255 -0
  76. package/src/tools/OpenapiViewer/components/PlaygroundLayout.tsx +123 -0
  77. package/src/tools/OpenapiViewer/components/PlaygroundStepper.tsx +98 -0
  78. package/src/tools/OpenapiViewer/components/RequestBuilder.tsx +164 -0
  79. package/src/tools/OpenapiViewer/components/RequestParametersForm.tsx +253 -0
  80. package/src/tools/OpenapiViewer/components/ResponseViewer.tsx +169 -0
  81. package/src/tools/OpenapiViewer/components/VersionSelector.tsx +64 -0
  82. package/src/tools/OpenapiViewer/components/index.ts +14 -0
  83. package/src/tools/OpenapiViewer/constants.ts +39 -0
  84. package/src/tools/OpenapiViewer/context/PlaygroundContext.tsx +338 -0
  85. package/src/tools/OpenapiViewer/hooks/index.ts +8 -0
  86. package/src/tools/OpenapiViewer/hooks/useMobile.ts +10 -0
  87. package/src/tools/OpenapiViewer/hooks/useOpenApiSchema.ts +203 -0
  88. package/src/tools/OpenapiViewer/index.tsx +36 -0
  89. package/src/tools/OpenapiViewer/types.ts +152 -0
  90. package/src/tools/OpenapiViewer/utils/apiKeyManager.ts +149 -0
  91. package/src/tools/OpenapiViewer/utils/formatters.ts +71 -0
  92. package/src/tools/OpenapiViewer/utils/index.ts +9 -0
  93. package/src/tools/OpenapiViewer/utils/versionManager.ts +161 -0
  94. package/src/tools/PrettyCode/PrettyCode.client.tsx +217 -0
  95. package/src/tools/PrettyCode/index.tsx +43 -0
  96. package/src/tools/VideoPlayer/README.md +239 -0
  97. package/src/tools/VideoPlayer/VideoControls.tsx +138 -0
  98. package/src/tools/VideoPlayer/VideoPlayer.tsx +230 -0
  99. package/src/tools/VideoPlayer/index.ts +9 -0
  100. package/src/tools/VideoPlayer/types.ts +62 -0
  101. package/src/tools/index.ts +43 -0
@@ -0,0 +1,866 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Slot } from "@radix-ui/react-slot"
5
+ import { VariantProps, cva } from "class-variance-authority"
6
+ import { useIsMobile } from "@djangocfg/ui-core/hooks"
7
+ import { cn } from "@djangocfg/ui-core/lib"
8
+ import {
9
+ Button,
10
+ Input,
11
+ Separator,
12
+ Sheet,
13
+ SheetContent,
14
+ SheetDescription,
15
+ SheetHeader,
16
+ SheetTitle,
17
+ Skeleton,
18
+ Tooltip,
19
+ TooltipContent,
20
+ TooltipProvider,
21
+ TooltipTrigger,
22
+ } from "@djangocfg/ui-core/components"
23
+ import { ViewVerticalIcon } from "@radix-ui/react-icons"
24
+ import Link from "next/link"
25
+
26
+ const SIDEBAR_COOKIE_NAME = "sidebar_state"
27
+ const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
28
+ const SIDEBAR_WIDTH = "16rem"
29
+ const SIDEBAR_WIDTH_MOBILE = "min(80vw, 320px)"
30
+ const SIDEBAR_WIDTH_ICON = "3rem"
31
+ const SIDEBAR_KEYBOARD_SHORTCUT = "b"
32
+
33
+ type SidebarContextProps = {
34
+ state: "expanded" | "collapsed"
35
+ open: boolean
36
+ setOpen: (open: boolean) => void
37
+ openMobile: boolean
38
+ setOpenMobile: (open: boolean) => void
39
+ isMobile: boolean
40
+ toggleSidebar: () => void
41
+ }
42
+
43
+ const SidebarContext = React.createContext<SidebarContextProps | null>(null)
44
+
45
+ function useSidebar() {
46
+ const context = React.useContext(SidebarContext)
47
+ if (!context) {
48
+ throw new Error("useSidebar must be used within a SidebarProvider.")
49
+ }
50
+
51
+ return context
52
+ }
53
+
54
+ const SidebarProvider = React.forwardRef<
55
+ HTMLDivElement,
56
+ React.ComponentProps<"div"> & {
57
+ defaultOpen?: boolean
58
+ open?: boolean
59
+ onOpenChange?: (open: boolean) => void
60
+ }
61
+ >(
62
+ (
63
+ {
64
+ defaultOpen = true,
65
+ open: openProp,
66
+ onOpenChange: setOpenProp,
67
+ className,
68
+ style,
69
+ children,
70
+ ...props
71
+ },
72
+ ref
73
+ ) => {
74
+ const isMobile = useIsMobile()
75
+ const [openMobile, setOpenMobile] = React.useState(false)
76
+
77
+ // This is the internal state of the sidebar.
78
+ // We use openProp and setOpenProp for control from outside the component.
79
+ const [_open, _setOpen] = React.useState(defaultOpen)
80
+ const open = openProp ?? _open
81
+ const setOpen = React.useCallback(
82
+ (value: boolean | ((value: boolean) => boolean)) => {
83
+ const openState = typeof value === "function" ? value(open) : value
84
+ if (setOpenProp) {
85
+ setOpenProp(openState)
86
+ } else {
87
+ _setOpen(openState)
88
+ }
89
+
90
+ // This sets the cookie to keep the sidebar state.
91
+ document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
92
+ },
93
+ [setOpenProp, open]
94
+ )
95
+
96
+ // Helper to toggle the sidebar.
97
+ const toggleSidebar = React.useCallback(() => {
98
+ return isMobile
99
+ ? setOpenMobile((open) => !open)
100
+ : 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
+ }),
133
+ [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
134
+ )
135
+
136
+ return (
137
+ <SidebarContext.Provider value={contextValue}>
138
+ <TooltipProvider delayDuration={0}>
139
+ <div
140
+ style={
141
+ {
142
+ "--sidebar-width": SIDEBAR_WIDTH,
143
+ "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
144
+ ...style,
145
+ } as React.CSSProperties
146
+ }
147
+ className={cn(
148
+ "group/sidebar-wrapper flex min-h-svh w-full has-[&_[data-variant=inset]]:bg-sidebar",
149
+ className
150
+ )}
151
+ ref={ref}
152
+ {...props}
153
+ >
154
+ {children}
155
+ </div>
156
+ </TooltipProvider>
157
+ </SidebarContext.Provider>
158
+ )
159
+ }
160
+ )
161
+ SidebarProvider.displayName = "SidebarProvider"
162
+
163
+ const Sidebar = React.forwardRef<
164
+ HTMLDivElement,
165
+ React.ComponentProps<"div"> & {
166
+ side?: "left" | "right"
167
+ variant?: "sidebar" | "floating" | "inset"
168
+ collapsible?: "offcanvas" | "icon" | "none"
169
+ }
170
+ >(
171
+ (
172
+ {
173
+ side = "left",
174
+ variant = "sidebar",
175
+ collapsible = "offcanvas",
176
+ className,
177
+ children,
178
+ ...props
179
+ },
180
+ ref
181
+ ) => {
182
+ const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
183
+
184
+ if (collapsible === "none") {
185
+ return (
186
+ <div
187
+ className={cn(
188
+ "flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",
189
+ className
190
+ )}
191
+ ref={ref}
192
+ {...props}
193
+ >
194
+ {children}
195
+ </div>
196
+ )
197
+ }
198
+
199
+ if (isMobile) {
200
+ return (
201
+ <Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
202
+ <SheetContent
203
+ data-sidebar="sidebar"
204
+ data-mobile="true"
205
+ className="!w-[--sidebar-width] p-0 text-sidebar-foreground [&>button]:hidden"
206
+ style={
207
+ {
208
+ "--sidebar-width": SIDEBAR_WIDTH_MOBILE,
209
+ backgroundColor: "hsl(var(--sidebar-background))",
210
+ } as React.CSSProperties
211
+ }
212
+ side={side}
213
+ >
214
+ <SheetHeader className="sr-only">
215
+ <SheetTitle>Sidebar</SheetTitle>
216
+ <SheetDescription>Displays the mobile sidebar.</SheetDescription>
217
+ </SheetHeader>
218
+ <div className="flex h-full w-full flex-col" style={{ backgroundColor: "hsl(var(--sidebar-background))" }}>{children}</div>
219
+ </SheetContent>
220
+ </Sheet>
221
+ )
222
+ }
223
+
224
+ // Calculate gap width based on state
225
+ const getGapWidth = () => {
226
+ if (state === "collapsed") {
227
+ if (collapsible === "offcanvas") return "0"
228
+ if (collapsible === "icon") {
229
+ return variant === "floating" || variant === "inset"
230
+ ? "calc(var(--sidebar-width-icon) + 1rem)"
231
+ : "var(--sidebar-width-icon)"
232
+ }
233
+ }
234
+ return "var(--sidebar-width)"
235
+ }
236
+
237
+ // Calculate fixed sidebar width based on state
238
+ const getFixedWidth = () => {
239
+ if (state === "collapsed" && collapsible === "icon") {
240
+ return variant === "floating" || variant === "inset"
241
+ ? "calc(var(--sidebar-width-icon) + 1rem + 2px)"
242
+ : "var(--sidebar-width-icon)"
243
+ }
244
+ return "var(--sidebar-width)"
245
+ }
246
+
247
+ return (
248
+ <div
249
+ ref={ref}
250
+ className="group peer hidden text-sidebar-foreground md:block"
251
+ data-state={state}
252
+ data-collapsible={collapsible}
253
+ data-variant={variant}
254
+ data-side={side}
255
+ >
256
+ {/* This is what handles the sidebar gap on desktop */}
257
+ <div
258
+ className={cn(
259
+ "relative h-full bg-transparent transition-[width] duration-200 ease-linear",
260
+ side === "right" && "rotate-180"
261
+ )}
262
+ style={{
263
+ width: getGapWidth()
264
+ }}
265
+ />
266
+ <div
267
+ className={cn(
268
+ "fixed inset-y-0 z-10 hidden h-svh transition-[left,right,width] duration-200 ease-linear md:flex",
269
+ side === "left"
270
+ ? state === "collapsed" && collapsible === "offcanvas"
271
+ ? "left-[calc(var(--sidebar-width)*-1)]"
272
+ : "left-0"
273
+ : state === "collapsed" && collapsible === "offcanvas"
274
+ ? "right-[calc(var(--sidebar-width)*-1)]"
275
+ : "right-0",
276
+ // Adjust the padding for floating and inset variants.
277
+ variant === "floating" || variant === "inset"
278
+ ? "p-2"
279
+ : cn(
280
+ side === "left" && "border-r",
281
+ side === "right" && "border-l"
282
+ ),
283
+ className
284
+ )}
285
+ style={{
286
+ width: getFixedWidth()
287
+ }}
288
+ {...props}
289
+ >
290
+ <div
291
+ data-sidebar="sidebar"
292
+ className={cn(
293
+ "flex h-full w-full flex-col bg-sidebar",
294
+ variant === "floating" && "rounded-lg border border-sidebar-border shadow"
295
+ )}
296
+ >
297
+ {children}
298
+ </div>
299
+ </div>
300
+ </div>
301
+ )
302
+ }
303
+ )
304
+ Sidebar.displayName = "Sidebar"
305
+
306
+ const SidebarTrigger = React.forwardRef<
307
+ React.ElementRef<typeof Button>,
308
+ React.ComponentProps<typeof Button>
309
+ >(({ className, onClick, ...props }, ref) => {
310
+ const { toggleSidebar } = useSidebar()
311
+
312
+ return (
313
+ <Button
314
+ ref={ref}
315
+ data-sidebar="trigger"
316
+ variant="ghost"
317
+ size="icon"
318
+ className={cn("h-7 w-7", className)}
319
+ onClick={(event) => {
320
+ onClick?.(event)
321
+ toggleSidebar()
322
+ }}
323
+ {...props}
324
+ >
325
+ <ViewVerticalIcon />
326
+ <span className="sr-only">Toggle Sidebar</span>
327
+ </Button>
328
+ )
329
+ })
330
+ SidebarTrigger.displayName = "SidebarTrigger"
331
+
332
+ const SidebarRail = React.forwardRef<
333
+ HTMLButtonElement,
334
+ React.ComponentProps<"button">
335
+ >(({ className, ...props }, ref) => {
336
+ const { toggleSidebar } = useSidebar()
337
+
338
+ return (
339
+ <button
340
+ ref={ref}
341
+ data-sidebar="rail"
342
+ aria-label="Toggle Sidebar"
343
+ tabIndex={-1}
344
+ onClick={toggleSidebar}
345
+ title="Toggle Sidebar"
346
+ className={cn(
347
+ "absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex",
348
+ "group-data-[side=left]:cursor-w-resize group-data-[side=right]:cursor-e-resize",
349
+ "group-data-[side=left]:group-data-[state=collapsed]:cursor-e-resize group-data-[side=right]:group-data-[state=collapsed]:cursor-w-resize",
350
+ "group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar",
351
+ "group-data-[side=left]:group-data-[collapsible=offcanvas]:-right-2",
352
+ "group-data-[side=right]:group-data-[collapsible=offcanvas]:-left-2",
353
+ className
354
+ )}
355
+ {...props}
356
+ />
357
+ )
358
+ })
359
+ SidebarRail.displayName = "SidebarRail"
360
+
361
+ const SidebarInset = React.forwardRef<
362
+ HTMLDivElement,
363
+ React.ComponentProps<"main">
364
+ >(({ className, ...props }, ref) => {
365
+ return (
366
+ <main
367
+ ref={ref}
368
+ className={cn(
369
+ "relative flex w-full flex-1 flex-col bg-background",
370
+ "md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",
371
+ className
372
+ )}
373
+ {...props}
374
+ />
375
+ )
376
+ })
377
+ SidebarInset.displayName = "SidebarInset"
378
+
379
+ const SidebarInput = React.forwardRef<
380
+ React.ElementRef<typeof Input>,
381
+ React.ComponentProps<typeof Input>
382
+ >(({ className, ...props }, ref) => {
383
+ return (
384
+ <Input
385
+ ref={ref}
386
+ data-sidebar="input"
387
+ className={cn(
388
+ "h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",
389
+ className
390
+ )}
391
+ {...props}
392
+ />
393
+ )
394
+ })
395
+ SidebarInput.displayName = "SidebarInput"
396
+
397
+ const SidebarHeader = React.forwardRef<
398
+ HTMLDivElement,
399
+ React.ComponentProps<"div">
400
+ >(({ className, style, ...props }, ref) => {
401
+ const { state } = useSidebar()
402
+
403
+ // Remove horizontal padding in collapsed state
404
+ const headerStyle = state === "collapsed" ? {
405
+ paddingLeft: '0',
406
+ paddingRight: '0',
407
+ paddingTop: '0.5rem',
408
+ paddingBottom: '0.5rem',
409
+ transition: 'padding 200ms ease-in-out',
410
+ ...style
411
+ } : {
412
+ transition: 'padding 200ms ease-in-out',
413
+ ...style
414
+ }
415
+
416
+ return (
417
+ <div
418
+ ref={ref}
419
+ data-sidebar="header"
420
+ className={cn("flex flex-col gap-2 p-2", className)}
421
+ style={headerStyle}
422
+ {...props}
423
+ />
424
+ )
425
+ })
426
+ SidebarHeader.displayName = "SidebarHeader"
427
+
428
+ const SidebarFooter = React.forwardRef<
429
+ HTMLDivElement,
430
+ React.ComponentProps<"div">
431
+ >(({ className, ...props }, ref) => {
432
+ return (
433
+ <div
434
+ ref={ref}
435
+ data-sidebar="footer"
436
+ className={cn("flex flex-col gap-2 p-2", className)}
437
+ {...props}
438
+ />
439
+ )
440
+ })
441
+ SidebarFooter.displayName = "SidebarFooter"
442
+
443
+ const SidebarSeparator = React.forwardRef<
444
+ React.ElementRef<typeof Separator>,
445
+ React.ComponentProps<typeof Separator>
446
+ >(({ className, ...props }, ref) => {
447
+ return (
448
+ <Separator
449
+ ref={ref}
450
+ data-sidebar="separator"
451
+ className={cn("mx-2 w-auto bg-sidebar-border", className)}
452
+ {...props}
453
+ />
454
+ )
455
+ })
456
+ SidebarSeparator.displayName = "SidebarSeparator"
457
+
458
+ const SidebarContent = React.forwardRef<
459
+ HTMLDivElement,
460
+ React.ComponentProps<"div">
461
+ >(({ className, ...props }, ref) => {
462
+ return (
463
+ <div
464
+ ref={ref}
465
+ data-sidebar="content"
466
+ className={cn(
467
+ "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[state=collapsed]:group-data-[collapsible=icon]:overflow-hidden",
468
+ className
469
+ )}
470
+ {...props}
471
+ />
472
+ )
473
+ })
474
+ SidebarContent.displayName = "SidebarContent"
475
+
476
+ const SidebarGroup = React.forwardRef<
477
+ HTMLDivElement,
478
+ React.ComponentProps<"div">
479
+ >(({ className, ...props }, ref) => {
480
+ return (
481
+ <div
482
+ ref={ref}
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
+ SidebarGroup.displayName = "SidebarGroup"
490
+
491
+ const SidebarGroupLabel = React.forwardRef<
492
+ HTMLDivElement,
493
+ React.ComponentProps<"div"> & { asChild?: boolean }
494
+ >(({ className, asChild = false, ...props }, ref) => {
495
+ const Comp = asChild ? Slot : "div"
496
+
497
+ return (
498
+ <Comp
499
+ ref={ref}
500
+ data-sidebar="group-label"
501
+ className={cn(
502
+ "flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider outline-none ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
503
+ "group-data-[state=collapsed]:group-data-[collapsible=icon]:-mt-8 group-data-[state=collapsed]:group-data-[collapsible=icon]:opacity-0",
504
+ className
505
+ )}
506
+ {...props}
507
+ />
508
+ )
509
+ })
510
+ SidebarGroupLabel.displayName = "SidebarGroupLabel"
511
+
512
+ const SidebarGroupAction = React.forwardRef<
513
+ HTMLButtonElement,
514
+ React.ComponentProps<"button"> & { asChild?: boolean }
515
+ >(({ className, asChild = false, ...props }, ref) => {
516
+ const Comp = asChild ? Slot : "button"
517
+
518
+ return (
519
+ <Comp
520
+ ref={ref}
521
+ data-sidebar="group-action"
522
+ className={cn(
523
+ "absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
524
+ // Increases the hit area of the button on mobile.
525
+ "after:absolute after:-inset-2 after:md:hidden",
526
+ "group-data-[state=collapsed]:group-data-[collapsible=icon]:hidden",
527
+ className
528
+ )}
529
+ {...props}
530
+ />
531
+ )
532
+ })
533
+ SidebarGroupAction.displayName = "SidebarGroupAction"
534
+
535
+ const SidebarGroupContent = React.forwardRef<
536
+ HTMLDivElement,
537
+ React.ComponentProps<"div">
538
+ >(({ className, ...props }, ref) => (
539
+ <div
540
+ ref={ref}
541
+ data-sidebar="group-content"
542
+ className={cn("w-full text-sm", className)}
543
+ {...props}
544
+ />
545
+ ))
546
+ SidebarGroupContent.displayName = "SidebarGroupContent"
547
+
548
+ const SidebarMenu = React.forwardRef<
549
+ HTMLUListElement,
550
+ React.ComponentProps<"ul">
551
+ >(({ className, ...props }, ref) => (
552
+ <ul
553
+ ref={ref}
554
+ data-sidebar="menu"
555
+ className={cn("flex w-full min-w-0 flex-col gap-1", className)}
556
+ {...props}
557
+ />
558
+ ))
559
+ SidebarMenu.displayName = "SidebarMenu"
560
+
561
+ const SidebarMenuItem = React.forwardRef<
562
+ HTMLLIElement,
563
+ React.ComponentProps<"li">
564
+ >(({ className, ...props }, ref) => (
565
+ <li
566
+ ref={ref}
567
+ data-sidebar="menu-item"
568
+ className={cn("group/menu-item relative", className)}
569
+ {...props}
570
+ />
571
+ ))
572
+ SidebarMenuItem.displayName = "SidebarMenuItem"
573
+
574
+ const sidebarMenuButtonVariants = cva(
575
+ "peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[&_[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-muted-foreground [&>svg]:opacity-70 data-[active=true]:[&>svg]:text-sidebar-accent-foreground data-[active=true]:[&>svg]:opacity-100 hover:[&>svg]:text-sidebar-accent-foreground hover:[&>svg]:opacity-100",
576
+ {
577
+ variants: {
578
+ variant: {
579
+ default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
580
+ outline:
581
+ "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))]",
582
+ },
583
+ size: {
584
+ default: "h-8 text-sm",
585
+ sm: "h-7 text-xs",
586
+ lg: "h-12 text-sm group-data-[state=collapsed]:group-data-[collapsible=icon]:!p-0",
587
+ },
588
+ },
589
+ defaultVariants: {
590
+ variant: "default",
591
+ size: "default",
592
+ },
593
+ }
594
+ )
595
+
596
+ const SidebarMenuButton = React.forwardRef<
597
+ HTMLButtonElement,
598
+ React.ComponentProps<"button"> & {
599
+ asChild?: boolean
600
+ isActive?: boolean
601
+ tooltip?: string | React.ComponentProps<typeof TooltipContent>
602
+ href?: string
603
+ } & VariantProps<typeof sidebarMenuButtonVariants>
604
+ >(
605
+ (
606
+ {
607
+ asChild = false,
608
+ isActive = false,
609
+ variant = "default",
610
+ size = "default",
611
+ tooltip,
612
+ className,
613
+ style,
614
+ href,
615
+ children,
616
+ ...props
617
+ },
618
+ ref
619
+ ) => {
620
+ const { isMobile, state } = useSidebar()
621
+
622
+ const buttonContent = React.useMemo(() => {
623
+ if (href) {
624
+ return (
625
+ <Link
626
+ href={href}
627
+ className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
628
+ style={style}
629
+ data-sidebar="menu-button"
630
+ data-size={size}
631
+ data-active={isActive}
632
+ >
633
+ {children}
634
+ </Link>
635
+ )
636
+ }
637
+
638
+ const Comp = asChild ? Slot : "button"
639
+ return (
640
+ <Comp
641
+ ref={ref}
642
+ data-sidebar="menu-button"
643
+ data-size={size}
644
+ data-active={isActive}
645
+ className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
646
+ style={style}
647
+ {...props}
648
+ >
649
+ {children}
650
+ </Comp>
651
+ )
652
+ }, [href, asChild, ref, variant, size, className, style, isActive, children, props])
653
+
654
+ if (!tooltip) {
655
+ return buttonContent
656
+ }
657
+
658
+ if (typeof tooltip === "string") {
659
+ tooltip = {
660
+ children: tooltip,
661
+ }
662
+ }
663
+
664
+ return (
665
+ <Tooltip>
666
+ <TooltipTrigger asChild>{buttonContent}</TooltipTrigger>
667
+ <TooltipContent
668
+ side="right"
669
+ align="center"
670
+ hidden={state !== "collapsed" || isMobile}
671
+ {...tooltip}
672
+ />
673
+ </Tooltip>
674
+ )
675
+ }
676
+ )
677
+ SidebarMenuButton.displayName = "SidebarMenuButton"
678
+
679
+ const SidebarMenuAction = React.forwardRef<
680
+ HTMLButtonElement,
681
+ React.ComponentProps<"button"> & {
682
+ asChild?: boolean
683
+ showOnHover?: boolean
684
+ }
685
+ >(({ className, asChild = false, showOnHover = false, ...props }, ref) => {
686
+ const Comp = asChild ? Slot : "button"
687
+
688
+ return (
689
+ <Comp
690
+ ref={ref}
691
+ data-sidebar="menu-action"
692
+ className={cn(
693
+ "absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0",
694
+ // Increases the hit area of the button on mobile.
695
+ "after:absolute after:-inset-2 after:md:hidden",
696
+ "peer-data-[size=sm]/menu-button:top-1",
697
+ "peer-data-[size=default]/menu-button:top-1.5",
698
+ "peer-data-[size=lg]/menu-button:top-2.5",
699
+ "group-data-[state=collapsed]:group-data-[collapsible=icon]:hidden",
700
+ showOnHover &&
701
+ "group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",
702
+ className
703
+ )}
704
+ {...props}
705
+ />
706
+ )
707
+ })
708
+ SidebarMenuAction.displayName = "SidebarMenuAction"
709
+
710
+ const SidebarMenuBadge = React.forwardRef<
711
+ HTMLDivElement,
712
+ React.ComponentProps<"div">
713
+ >(({ className, ...props }, ref) => (
714
+ <div
715
+ ref={ref}
716
+ data-sidebar="menu-badge"
717
+ className={cn(
718
+ "pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground",
719
+ "peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
720
+ "peer-data-[size=sm]/menu-button:top-1",
721
+ "peer-data-[size=default]/menu-button:top-1.5",
722
+ "peer-data-[size=lg]/menu-button:top-2.5",
723
+ "group-data-[state=collapsed]:group-data-[collapsible=icon]:hidden",
724
+ className
725
+ )}
726
+ {...props}
727
+ />
728
+ ))
729
+ SidebarMenuBadge.displayName = "SidebarMenuBadge"
730
+
731
+ const SidebarMenuSkeleton = React.forwardRef<
732
+ HTMLDivElement,
733
+ React.ComponentProps<"div"> & {
734
+ showIcon?: boolean
735
+ }
736
+ >(({ className, showIcon = false, ...props }, ref) => {
737
+ // Random width between 50 to 90%.
738
+ const width = React.useMemo(() => {
739
+ return `${Math.floor(Math.random() * 40) + 50}%`
740
+ }, [])
741
+
742
+ return (
743
+ <div
744
+ ref={ref}
745
+ data-sidebar="menu-skeleton"
746
+ className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
747
+ {...props}
748
+ >
749
+ {showIcon && (
750
+ <Skeleton
751
+ className="size-4 rounded-md"
752
+ data-sidebar="menu-skeleton-icon"
753
+ />
754
+ )}
755
+ <Skeleton
756
+ className="h-4 max-w-[--skeleton-width] flex-1"
757
+ data-sidebar="menu-skeleton-text"
758
+ style={
759
+ {
760
+ "--skeleton-width": width,
761
+ } as React.CSSProperties
762
+ }
763
+ />
764
+ </div>
765
+ )
766
+ })
767
+ SidebarMenuSkeleton.displayName = "SidebarMenuSkeleton"
768
+
769
+ const SidebarMenuSub = React.forwardRef<
770
+ HTMLUListElement,
771
+ React.ComponentProps<"ul">
772
+ >(({ className, ...props }, ref) => (
773
+ <ul
774
+ ref={ref}
775
+ data-sidebar="menu-sub"
776
+ className={cn(
777
+ "mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5",
778
+ "group-data-[state=collapsed]:group-data-[collapsible=icon]:hidden",
779
+ className
780
+ )}
781
+ {...props}
782
+ />
783
+ ))
784
+ SidebarMenuSub.displayName = "SidebarMenuSub"
785
+
786
+ const SidebarMenuSubItem = React.forwardRef<
787
+ HTMLLIElement,
788
+ React.ComponentProps<"li">
789
+ >(({ ...props }, ref) => <li ref={ref} {...props} />)
790
+ SidebarMenuSubItem.displayName = "SidebarMenuSubItem"
791
+
792
+ const SidebarMenuSubButton = React.forwardRef<
793
+ HTMLAnchorElement,
794
+ React.ComponentProps<"a"> & {
795
+ asChild?: boolean
796
+ size?: "sm" | "md"
797
+ isActive?: boolean
798
+ href?: string
799
+ }
800
+ >(({ asChild = false, size = "md", isActive, className, href, children, ...props }, ref) => {
801
+ const Comp = asChild ? Slot : "a"
802
+
803
+ const buttonClasses = cn(
804
+ "flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-muted-foreground [&>svg]:opacity-70 data-[active=true]:[&>svg]:text-sidebar-accent-foreground data-[active=true]:[&>svg]:opacity-100 hover:[&>svg]:text-sidebar-accent-foreground hover:[&>svg]:opacity-100",
805
+ "data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
806
+ size === "sm" && "text-xs",
807
+ size === "md" && "text-sm",
808
+ "group-data-[state=collapsed]:group-data-[collapsible=icon]:hidden",
809
+ className
810
+ )
811
+
812
+ if (href) {
813
+ return (
814
+ <Link
815
+ href={href}
816
+ className={buttonClasses}
817
+ data-sidebar="menu-sub-button"
818
+ data-size={size}
819
+ data-active={isActive}
820
+ >
821
+ {children}
822
+ </Link>
823
+ )
824
+ }
825
+
826
+ return (
827
+ <Comp
828
+ ref={ref}
829
+ data-sidebar="menu-sub-button"
830
+ data-size={size}
831
+ data-active={isActive}
832
+ className={buttonClasses}
833
+ {...props}
834
+ >
835
+ {children}
836
+ </Comp>
837
+ )
838
+ })
839
+ SidebarMenuSubButton.displayName = "SidebarMenuSubButton"
840
+
841
+ export {
842
+ Sidebar,
843
+ SidebarContent,
844
+ SidebarFooter,
845
+ SidebarGroup,
846
+ SidebarGroupAction,
847
+ SidebarGroupContent,
848
+ SidebarGroupLabel,
849
+ SidebarHeader,
850
+ SidebarInput,
851
+ SidebarInset,
852
+ SidebarMenu,
853
+ SidebarMenuAction,
854
+ SidebarMenuBadge,
855
+ SidebarMenuButton,
856
+ SidebarMenuItem,
857
+ SidebarMenuSkeleton,
858
+ SidebarMenuSub,
859
+ SidebarMenuSubButton,
860
+ SidebarMenuSubItem,
861
+ SidebarProvider,
862
+ SidebarRail,
863
+ SidebarSeparator,
864
+ SidebarTrigger,
865
+ useSidebar,
866
+ }