@zedtech/zedkit-ui 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +48 -2
- 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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zedtech-fr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zedtech/zedkit-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Admin UI kit: design tokens, dark/light theme, and shadcn/ui-based
|
|
4
|
+
building blocks (MIT, see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)).
|
|
5
|
+
Neutral and calm by default. Not published to npm yet — install
|
|
6
|
+
from a packed tarball.
|
|
7
|
+
|
|
8
|
+
## Adopt in 3 lines
|
|
9
|
+
|
|
10
|
+
```css
|
|
11
|
+
/* app/globals.css (Tailwind v4, PostCSS or Vite plugin) */
|
|
12
|
+
@import "@zedtech/zedkit-ui/styles.css";
|
|
13
|
+
@source "../node_modules/@zedtech/zedkit-ui/src/**/*.{ts,tsx}";
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { cn } from "@zedtech/zedkit-ui"; // components land per slice; see CATALOG.md
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Needs: React 19 + Tailwind v4 in the consumer (peer dependencies),
|
|
21
|
+
`.dark` class strategy for dark mode (`next-themes` recommended).
|
|
22
|
+
|
|
23
|
+
## Contents
|
|
24
|
+
|
|
25
|
+
- `styles.css`: tokens + dark/light theme preset.
|
|
26
|
+
- `cn()`: classnames merge.
|
|
27
|
+
- Primitives: `Button`, `Badge`, `Input`, `Label`, `Separator`,
|
|
28
|
+
`Skeleton` (see CATALOG.md for usage).
|
|
29
|
+
- Overlays: `Dialog` set, `ConfirmDialog`, `Toaster`, `SecretField`.
|
|
30
|
+
- Data: `DataTable` (sort, filter, pagination, empty/loading/
|
|
31
|
+
error states) + `Table` primitives.
|
|
32
|
+
- Layout: `AppShell` (sidebar + topbar + main slots), `PageHeader`.
|
|
33
|
+
- Wizard: `WizardSteps` (step indicator), `OptionCards` (multi-select cards).
|
|
34
|
+
- Detail: `DetailPanel` (key-value rows), `LivePulse` (live indicator).
|
|
35
|
+
- Planned next: preview gallery, frontend guardrails.
|
|
36
|
+
|
|
37
|
+
## Develop
|
|
38
|
+
|
|
39
|
+
`pnpm --filter @zedtech/zedkit-ui test|typecheck|lint|build`.
|
|
40
|
+
Component tests render with Testing Library + jsdom.
|
|
41
|
+
|
|
42
|
+
## Gallery
|
|
43
|
+
|
|
44
|
+
`pnpm --filter @zedtech/zedkit-ui preview` builds and serves a static gallery
|
|
45
|
+
of every component in every state at http://127.0.0.1:4123/ (`/dark`
|
|
46
|
+
for the dark theme). Static server render for visual review only —
|
|
47
|
+
behavior stays covered by unit tests. `pnpm --filter @zedtech/zedkit-ui
|
|
48
|
+
smoke` runs the Playwright smoke over both themes (sections render,
|
|
49
|
+
zero console errors) and writes screenshots to test-results/.
|
package/package.json
CHANGED
|
@@ -1,6 +1,86 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zedtech/zedkit-ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"registry": "https://registry.npmjs.org/"
|
|
7
|
+
},
|
|
8
|
+
"description": "Admin UI kit: design tokens, dark/light theme, shadcn/ui-based components (MIT, see THIRD_PARTY_NOTICES.md).",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/zedtech-fr/zedkit",
|
|
13
|
+
"directory": "packages/ui"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"*.css"
|
|
18
|
+
],
|
|
19
|
+
"imports": {
|
|
20
|
+
"#*": "./src/*",
|
|
21
|
+
"#preview/*": "./preview/*"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./styles.css": "./src/styles.css",
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"src"
|
|
36
|
+
],
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": "19.3.1",
|
|
39
|
+
"react-dom": "19.3.1",
|
|
40
|
+
"tailwindcss": "4.3.3"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@hookform/resolvers": "6.0.0",
|
|
44
|
+
"@radix-ui/react-checkbox": "1.4.1",
|
|
45
|
+
"@radix-ui/react-dialog": "1.3.1",
|
|
46
|
+
"@radix-ui/react-dropdown-menu": "2.2.1",
|
|
47
|
+
"@radix-ui/react-label": "2.1.17",
|
|
48
|
+
"@radix-ui/react-separator": "1.2.0",
|
|
49
|
+
"@radix-ui/react-select": "2.4.1",
|
|
50
|
+
"@radix-ui/react-slot": "1.5.0",
|
|
51
|
+
"@radix-ui/react-switch": "1.4.1",
|
|
52
|
+
"@radix-ui/react-tabs": "1.2.1",
|
|
53
|
+
"@tanstack/react-table": "9.3.1",
|
|
54
|
+
"class-variance-authority": "0.7.1",
|
|
55
|
+
"clsx": "2.1.1",
|
|
56
|
+
"lucide-react": "1.61.0",
|
|
57
|
+
"next-themes": "0.4.6",
|
|
58
|
+
"react-hook-form": "7.91.0",
|
|
59
|
+
"sonner": "2.0.8",
|
|
60
|
+
"tailwind-merge": "3.7.0",
|
|
61
|
+
"zod": "4.6.7"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@tailwindcss/postcss": "4.3.3",
|
|
65
|
+
"@testing-library/react": "16.3.3",
|
|
66
|
+
"@testing-library/user-event": "14.6.8",
|
|
67
|
+
"@types/react": "19.3.0",
|
|
68
|
+
"@types/react-dom": "19.3.0",
|
|
69
|
+
"axe-core": "4.14.0",
|
|
70
|
+
"jsdom": "30.1.3",
|
|
71
|
+
"postcss": "8.5.31",
|
|
72
|
+
"typescript": "5.9.3",
|
|
73
|
+
"vitest": "2.1.9",
|
|
74
|
+
"vitest-axe": "0.1.0",
|
|
75
|
+
"@zedtech/zedkit-core": "0.0.0"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "tsc -p tsconfig.json",
|
|
79
|
+
"test": "vitest run",
|
|
80
|
+
"typecheck": "tsc --noEmit -p tsconfig.tests.json",
|
|
81
|
+
"lint": "eslint src tests preview",
|
|
82
|
+
"preview:build": "pnpm build && node ./preview/build.mjs",
|
|
83
|
+
"preview": "pnpm preview:build && node ./preview/serve.mjs",
|
|
84
|
+
"smoke": "playwright test"
|
|
85
|
+
}
|
|
6
86
|
}
|
package/src/alert.tsx
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
|
|
4
|
+
import { cn } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
const alertVariants = cva(
|
|
7
|
+
"relative w-full rounded-lg border px-4 py-3 text-sm [&>svg]:absolute [&>svg]:top-4 [&>svg]:left-4 [&>svg]:text-foreground [&>svg+div]:translate-y-[-3px] [&>svg~*]:pl-7",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "bg-background text-foreground",
|
|
12
|
+
destructive: "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
defaultVariants: {
|
|
16
|
+
variant: "default",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const Alert = React.forwardRef<
|
|
22
|
+
HTMLDivElement,
|
|
23
|
+
React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
|
|
24
|
+
>(({ className, variant, ...props }, ref) => (
|
|
25
|
+
<div ref={ref} role="alert" className={cn(alertVariants({ variant }), className)} {...props} />
|
|
26
|
+
));
|
|
27
|
+
Alert.displayName = "Alert";
|
|
28
|
+
|
|
29
|
+
const AlertTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>(
|
|
30
|
+
// Children are explicit (not part of the props spread) so the
|
|
31
|
+
// heading-has-content rule can see them; renders identically.
|
|
32
|
+
({ className, children, ...props }, ref) => (
|
|
33
|
+
<h5 ref={ref} className={cn("mb-1 leading-none font-medium tracking-tight", className)} {...props}>
|
|
34
|
+
{children}
|
|
35
|
+
</h5>
|
|
36
|
+
),
|
|
37
|
+
);
|
|
38
|
+
AlertTitle.displayName = "AlertTitle";
|
|
39
|
+
|
|
40
|
+
const AlertDescription = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
|
|
41
|
+
({ className, ...props }, ref) => (
|
|
42
|
+
<div ref={ref} className={cn("text-sm [&_p]:leading-relaxed", className)} {...props} />
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
AlertDescription.displayName = "AlertDescription";
|
|
46
|
+
|
|
47
|
+
export { Alert, AlertTitle, AlertDescription };
|
|
@@ -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
|
+
}
|