@inbeat/ui 0.7.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 (56) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/package.json +100 -0
  3. package/src/components/alert-dialog.tsx +246 -0
  4. package/src/components/alert.tsx +66 -0
  5. package/src/components/app-nav.tsx +55 -0
  6. package/src/components/app-shell.tsx +95 -0
  7. package/src/components/avatar.tsx +73 -0
  8. package/src/components/badge.tsx +42 -0
  9. package/src/components/breadcrumb.tsx +109 -0
  10. package/src/components/button.tsx +75 -0
  11. package/src/components/calendar.tsx +220 -0
  12. package/src/components/carousel.tsx +83 -0
  13. package/src/components/checkbox.tsx +29 -0
  14. package/src/components/collapsible-section.tsx +88 -0
  15. package/src/components/combobox.tsx +351 -0
  16. package/src/components/data-table-shell.tsx +6 -0
  17. package/src/components/data-table-sortable-header.tsx +29 -0
  18. package/src/components/data-table.tsx +141 -0
  19. package/src/components/destructive-action-dialog.tsx +108 -0
  20. package/src/components/dialog.tsx +187 -0
  21. package/src/components/dropdown-menu.tsx +228 -0
  22. package/src/components/empty-state.tsx +55 -0
  23. package/src/components/field.tsx +248 -0
  24. package/src/components/icon-button.tsx +51 -0
  25. package/src/components/input-group.tsx +170 -0
  26. package/src/components/input.tsx +22 -0
  27. package/src/components/label.tsx +24 -0
  28. package/src/components/labeled-field.tsx +18 -0
  29. package/src/components/load-more-sentinel.tsx +12 -0
  30. package/src/components/member-avatar-stack.tsx +44 -0
  31. package/src/components/multi-select-popover.tsx +202 -0
  32. package/src/components/nav-user.tsx +71 -0
  33. package/src/components/number-dot.tsx +13 -0
  34. package/src/components/person-identity.tsx +52 -0
  35. package/src/components/platform-disclaimer.tsx +70 -0
  36. package/src/components/popover.tsx +92 -0
  37. package/src/components/portal-container.tsx +21 -0
  38. package/src/components/progress.tsx +23 -0
  39. package/src/components/search-input.tsx +57 -0
  40. package/src/components/select.tsx +232 -0
  41. package/src/components/separator.tsx +28 -0
  42. package/src/components/sheet.tsx +147 -0
  43. package/src/components/sidebar.tsx +471 -0
  44. package/src/components/skeleton.tsx +13 -0
  45. package/src/components/sonner.tsx +46 -0
  46. package/src/components/spinner.tsx +21 -0
  47. package/src/components/table.tsx +92 -0
  48. package/src/components/tabs.tsx +62 -0
  49. package/src/components/textarea.tsx +18 -0
  50. package/src/components/toggle-pills.tsx +32 -0
  51. package/src/components/tooltip.tsx +67 -0
  52. package/src/hooks/use-mobile.ts +21 -0
  53. package/src/lib/easing.ts +5 -0
  54. package/src/lib/initials.ts +12 -0
  55. package/src/lib/utils.ts +6 -0
  56. package/theme.css +141 -0
