@zedtech/zedkit-ui 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/alert.d.ts +9 -0
- package/dist/alert.d.ts.map +1 -0
- package/dist/alert.js +26 -0
- package/dist/alert.js.map +1 -0
- package/dist/app-shell.d.ts +9 -0
- package/dist/app-shell.d.ts.map +1 -0
- package/dist/app-shell.js +6 -0
- package/dist/app-shell.js.map +1 -0
- package/dist/badge.d.ts +10 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +19 -0
- package/dist/badge.js.map +1 -0
- package/dist/button.d.ts +12 -0
- package/dist/button.d.ts.map +1 -0
- package/dist/button.js +31 -0
- package/dist/button.js.map +1 -0
- package/dist/card.d.ts +9 -0
- package/dist/card.d.ts.map +1 -0
- package/dist/card.js +17 -0
- package/dist/card.js.map +1 -0
- package/dist/checkbox.d.ts +5 -0
- package/dist/checkbox.d.ts.map +1 -0
- package/dist/checkbox.js +10 -0
- package/dist/checkbox.js.map +1 -0
- package/dist/confirm-dialog.d.ts +17 -0
- package/dist/confirm-dialog.d.ts.map +1 -0
- package/dist/confirm-dialog.js +18 -0
- package/dist/confirm-dialog.js.map +1 -0
- package/dist/data-table.d.ts +33 -0
- package/dist/data-table.d.ts.map +1 -0
- package/dist/data-table.js +40 -0
- package/dist/data-table.js.map +1 -0
- package/dist/detail-panel.d.ts +11 -0
- package/dist/detail-panel.d.ts.map +1 -0
- package/dist/detail-panel.js +6 -0
- package/dist/detail-panel.js.map +1 -0
- package/dist/dialog.d.ts +14 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +26 -0
- package/dist/dialog.js.map +1 -0
- package/dist/field.d.ts +26 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +74 -0
- package/dist/field.js.map +1 -0
- package/dist/form-submit.d.ts +16 -0
- package/dist/form-submit.d.ts.map +1 -0
- package/dist/form-submit.js +15 -0
- package/dist/form-submit.js.map +1 -0
- package/dist/form.d.ts +26 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +65 -0
- package/dist/form.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/input.d.ts +4 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +9 -0
- package/dist/input.js.map +1 -0
- package/dist/label.d.ts +6 -0
- package/dist/label.d.ts.map +1 -0
- package/dist/label.js +11 -0
- package/dist/label.js.map +1 -0
- package/dist/layout.d.ts +22 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +36 -0
- package/dist/layout.js.map +1 -0
- package/dist/live-pulse.d.ts +7 -0
- package/dist/live-pulse.d.ts.map +1 -0
- package/dist/live-pulse.js +6 -0
- package/dist/live-pulse.js.map +1 -0
- package/dist/option-cards.d.ts +15 -0
- package/dist/option-cards.d.ts.map +1 -0
- package/dist/option-cards.js +9 -0
- package/dist/option-cards.js.map +1 -0
- package/dist/page-header.d.ts +9 -0
- package/dist/page-header.d.ts.map +1 -0
- package/dist/page-header.js +6 -0
- package/dist/page-header.js.map +1 -0
- package/dist/secret-field.d.ts +22 -0
- package/dist/secret-field.d.ts.map +1 -0
- package/dist/secret-field.js +26 -0
- package/dist/secret-field.js.map +1 -0
- package/dist/select.d.ts +14 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +30 -0
- package/dist/select.js.map +1 -0
- package/dist/separator.d.ts +5 -0
- package/dist/separator.d.ts.map +1 -0
- package/dist/separator.js +9 -0
- package/dist/separator.js.map +1 -0
- package/dist/skeleton.d.ts +3 -0
- package/dist/skeleton.d.ts.map +1 -0
- package/dist/skeleton.js +7 -0
- package/dist/skeleton.js.map +1 -0
- package/dist/sonner.d.ts +8 -0
- package/dist/sonner.d.ts.map +1 -0
- package/dist/sonner.js +19 -0
- package/dist/sonner.js.map +1 -0
- package/dist/switch.d.ts +5 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/switch.js +9 -0
- package/dist/switch.js.map +1 -0
- package/dist/table.d.ts +11 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +28 -0
- package/dist/table.js.map +1 -0
- package/dist/tabs.d.ts +8 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +14 -0
- package/dist/tabs.js.map +1 -0
- package/dist/textarea.d.ts +4 -0
- package/dist/textarea.d.ts.map +1 -0
- package/dist/textarea.js +9 -0
- package/dist/textarea.js.map +1 -0
- package/dist/typography.d.ts +22 -0
- package/dist/typography.d.ts.map +1 -0
- package/dist/typography.js +39 -0
- package/dist/typography.js.map +1 -0
- package/dist/use-validated-form.d.ts +10 -0
- package/dist/use-validated-form.d.ts.map +1 -0
- package/dist/use-validated-form.js +20 -0
- package/dist/use-validated-form.js.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +11 -0
- package/dist/utils.js.map +1 -0
- package/dist/wizard-steps.d.ts +8 -0
- package/dist/wizard-steps.d.ts.map +1 -0
- package/dist/wizard-steps.js +7 -0
- package/dist/wizard-steps.js.map +1 -0
- package/package.json +83 -3
- package/src/alert.tsx +47 -0
- package/src/app-shell.tsx +24 -0
- package/src/badge.tsx +30 -0
- package/src/button.tsx +48 -0
- package/src/card.tsx +47 -0
- package/src/checkbox.tsx +28 -0
- package/src/confirm-dialog.tsx +65 -0
- package/src/data-table.tsx +176 -0
- package/src/detail-panel.tsx +26 -0
- package/src/dialog.tsx +102 -0
- package/src/field.tsx +230 -0
- package/src/form-submit.tsx +29 -0
- package/src/form.tsx +157 -0
- package/src/index.ts +95 -0
- package/src/input.tsx +21 -0
- package/src/label.tsx +20 -0
- package/src/layout.tsx +69 -0
- package/src/live-pulse.tsx +27 -0
- package/src/option-cards.tsx +47 -0
- package/src/page-header.tsx +22 -0
- package/src/secret-field.tsx +50 -0
- package/src/select.tsx +146 -0
- package/src/separator.tsx +30 -0
- package/src/skeleton.tsx +7 -0
- package/src/sonner.tsx +25 -0
- package/src/styles.css +117 -0
- package/src/switch.tsx +29 -0
- package/src/table.tsx +68 -0
- package/src/tabs.tsx +52 -0
- package/src/textarea.tsx +21 -0
- package/src/typography.tsx +59 -0
- package/src/use-validated-form.ts +30 -0
- package/src/utils.ts +11 -0
- package/src/wizard-steps.tsx +40 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "./utils.js";
|
|
4
|
+
|
|
5
|
+
export interface AppShellProps {
|
|
6
|
+
sidebar: React.ReactNode;
|
|
7
|
+
topbar?: React.ReactNode;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function AppShell({ sidebar, topbar, children, className }: AppShellProps) {
|
|
13
|
+
return (
|
|
14
|
+
<div className={cn("flex min-h-svh w-full", className)}>
|
|
15
|
+
<aside className="hidden w-64 shrink-0 border-r bg-muted/40 md:block">{sidebar}</aside>
|
|
16
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
17
|
+
{topbar ? (
|
|
18
|
+
<header className="sticky top-0 z-10 border-b bg-background/95 backdrop-blur">{topbar}</header>
|
|
19
|
+
) : null}
|
|
20
|
+
<main className="flex-1 p-4 md:p-6">{children}</main>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
}
|
package/src/badge.tsx
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
import { cn } from "./utils.js";
|
|
4
|
+
|
|
5
|
+
const badgeVariants = cva(
|
|
6
|
+
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-none",
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default: "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
|
|
11
|
+
secondary:
|
|
12
|
+
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
13
|
+
destructive:
|
|
14
|
+
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
|
|
15
|
+
outline: "text-foreground",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
defaultVariants: { variant: "default" },
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export interface BadgeProps
|
|
23
|
+
extends React.HTMLAttributes<HTMLDivElement>,
|
|
24
|
+
VariantProps<typeof badgeVariants> {}
|
|
25
|
+
|
|
26
|
+
function Badge({ className, variant, ...props }: BadgeProps) {
|
|
27
|
+
return <div className={cn(badgeVariants({ variant }), className)} {...props} />;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { Badge, badgeVariants };
|
package/src/button.tsx
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
5
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
6
|
+
import { cn } from "./utils.js";
|
|
7
|
+
|
|
8
|
+
const buttonVariants = cva(
|
|
9
|
+
"inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-colors focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
|
10
|
+
{
|
|
11
|
+
variants: {
|
|
12
|
+
variant: {
|
|
13
|
+
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
|
14
|
+
destructive:
|
|
15
|
+
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
|
16
|
+
outline:
|
|
17
|
+
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
18
|
+
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
|
19
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
20
|
+
},
|
|
21
|
+
size: {
|
|
22
|
+
default: "h-9 px-4 py-2",
|
|
23
|
+
sm: "h-8 rounded-md px-3 text-xs",
|
|
24
|
+
lg: "h-10 rounded-md px-8",
|
|
25
|
+
icon: "h-9 w-9",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
defaultVariants: { variant: "default", size: "default" },
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export interface ButtonProps
|
|
33
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
34
|
+
VariantProps<typeof buttonVariants> {
|
|
35
|
+
asChild?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
39
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
40
|
+
const Comp = asChild ? Slot : "button";
|
|
41
|
+
return (
|
|
42
|
+
<Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
Button.displayName = "Button";
|
|
47
|
+
|
|
48
|
+
export { Button, buttonVariants };
|
package/src/card.tsx
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "./utils.js";
|
|
4
|
+
|
|
5
|
+
const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
6
|
+
({ className, ...props }, ref) => (
|
|
7
|
+
<div ref={ref} className={cn("rounded-xl border bg-card text-card-foreground shadow", className)} {...props} />
|
|
8
|
+
),
|
|
9
|
+
);
|
|
10
|
+
Card.displayName = "Card";
|
|
11
|
+
|
|
12
|
+
const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
13
|
+
({ className, ...props }, ref) => (
|
|
14
|
+
<div ref={ref} className={cn("flex flex-col space-y-1.5 p-6", className)} {...props} />
|
|
15
|
+
),
|
|
16
|
+
);
|
|
17
|
+
CardHeader.displayName = "CardHeader";
|
|
18
|
+
|
|
19
|
+
const CardTitle = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
20
|
+
({ className, ...props }, ref) => (
|
|
21
|
+
<div ref={ref} className={cn("leading-none font-semibold tracking-tight", className)} {...props} />
|
|
22
|
+
),
|
|
23
|
+
);
|
|
24
|
+
CardTitle.displayName = "CardTitle";
|
|
25
|
+
|
|
26
|
+
const CardDescription = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
27
|
+
({ className, ...props }, ref) => (
|
|
28
|
+
<div ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
CardDescription.displayName = "CardDescription";
|
|
32
|
+
|
|
33
|
+
const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
34
|
+
({ className, ...props }, ref) => (
|
|
35
|
+
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
|
36
|
+
),
|
|
37
|
+
);
|
|
38
|
+
CardContent.displayName = "CardContent";
|
|
39
|
+
|
|
40
|
+
const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
41
|
+
({ className, ...props }, ref) => (
|
|
42
|
+
<div ref={ref} className={cn("flex items-center p-6 pt-0", className)} {...props} />
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
CardFooter.displayName = "CardFooter";
|
|
46
|
+
|
|
47
|
+
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
|
package/src/checkbox.tsx
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
5
|
+
import { Check } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
import { cn } from "./utils.js";
|
|
8
|
+
|
|
9
|
+
const Checkbox = React.forwardRef<
|
|
10
|
+
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
|
11
|
+
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
|
12
|
+
>(({ className, ...props }, ref) => (
|
|
13
|
+
<CheckboxPrimitive.Root
|
|
14
|
+
ref={ref}
|
|
15
|
+
className={cn(
|
|
16
|
+
"peer grid h-4 w-4 shrink-0 place-content-center rounded-sm border border-primary shadow focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
|
17
|
+
className,
|
|
18
|
+
)}
|
|
19
|
+
{...props}
|
|
20
|
+
>
|
|
21
|
+
<CheckboxPrimitive.Indicator className={cn("grid place-content-center text-current")}>
|
|
22
|
+
<Check className="h-4 w-4" />
|
|
23
|
+
</CheckboxPrimitive.Indicator>
|
|
24
|
+
</CheckboxPrimitive.Root>
|
|
25
|
+
));
|
|
26
|
+
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
|
|
27
|
+
|
|
28
|
+
export { Checkbox };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Button } from "./button.js";
|
|
5
|
+
import {
|
|
6
|
+
Dialog,
|
|
7
|
+
DialogContent,
|
|
8
|
+
DialogDescription,
|
|
9
|
+
DialogFooter,
|
|
10
|
+
DialogHeader,
|
|
11
|
+
DialogTitle,
|
|
12
|
+
DialogTrigger,
|
|
13
|
+
} from "./dialog.js";
|
|
14
|
+
|
|
15
|
+
export interface ConfirmDialogProps {
|
|
16
|
+
/** Element that opens the dialog (rendered via Trigger asChild). */
|
|
17
|
+
trigger: React.ReactNode;
|
|
18
|
+
title: string;
|
|
19
|
+
description: string;
|
|
20
|
+
confirmLabel?: string;
|
|
21
|
+
cancelLabel?: string;
|
|
22
|
+
onConfirm: () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Destructive-action confirmation: trigger opens a dialog, Confirm
|
|
27
|
+
* runs the callback and closes. Cancel and backdrop dismiss.
|
|
28
|
+
*/
|
|
29
|
+
function ConfirmDialog({
|
|
30
|
+
trigger,
|
|
31
|
+
title,
|
|
32
|
+
description,
|
|
33
|
+
confirmLabel = "Confirm",
|
|
34
|
+
cancelLabel = "Cancel",
|
|
35
|
+
onConfirm,
|
|
36
|
+
}: ConfirmDialogProps) {
|
|
37
|
+
const [open, setOpen] = React.useState(false);
|
|
38
|
+
return (
|
|
39
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
40
|
+
<DialogTrigger asChild>{trigger}</DialogTrigger>
|
|
41
|
+
<DialogContent>
|
|
42
|
+
<DialogHeader>
|
|
43
|
+
<DialogTitle>{title}</DialogTitle>
|
|
44
|
+
<DialogDescription>{description}</DialogDescription>
|
|
45
|
+
</DialogHeader>
|
|
46
|
+
<DialogFooter>
|
|
47
|
+
<Button variant="outline" onClick={() => setOpen(false)}>
|
|
48
|
+
{cancelLabel}
|
|
49
|
+
</Button>
|
|
50
|
+
<Button
|
|
51
|
+
variant="destructive"
|
|
52
|
+
onClick={() => {
|
|
53
|
+
onConfirm();
|
|
54
|
+
setOpen(false);
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
{confirmLabel}
|
|
58
|
+
</Button>
|
|
59
|
+
</DialogFooter>
|
|
60
|
+
</DialogContent>
|
|
61
|
+
</Dialog>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { ConfirmDialog };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import {
|
|
5
|
+
columnFilteringFeature,
|
|
6
|
+
createColumnHelper,
|
|
7
|
+
createFilteredRowModel,
|
|
8
|
+
createPaginatedRowModel,
|
|
9
|
+
createSortedRowModel,
|
|
10
|
+
globalFilteringFeature,
|
|
11
|
+
rowPaginationFeature,
|
|
12
|
+
rowSortingFeature,
|
|
13
|
+
tableFeatures,
|
|
14
|
+
useTable,
|
|
15
|
+
type CellData,
|
|
16
|
+
type ColumnDef,
|
|
17
|
+
type RowData,
|
|
18
|
+
type SortDirection,
|
|
19
|
+
} from "@tanstack/react-table";
|
|
20
|
+
import { ArrowDown, ArrowUp, ArrowUpDown } from "lucide-react";
|
|
21
|
+
|
|
22
|
+
import { Button } from "./button.js";
|
|
23
|
+
import { Input } from "./input.js";
|
|
24
|
+
import { Skeleton } from "./skeleton.js";
|
|
25
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "./table.js";
|
|
26
|
+
import { cn } from "./utils.js";
|
|
27
|
+
|
|
28
|
+
const features = tableFeatures({
|
|
29
|
+
rowSortingFeature,
|
|
30
|
+
columnFilteringFeature,
|
|
31
|
+
globalFilteringFeature,
|
|
32
|
+
rowPaginationFeature,
|
|
33
|
+
sortedRowModel: createSortedRowModel(),
|
|
34
|
+
filteredRowModel: createFilteredRowModel(),
|
|
35
|
+
paginatedRowModel: createPaginatedRowModel(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export type DataTableColumn<TData extends RowData, TValue extends CellData> = ColumnDef<
|
|
39
|
+
typeof features,
|
|
40
|
+
TData,
|
|
41
|
+
TValue
|
|
42
|
+
>;
|
|
43
|
+
|
|
44
|
+
export function createDataTableColumns<TData extends RowData>() {
|
|
45
|
+
return createColumnHelper<typeof features, TData>();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface DataTableProps<TData extends RowData> {
|
|
49
|
+
// `any` mirrors upstream: TanStack's own helper.columns() returns
|
|
50
|
+
// Array<ColumnDef<TFeatures, TData, any>> since TValue is invariant.
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
columns: ReadonlyArray<DataTableColumn<TData, any>>;
|
|
53
|
+
data: TData[];
|
|
54
|
+
loading?: boolean;
|
|
55
|
+
error?: string | null;
|
|
56
|
+
emptyMessage?: string;
|
|
57
|
+
filterPlaceholder?: string;
|
|
58
|
+
pageSize?: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function SortIcon({ direction }: { direction: SortDirection | false }) {
|
|
62
|
+
const className = "size-3.5 opacity-60";
|
|
63
|
+
if (direction === "asc") return <ArrowUp className={className} aria-hidden />;
|
|
64
|
+
if (direction === "desc") return <ArrowDown className={className} aria-hidden />;
|
|
65
|
+
return <ArrowUpDown className={className} aria-hidden />;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function DataTable<TData extends RowData>({
|
|
69
|
+
columns,
|
|
70
|
+
data,
|
|
71
|
+
loading = false,
|
|
72
|
+
error = null,
|
|
73
|
+
emptyMessage = "No results.",
|
|
74
|
+
filterPlaceholder = "Filter…",
|
|
75
|
+
pageSize = 10,
|
|
76
|
+
}: DataTableProps<TData>) {
|
|
77
|
+
const table = useTable({ features, columns, data });
|
|
78
|
+
const rows = table.getRowModel().rows;
|
|
79
|
+
const { pageIndex } = table.state.pagination;
|
|
80
|
+
|
|
81
|
+
React.useEffect(() => {
|
|
82
|
+
table.setPageSize(pageSize);
|
|
83
|
+
}, [table, pageSize]);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<div className="space-y-4">
|
|
87
|
+
<Input
|
|
88
|
+
placeholder={filterPlaceholder}
|
|
89
|
+
value={table.state.globalFilter ?? ""}
|
|
90
|
+
onChange={(event) => table.setGlobalFilter(event.target.value)}
|
|
91
|
+
className="max-w-sm"
|
|
92
|
+
aria-label={filterPlaceholder}
|
|
93
|
+
/>
|
|
94
|
+
<Table aria-busy={loading || undefined} aria-label={loading ? "Loading" : undefined}>
|
|
95
|
+
<TableHeader>
|
|
96
|
+
{table.getHeaderGroups().map((group) => (
|
|
97
|
+
<TableRow key={group.id}>
|
|
98
|
+
{group.headers.map((header) => (
|
|
99
|
+
<TableHead key={header.id}>
|
|
100
|
+
{header.isPlaceholder || !header.column.getCanSort() ? (
|
|
101
|
+
<table.FlexRender header={header} />
|
|
102
|
+
) : (
|
|
103
|
+
<button
|
|
104
|
+
type="button"
|
|
105
|
+
onClick={header.column.getToggleSortingHandler()}
|
|
106
|
+
className={cn("inline-flex items-center gap-1 hover:text-foreground")}
|
|
107
|
+
>
|
|
108
|
+
<table.FlexRender header={header} />
|
|
109
|
+
<SortIcon direction={header.column.getIsSorted()} />
|
|
110
|
+
</button>
|
|
111
|
+
)}
|
|
112
|
+
</TableHead>
|
|
113
|
+
))}
|
|
114
|
+
</TableRow>
|
|
115
|
+
))}
|
|
116
|
+
</TableHeader>
|
|
117
|
+
<TableBody>
|
|
118
|
+
{error !== null ? (
|
|
119
|
+
<TableRow>
|
|
120
|
+
<TableCell colSpan={columns.length} role="alert" className="text-destructive">
|
|
121
|
+
{error}
|
|
122
|
+
</TableCell>
|
|
123
|
+
</TableRow>
|
|
124
|
+
) : loading ? (
|
|
125
|
+
[0, 1, 2].map((row) => (
|
|
126
|
+
<TableRow key={row}>
|
|
127
|
+
{columns.map((_column, index) => (
|
|
128
|
+
<TableCell key={index}>
|
|
129
|
+
<Skeleton className="h-4 w-full" />
|
|
130
|
+
</TableCell>
|
|
131
|
+
))}
|
|
132
|
+
</TableRow>
|
|
133
|
+
))
|
|
134
|
+
) : rows.length === 0 ? (
|
|
135
|
+
<TableRow>
|
|
136
|
+
<TableCell colSpan={columns.length} className="text-center text-muted-foreground">
|
|
137
|
+
{emptyMessage}
|
|
138
|
+
</TableCell>
|
|
139
|
+
</TableRow>
|
|
140
|
+
) : (
|
|
141
|
+
rows.map((row) => (
|
|
142
|
+
<TableRow key={row.id}>
|
|
143
|
+
{row.getAllCells().map((cell) => (
|
|
144
|
+
<TableCell key={cell.id}>
|
|
145
|
+
<table.FlexRender cell={cell} />
|
|
146
|
+
</TableCell>
|
|
147
|
+
))}
|
|
148
|
+
</TableRow>
|
|
149
|
+
))
|
|
150
|
+
)}
|
|
151
|
+
</TableBody>
|
|
152
|
+
</Table>
|
|
153
|
+
<div className="flex items-center justify-end gap-2">
|
|
154
|
+
<span className="text-sm text-muted-foreground">
|
|
155
|
+
Page {pageIndex + 1} of {Math.max(table.getPageCount(), 1)}
|
|
156
|
+
</span>
|
|
157
|
+
<Button
|
|
158
|
+
variant="outline"
|
|
159
|
+
size="sm"
|
|
160
|
+
onClick={() => table.previousPage()}
|
|
161
|
+
disabled={!table.getCanPreviousPage()}
|
|
162
|
+
>
|
|
163
|
+
Previous
|
|
164
|
+
</Button>
|
|
165
|
+
<Button
|
|
166
|
+
variant="outline"
|
|
167
|
+
size="sm"
|
|
168
|
+
onClick={() => table.nextPage()}
|
|
169
|
+
disabled={!table.getCanNextPage()}
|
|
170
|
+
>
|
|
171
|
+
Next
|
|
172
|
+
</Button>
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "./utils.js";
|
|
4
|
+
|
|
5
|
+
export interface DetailItem {
|
|
6
|
+
label: React.ReactNode;
|
|
7
|
+
value: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface DetailPanelProps {
|
|
11
|
+
items: DetailItem[];
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function DetailPanel({ items, className }: DetailPanelProps) {
|
|
16
|
+
return (
|
|
17
|
+
<dl className={cn("divide-y divide-border rounded-lg border", className)}>
|
|
18
|
+
{items.map((item, index) => (
|
|
19
|
+
<div key={index} className="grid grid-cols-3 gap-4 px-4 py-3 text-sm">
|
|
20
|
+
<dt className="text-muted-foreground">{item.label}</dt>
|
|
21
|
+
<dd className="col-span-2 font-medium">{item.value}</dd>
|
|
22
|
+
</div>
|
|
23
|
+
))}
|
|
24
|
+
</dl>
|
|
25
|
+
);
|
|
26
|
+
}
|
package/src/dialog.tsx
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
5
|
+
import { X } from "lucide-react";
|
|
6
|
+
import { cn } from "./utils.js";
|
|
7
|
+
|
|
8
|
+
const Dialog = DialogPrimitive.Root;
|
|
9
|
+
const DialogTrigger = DialogPrimitive.Trigger;
|
|
10
|
+
const DialogClose = DialogPrimitive.Close;
|
|
11
|
+
const DialogPortal = DialogPrimitive.Portal;
|
|
12
|
+
|
|
13
|
+
const DialogOverlay = React.forwardRef<
|
|
14
|
+
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
|
15
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
|
16
|
+
>(({ className, ...props }, ref) => (
|
|
17
|
+
<DialogPrimitive.Overlay
|
|
18
|
+
ref={ref}
|
|
19
|
+
className={cn("fixed inset-0 z-50 bg-overlay/80", className)}
|
|
20
|
+
{...props}
|
|
21
|
+
/>
|
|
22
|
+
));
|
|
23
|
+
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
|
24
|
+
|
|
25
|
+
const DialogContent = React.forwardRef<
|
|
26
|
+
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
27
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
|
28
|
+
>(({ className, children, ...props }, ref) => (
|
|
29
|
+
<DialogPortal>
|
|
30
|
+
<DialogOverlay />
|
|
31
|
+
<DialogPrimitive.Content
|
|
32
|
+
ref={ref}
|
|
33
|
+
className={cn(
|
|
34
|
+
"fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg sm:rounded-lg",
|
|
35
|
+
className,
|
|
36
|
+
)}
|
|
37
|
+
{...props}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
<DialogPrimitive.Close className="absolute top-4 right-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-none disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
|
41
|
+
<X className="h-4 w-4" />
|
|
42
|
+
<span className="sr-only">Close</span>
|
|
43
|
+
</DialogPrimitive.Close>
|
|
44
|
+
</DialogPrimitive.Content>
|
|
45
|
+
</DialogPortal>
|
|
46
|
+
));
|
|
47
|
+
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
|
48
|
+
|
|
49
|
+
function DialogHeader({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
className={cn("flex flex-col space-y-1.5 text-center sm:text-left", className)}
|
|
53
|
+
{...props}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function DialogFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
|
59
|
+
return (
|
|
60
|
+
<div
|
|
61
|
+
className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)}
|
|
62
|
+
{...props}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const DialogTitle = React.forwardRef<
|
|
68
|
+
React.ElementRef<typeof DialogPrimitive.Title>,
|
|
69
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
|
70
|
+
>(({ className, ...props }, ref) => (
|
|
71
|
+
<DialogPrimitive.Title
|
|
72
|
+
ref={ref}
|
|
73
|
+
className={cn("text-lg leading-none font-semibold tracking-tight", className)}
|
|
74
|
+
{...props}
|
|
75
|
+
/>
|
|
76
|
+
));
|
|
77
|
+
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
|
78
|
+
|
|
79
|
+
const DialogDescription = React.forwardRef<
|
|
80
|
+
React.ElementRef<typeof DialogPrimitive.Description>,
|
|
81
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
|
82
|
+
>(({ className, ...props }, ref) => (
|
|
83
|
+
<DialogPrimitive.Description
|
|
84
|
+
ref={ref}
|
|
85
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
86
|
+
{...props}
|
|
87
|
+
/>
|
|
88
|
+
));
|
|
89
|
+
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
Dialog,
|
|
93
|
+
DialogClose,
|
|
94
|
+
DialogContent,
|
|
95
|
+
DialogDescription,
|
|
96
|
+
DialogFooter,
|
|
97
|
+
DialogHeader,
|
|
98
|
+
DialogOverlay,
|
|
99
|
+
DialogPortal,
|
|
100
|
+
DialogTitle,
|
|
101
|
+
DialogTrigger,
|
|
102
|
+
};
|