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