@@ -0,0 +1,471 @@
1
+ "use client";
2
+
3
+ import { PanelLeftIcon, XIcon } from "lucide-react";
4
+ import { Slot } from "radix-ui";
5
+ import * as React from "react";
6
+ import { Button } from "./button";
7
+ import { Separator } from "./separator";
8
+ import {
9
+ Sheet,
10
+ SheetClose,
11
+ SheetContent,
12
+ SheetDescription,
13
+ SheetHeader,
14
+ SheetTitle,
15
+ } from "./sheet";
16
+ import {
17
+ TooltipContent,
18
+ TooltipProvider,
19
+ TooltipRoot,
20
+ TooltipTrigger,
21
+ } from "./tooltip";
22
+ import { useIsMobile } from "../hooks/use-mobile";
23
+ import { cn } from "../lib/utils";
24
+
25
+ const SIDEBAR_COOKIE_NAME = "sidebar_state";
26
+ const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
27
+ const SIDEBAR_WIDTH = "16rem";
28
+ const SIDEBAR_WIDTH_MOBILE = "18rem";
29
+ const SIDEBAR_WIDTH_ICON = "3rem";
30
+ const SIDEBAR_KEYBOARD_SHORTCUT = "b";
31
+
32
+ type SidebarContextProps = {
33
+ state: "expanded" | "collapsed";
34
+ open: boolean;
35
+ setOpen: (open: boolean) => void;
36
+ openMobile: boolean;
37
+ setOpenMobile: (open: boolean) => void;
38
+ isMobile: boolean;
39
+ toggleSidebar: () => void;
40
+ };
41
+
42
+ const SidebarContext = React.createContext<SidebarContextProps | null>(null);
43
+
44
+ function useSidebar() {
45
+ const context = React.useContext(SidebarContext);
46
+ if (!context) {
47
+ throw new Error("useSidebar must be used within a SidebarProvider.");
48
+ }
49
+
50
+ return context;
51
+ }
52
+
53
+ function SidebarProvider({
54
+ defaultOpen = true,
55
+ open: openProp,
56
+ onOpenChange: setOpenProp,
57
+ className,
58
+ style,
59
+ children,
60
+ ...props
61
+ }: React.ComponentProps<"div"> & {
62
+ defaultOpen?: boolean;
63
+ open?: boolean;
64
+ onOpenChange?: (open: boolean) => void;
65
+ }) {
66
+ const isMobile = useIsMobile();
67
+ const [openMobile, setOpenMobile] = React.useState(false);
68
+
69
+ const [_open, _setOpen] = React.useState(defaultOpen);
70
+ const open = openProp ?? _open;
71
+ const setOpen = React.useCallback(
72
+ (value: boolean | ((value: boolean) => boolean)) => {
73
+ const openState = typeof value === "function" ? value(open) : value;
74
+ if (setOpenProp) {
75
+ setOpenProp(openState);
76
+ } else {
77
+ _setOpen(openState);
78
+ }
79
+
80
+ document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
81
+ },
82
+ [setOpenProp, open],
83
+ );
84
+
85
+ const toggleSidebar = React.useCallback(() => {
86
+ return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open);
87
+ }, [isMobile, setOpen, setOpenMobile]);
88
+
89
+ React.useEffect(() => {
90
+ const handleKeyDown = (event: KeyboardEvent) => {
91
+ if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
92
+ event.preventDefault();
93
+ toggleSidebar();
94
+ }
95
+ };
96
+
97
+ window.addEventListener("keydown", handleKeyDown);
98
+ return () => window.removeEventListener("keydown", handleKeyDown);
99
+ }, [toggleSidebar]);
100
+
101
+ const state = open ? "expanded" : "collapsed";
102
+
103
+ const contextValue = React.useMemo<SidebarContextProps>(
104
+ () => ({
105
+ state,
106
+ open,
107
+ setOpen,
108
+ isMobile,
109
+ openMobile,
110
+ setOpenMobile,
111
+ toggleSidebar,
112
+ }),
113
+ [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar],
114
+ );
115
+
116
+ return (
117
+ <SidebarContext.Provider value={contextValue}>
118
+ <TooltipProvider delayDuration={0}>
119
+ <div
120
+ data-slot="sidebar-wrapper"
121
+ style={
122
+ {
123
+ "--sidebar-width": SIDEBAR_WIDTH,
124
+ "--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
125
+ ...style,
126
+ } as React.CSSProperties
127
+ }
128
+ className={cn(
129
+ "group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
130
+ className,
131
+ )}
132
+ {...props}
133
+ >
134
+ {children}
135
+ </div>
136
+ </TooltipProvider>
137
+ </SidebarContext.Provider>
138
+ );
139
+ }
140
+
141
+ function Sidebar({
142
+ side = "left",
143
+ variant = "sidebar",
144
+ collapsible = "offcanvas",
145
+ className,
146
+ children,
147
+ ...props
148
+ }: React.ComponentProps<"div"> & {
149
+ side?: "left" | "right";
150
+ variant?: "sidebar" | "floating" | "inset";
151
+ collapsible?: "offcanvas" | "icon" | "none";
152
+ }) {
153
+ const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
154
+
155
+ if (collapsible === "none") {
156
+ return (
157
+ <div
158
+ data-slot="sidebar"
159
+ className={cn(
160
+ "bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
161
+ className,
162
+ )}
163
+ {...props}
164
+ >
165
+ {children}
166
+ </div>
167
+ );
168
+ }
169
+
170
+ if (isMobile) {
171
+ return (
172
+ <Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
173
+ <SheetContent
174
+ data-sidebar="sidebar"
175
+ data-slot="sidebar"
176
+ data-mobile="true"
177
+ className="bg-sidebar text-sidebar-foreground w-(--sidebar-width) gap-0 p-0"
178
+ style={
179
+ {
180
+ "--sidebar-width": SIDEBAR_WIDTH_MOBILE,
181
+ } as React.CSSProperties
182
+ }
183
+ side={side}
184
+ >
185
+ <SheetHeader className="gap-0 space-y-0 shrink-0 border-b border-sidebar-border px-4 py-3">
186
+ <div className="flex items-center justify-between gap-3">
187
+ <SheetTitle className="text-sm font-medium">Menu</SheetTitle>
188
+ <SheetClose asChild>
189
+ <Button variant="ghost" size="icon-sm" className="shrink-0 -me-2">
190
+ <XIcon />
191
+ <span className="sr-only">Close sidebar</span>
192
+ </Button>
193
+ </SheetClose>
194
+ </div>
195
+ <SheetDescription className="sr-only">Displays the mobile sidebar.</SheetDescription>
196
+ </SheetHeader>
197
+ <div className="flex min-h-0 flex-1 flex-col overflow-auto">{children}</div>
198
+ </SheetContent>
199
+ </Sheet>
200
+ );
201
+ }
202
+
203
+ return (
204
+ <div
205
+ className="group peer hidden text-sidebar-foreground md:block"
206
+ data-state={state}
207
+ data-collapsible={state === "collapsed" ? collapsible : ""}
208
+ data-variant={variant}
209
+ data-side={side}
210
+ data-slot="sidebar"
211
+ >
212
+ <div
213
+ data-slot="sidebar-gap"
214
+ className={cn(
215
+ "relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
216
+ "group-data-[collapsible=offcanvas]:w-0",
217
+ "group-data-[side=right]:rotate-180",
218
+ variant === "floating" || variant === "inset"
219
+ ? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
220
+ : "group-data-[collapsible=icon]:w-(--sidebar-width-icon)",
221
+ )}
222
+ />
223
+ <div
224
+ data-slot="sidebar-container"
225
+ className={cn(
226
+ "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",
227
+ side === "left"
228
+ ? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
229
+ : "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
230
+ variant === "floating" || variant === "inset"
231
+ ? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
232
+ : "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
233
+ className,
234
+ )}
235
+ {...props}
236
+ >
237
+ <div
238
+ data-sidebar="sidebar"
239
+ data-slot="sidebar-inner"
240
+ className="bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow-sm"
241
+ >
242
+ {children}
243
+ </div>
244
+ </div>
245
+ </div>
246
+ );
247
+ }
248
+
249
+ function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<typeof Button>) {
250
+ const { toggleSidebar } = useSidebar();
251
+
252
+ return (
253
+ <Button
254
+ data-sidebar="trigger"
255
+ data-slot="sidebar-trigger"
256
+ variant="ghost"
257
+ size="icon"
258
+ className={cn("size-7", className)}
259
+ onClick={(event) => {
260
+ onClick?.(event);
261
+ toggleSidebar();
262
+ }}
263
+ {...props}
264
+ >
265
+ <PanelLeftIcon />
266
+ <span className="sr-only">Toggle Sidebar</span>
267
+ </Button>
268
+ );
269
+ }
270
+
271
+ function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
272
+ return (
273
+ <main
274
+ data-slot="sidebar-inset"
275
+ className={cn(
276
+ "bg-background relative flex w-full flex-1 flex-col",
277
+ "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",
278
+ className,
279
+ )}
280
+ {...props}
281
+ />
282
+ );
283
+ }
284
+
285
+ function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
286
+ return (
287
+ <div
288
+ data-slot="sidebar-header"
289
+ data-sidebar="header"
290
+ className={cn("flex flex-col gap-2 p-2", className)}
291
+ {...props}
292
+ />
293
+ );
294
+ }
295
+
296
+ function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
297
+ return (
298
+ <div
299
+ data-slot="sidebar-footer"
300
+ data-sidebar="footer"
301
+ className={cn("flex flex-col gap-2 p-2", className)}
302
+ {...props}
303
+ />
304
+ );
305
+ }
306
+
307
+ function SidebarSeparator({ className, ...props }: React.ComponentProps<typeof Separator>) {
308
+ return (
309
+ <Separator
310
+ data-slot="sidebar-separator"
311
+ data-sidebar="separator"
312
+ className={cn("bg-sidebar-border mx-2 w-auto", className)}
313
+ {...props}
314
+ />
315
+ );
316
+ }
317
+
318
+ function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
319
+ return (
320
+ <div
321
+ data-slot="sidebar-content"
322
+ data-sidebar="content"
323
+ className={cn(
324
+ "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
325
+ className,
326
+ )}
327
+ {...props}
328
+ />
329
+ );
330
+ }
331
+
332
+ function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
333
+ return (
334
+ <div
335
+ data-slot="sidebar-group"
336
+ data-sidebar="group"
337
+ className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
338
+ {...props}
339
+ />
340
+ );
341
+ }
342
+
343
+ function SidebarGroupLabel({
344
+ className,
345
+ asChild = false,
346
+ ...props
347
+ }: React.ComponentProps<"div"> & { asChild?: boolean }) {
348
+ const Comp = asChild ? Slot.Root : "div";
349
+
350
+ return (
351
+ <Comp
352
+ data-slot="sidebar-group-label"
353
+ data-sidebar="group-label"
354
+ className={cn(
355
+ "text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-2 [&>svg]:shrink-0",
356
+ "group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
357
+ className,
358
+ )}
359
+ {...props}
360
+ />
361
+ );
362
+ }
363
+
364
+ function SidebarGroupContent({ className, ...props }: React.ComponentProps<"div">) {
365
+ return (
366
+ <div
367
+ data-slot="sidebar-group-content"
368
+ data-sidebar="group-content"
369
+ className={cn("w-full text-sm", className)}
370
+ {...props}
371
+ />
372
+ );
373
+ }
374
+
375
+ function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
376
+ return (
377
+ <ul
378
+ data-slot="sidebar-menu"
379
+ data-sidebar="menu"
380
+ className={cn("flex w-full min-w-0 flex-col gap-1", className)}
381
+ {...props}
382
+ />
383
+ );
384
+ }
385
+
386
+ function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
387
+ return (
388
+ <li
389
+ data-slot="sidebar-menu-item"
390
+ data-sidebar="menu-item"
391
+ data-row
392
+ className={cn("group/menu-item relative", className)}
393
+ {...props}
394
+ />
395
+ );
396
+ }
397
+
398
+ const sidebarMenuButtonClassName =
399
+ "peer/menu-button flex h-8 w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&_svg]:size-4 [&_svg]:shrink-0";
400
+
401
+ // Only tooltip rows subscribe to the sidebar state: a toggle would otherwise re-render every row
402
+ // while the collapse animation starts, which stutters on long lists.
403
+ function SidebarMenuButtonTooltip({
404
+ button,
405
+ tooltip,
406
+ }: {
407
+ button: React.ReactElement;
408
+ tooltip: React.ComponentProps<typeof TooltipContent>;
409
+ }) {
410
+ const { isMobile, state } = useSidebar();
411
+ return (
412
+ <TooltipRoot>
413
+ <TooltipTrigger asChild>{button}</TooltipTrigger>
414
+ <TooltipContent
415
+ side="right"
416
+ align="center"
417
+ hidden={state !== "collapsed" || isMobile}
418
+ {...tooltip}
419
+ />
420
+ </TooltipRoot>
421
+ );
422
+ }
423
+
424
+ function SidebarMenuButton({
425
+ asChild = false,
426
+ isActive = false,
427
+ tooltip,
428
+ className,
429
+ ...props
430
+ }: React.ComponentProps<"button"> & {
431
+ asChild?: boolean;
432
+ isActive?: boolean;
433
+ tooltip?: string | React.ComponentProps<typeof TooltipContent>;
434
+ }) {
435
+ const Comp = asChild ? Slot.Root : "button";
436
+ const button = (
437
+ <Comp
438
+ data-slot="sidebar-menu-button"
439
+ data-sidebar="menu-button"
440
+ data-active={isActive}
441
+ className={cn(sidebarMenuButtonClassName, className)}
442
+ {...props}
443
+ />
444
+ );
445
+
446
+ if (!tooltip) return button;
447
+ return (
448
+ <SidebarMenuButtonTooltip
449
+ button={button}
450
+ tooltip={typeof tooltip === "string" ? { children: tooltip } : tooltip}
451
+ />
452
+ );
453
+ }
454
+
455
+ export {
456
+ Sidebar,
457
+ SidebarContent,
458
+ SidebarFooter,
459
+ SidebarGroup,
460
+ SidebarGroupContent,
461
+ SidebarGroupLabel,
462
+ SidebarHeader,
463
+ SidebarInset,
464
+ SidebarMenu,
465
+ SidebarMenuButton,
466
+ SidebarMenuItem,
467
+ SidebarProvider,
468
+ SidebarSeparator,
469
+ SidebarTrigger,
470
+ useSidebar,
471
+ };
@@ -0,0 +1,13 @@
1
+ import { cn } from "../lib/utils";
2
+
3
+ function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
4
+ return (
5
+ <div
6
+ data-slot="skeleton"
7
+ className={cn("bg-accent animate-pulse rounded-md", className)}
8
+ {...props}
9
+ />
10
+ );
11
+ }
12
+
13
+ export { Skeleton };
@@ -0,0 +1,46 @@
1
+ "use client";
2
+
3
+ import {
4
+ CircleCheckIcon,
5
+ InfoIcon,
6
+ OctagonXIcon,
7
+ TriangleAlertIcon,
8
+ } from "lucide-react";
9
+ import { useTheme } from "next-themes";
10
+ import { Toaster as Sonner, type ToasterProps } from "sonner";
11
+ import { Spinner } from "./spinner";
12
+
13
+ const Toaster = ({ ...props }: ToasterProps) => {
14
+ const { theme = "system" } = useTheme();
15
+
16
+ return (
17
+ <Sonner
18
+ theme={theme as ToasterProps["theme"]}
19
+ className="toaster group"
20
+ icons={{
21
+ success: <CircleCheckIcon className="size-4" />,
22
+ info: <InfoIcon className="size-4" />,
23
+ warning: <TriangleAlertIcon className="size-4" />,
24
+ error: <OctagonXIcon className="size-4" />,
25
+ loading: <Spinner className="size-4" />,
26
+ }}
27
+ style={
28
+ {
29
+ "--normal-bg": "var(--popover)",
30
+ "--normal-text": "var(--popover-foreground)",
31
+ "--normal-border": "var(--border)",
32
+ "--border-radius": "var(--radius)",
33
+ } as React.CSSProperties
34
+ }
35
+ toastOptions={{
36
+ classNames: {
37
+ actionButton:
38
+ "!bg-transparent !text-foreground !border !border-border !rounded-full !text-xs !font-medium hover:!bg-accent",
39
+ },
40
+ }}
41
+ {...props}
42
+ />
43
+ );
44
+ };
45
+
46
+ export { Toaster };
@@ -0,0 +1,21 @@
1
+ import { Loader2 } from "lucide-react";
2
+ import { cn } from "../lib/utils";
3
+
4
+ export function Spinner({ className, label = "Loading" }: { className?: string; label?: string }) {
5
+ return (
6
+ <Loader2
7
+ className={cn("size-4 animate-spin text-muted-foreground", className)}
8
+ role="status"
9
+ aria-label={label}
10
+ />
11
+ );
12
+ }
13
+
14
+ /** Section / tab / panel loading when page chrome is already visible. */
15
+ export function SectionSpinner() {
16
+ return (
17
+ <div className="flex h-full min-h-[200px] flex-1 items-center justify-center">
18
+ <Spinner className="size-4" />
19
+ </div>
20
+ );
21
+ }
@@ -0,0 +1,92 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ import { cn } from "../lib/utils";
6
+
7
+ function Table({ className, ...props }: React.ComponentProps<"table">) {
8
+ return (
9
+ <div
10
+ data-slot="table-container"
11
+ className="relative w-full min-h-0 overflow-x-auto rounded-[inherit]"
12
+ >
13
+ <table
14
+ data-slot="table"
15
+ className={cn(
16
+ "w-full border-separate border-spacing-x-0 border-spacing-y-1.5 text-sm",
17
+ "[&_tbody_tr>td:first-child]:rounded-l-xl [&_tbody_tr>td:last-child]:rounded-r-xl",
18
+ "[&_tbody_tr:hover>td]:bg-muted/50 [&_tbody_tr:focus-within>td]:bg-muted/50",
19
+ "[&_tbody_tr[data-state=selected]>td]:bg-muted",
20
+ "[&_tbody_tr>td]:transition-[background-color,color]",
21
+ className,
22
+ )}
23
+ {...props}
24
+ />
25
+ </div>
26
+ );
27
+ }
28
+
29
+ function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
30
+ return (
31
+ <thead
32
+ data-slot="table-header"
33
+ className={cn(
34
+ "[&_tr]:cursor-default",
35
+ className,
36
+ )}
37
+ {...props}
38
+ />
39
+ );
40
+ }
41
+
42
+ function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
43
+ return (
44
+ <tbody
45
+ data-slot="table-body"
46
+ className={className}
47
+ {...props}
48
+ />
49
+ );
50
+ }
51
+
52
+ function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
53
+ return (
54
+ <tr
55
+ data-slot="table-row"
56
+ data-row
57
+ className={cn(
58
+ "group",
59
+ className,
60
+ )}
61
+ {...props}
62
+ />
63
+ );
64
+ }
65
+
66
+ function TableHead({ className, ...props }: React.ComponentProps<"th">) {
67
+ return (
68
+ <th
69
+ data-slot="table-head"
70
+ className={cn(
71
+ "px-2 pb-2 text-left align-middle text-xs font-medium whitespace-nowrap text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
72
+ className,
73
+ )}
74
+ {...props}
75
+ />
76
+ );
77
+ }
78
+
79
+ function TableCell({ className, ...props }: React.ComponentProps<"td">) {
80
+ return (
81
+ <td
82
+ data-slot="table-cell"
83
+ className={cn(
84
+ "p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
85
+ className,
86
+ )}
87
+ {...props}
88
+ />
89
+ );
90
+ }
91
+
92
+ export { Table, TableHeader, TableBody, TableHead, TableRow, TableCell };
@@ -0,0 +1,62 @@
1
+ "use client";
2
+
3
+ import { Tabs as TabsPrimitive } from "radix-ui";
4
+ import type * as React from "react";
5
+ import { cn } from "../lib/utils";
6
+ import { NumberDot } from "./number-dot";
7
+
8
+ export type TabDefinition = {
9
+ value: string;
10
+ label: string;
11
+ count?: number;
12
+ disabled?: boolean;
13
+ };
14
+
15
+ const triggerClassName =
16
+ "inline-flex h-auto flex-none items-center justify-center gap-1.5 rounded-full border border-transparent bg-transparent px-3 py-1.5 text-sm font-medium whitespace-nowrap text-muted-foreground transition-all hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-linear-to-b data-[state=active]:from-muted/90 data-[state=active]:via-muted data-[state=active]:to-muted/75 data-[state=active]:text-foreground dark:data-[state=active]:from-muted/80 dark:data-[state=active]:to-muted/60";
17
+
18
+ function Tabs({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Root>) {
19
+ return (
20
+ <TabsPrimitive.Root data-slot="tabs" className={cn("flex flex-col gap-2", className)} {...props} />
21
+ );
22
+ }
23
+
24
+ /** Works without `TabsContent` too, as a filter bar driven by `value`/`onValueChange` on `Tabs`. */
25
+ function TabsList({
26
+ tabs,
27
+ className,
28
+ ...props
29
+ }: Omit<React.ComponentProps<typeof TabsPrimitive.List>, "children"> & { tabs: TabDefinition[] }) {
30
+ return (
31
+ <TabsPrimitive.List
32
+ data-slot="tabs-list"
33
+ className={cn("inline-flex w-fit shrink-0 items-center gap-1", className)}
34
+ {...props}
35
+ >
36
+ {tabs.map((tab) => (
37
+ <TabsPrimitive.Trigger
38
+ key={tab.value}
39
+ value={tab.value}
40
+ disabled={tab.disabled}
41
+ data-slot="tabs-trigger"
42
+ className={triggerClassName}
43
+ >
44
+ {tab.label}
45
+ {tab.count != null && tab.count > 0 ? <NumberDot count={tab.count} /> : null}
46
+ </TabsPrimitive.Trigger>
47
+ ))}
48
+ </TabsPrimitive.List>
49
+ );
50
+ }
51
+
52
+ function TabsContent({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Content>) {
53
+ return (
54
+ <TabsPrimitive.Content
55
+ data-slot="tabs-content"
56
+ className={cn("mt-0 flex min-h-0 flex-1 flex-col text-sm outline-none", className)}
57
+ {...props}
58
+ />
59
+ );
60
+ }
61
+
62
+ export { Tabs, TabsContent, TabsList };