formcn 1.0.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 (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +294 -0
  3. package/bin/index.js +71 -0
  4. package/generators/form-generator.js +152 -0
  5. package/generators/form-ui-templates.js +183 -0
  6. package/generators/multi-form-generator.js +257 -0
  7. package/generators/schema-generator.js +89 -0
  8. package/package.json +46 -0
  9. package/test/README.md +73 -0
  10. package/test/components.json +22 -0
  11. package/test/eslint.config.js +23 -0
  12. package/test/index.html +13 -0
  13. package/test/package-lock.json +4759 -0
  14. package/test/package.json +46 -0
  15. package/test/public/vite.svg +1 -0
  16. package/test/src/App.css +42 -0
  17. package/test/src/App.tsx +7 -0
  18. package/test/src/assets/react.svg +1 -0
  19. package/test/src/components/ui/button.tsx +62 -0
  20. package/test/src/components/ui/checkbox.tsx +32 -0
  21. package/test/src/components/ui/field.tsx +246 -0
  22. package/test/src/components/ui/input-group.tsx +170 -0
  23. package/test/src/components/ui/input.tsx +21 -0
  24. package/test/src/components/ui/label.tsx +22 -0
  25. package/test/src/components/ui/radio-group.tsx +43 -0
  26. package/test/src/components/ui/select.tsx +188 -0
  27. package/test/src/components/ui/separator.tsx +28 -0
  28. package/test/src/components/ui/textarea.tsx +18 -0
  29. package/test/src/index.css +123 -0
  30. package/test/src/lib/utils.ts +6 -0
  31. package/test/src/main.tsx +10 -0
  32. package/test/tsconfig.app.json +33 -0
  33. package/test/tsconfig.json +13 -0
  34. package/test/tsconfig.node.json +26 -0
  35. package/test/vite.config.ts +14 -0
  36. package/utils/ensurePackages.js +62 -0
  37. package/utils/lib.js +22 -0
  38. package/utils/prompts.js +200 -0
  39. package/utils/tailwind-presets.js +132 -0
  40. package/utils/templates.js +103 -0
  41. package/utils/test.js +136 -0
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "test",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc -b && vite build",
9
+ "lint": "eslint .",
10
+ "preview": "vite preview"
11
+ },
12
+ "dependencies": {
13
+ "@hookform/resolvers": "^5.2.2",
14
+ "@radix-ui/react-checkbox": "^1.3.3",
15
+ "@radix-ui/react-label": "^2.1.8",
16
+ "@radix-ui/react-radio-group": "^1.3.8",
17
+ "@radix-ui/react-select": "^2.2.6",
18
+ "@radix-ui/react-separator": "^1.1.8",
19
+ "@radix-ui/react-slot": "^1.2.4",
20
+ "@tailwindcss/vite": "^4.1.18",
21
+ "class-variance-authority": "^0.7.1",
22
+ "clsx": "^2.1.1",
23
+ "lucide-react": "^0.562.0",
24
+ "react": "^19.2.0",
25
+ "react-dom": "^19.2.0",
26
+ "react-hook-form": "^7.69.0",
27
+ "tailwind-merge": "^3.4.0",
28
+ "tailwindcss": "^4.1.18",
29
+ "zod": "^4.2.1"
30
+ },
31
+ "devDependencies": {
32
+ "@eslint/js": "^9.39.1",
33
+ "@types/node": "^24.10.1",
34
+ "@types/react": "^19.2.5",
35
+ "@types/react-dom": "^19.2.3",
36
+ "@vitejs/plugin-react": "^5.1.1",
37
+ "eslint": "^9.39.1",
38
+ "eslint-plugin-react-hooks": "^7.0.1",
39
+ "eslint-plugin-react-refresh": "^0.4.24",
40
+ "globals": "^16.5.0",
41
+ "tw-animate-css": "^1.4.0",
42
+ "typescript": "~5.9.3",
43
+ "typescript-eslint": "^8.46.4",
44
+ "vite": "^7.2.4"
45
+ }
46
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
@@ -0,0 +1,42 @@
1
+ #root {
2
+ max-width: 1280px;
3
+ margin: 0 auto;
4
+ padding: 2rem;
5
+ text-align: center;
6
+ }
7
+
8
+ .logo {
9
+ height: 6em;
10
+ padding: 1.5em;
11
+ will-change: filter;
12
+ transition: filter 300ms;
13
+ }
14
+ .logo:hover {
15
+ filter: drop-shadow(0 0 2em #646cffaa);
16
+ }
17
+ .logo.react:hover {
18
+ filter: drop-shadow(0 0 2em #61dafbaa);
19
+ }
20
+
21
+ @keyframes logo-spin {
22
+ from {
23
+ transform: rotate(0deg);
24
+ }
25
+ to {
26
+ transform: rotate(360deg);
27
+ }
28
+ }
29
+
30
+ @media (prefers-reduced-motion: no-preference) {
31
+ a:nth-of-type(2) .logo {
32
+ animation: logo-spin infinite 20s linear;
33
+ }
34
+ }
35
+
36
+ .card {
37
+ padding: 2em;
38
+ }
39
+
40
+ .read-the-docs {
41
+ color: #888;
42
+ }
@@ -0,0 +1,7 @@
1
+ import "./App.css";
2
+
3
+ function App() {
4
+ return <></>;
5
+ }
6
+
7
+ export default App;
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
@@ -0,0 +1,62 @@
1
+ import * as React from "react"
2
+ import { Slot } from "@radix-ui/react-slot"
3
+ import { cva, type VariantProps } from "class-variance-authority"
4
+
5
+ import { cn } from "@/lib/utils"
6
+
7
+ const buttonVariants = cva(
8
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
13
+ destructive:
14
+ "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
15
+ outline:
16
+ "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
17
+ secondary:
18
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80",
19
+ ghost:
20
+ "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
21
+ link: "text-primary underline-offset-4 hover:underline",
22
+ },
23
+ size: {
24
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
25
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
26
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
27
+ icon: "size-9",
28
+ "icon-sm": "size-8",
29
+ "icon-lg": "size-10",
30
+ },
31
+ },
32
+ defaultVariants: {
33
+ variant: "default",
34
+ size: "default",
35
+ },
36
+ }
37
+ )
38
+
39
+ function Button({
40
+ className,
41
+ variant = "default",
42
+ size = "default",
43
+ asChild = false,
44
+ ...props
45
+ }: React.ComponentProps<"button"> &
46
+ VariantProps<typeof buttonVariants> & {
47
+ asChild?: boolean
48
+ }) {
49
+ const Comp = asChild ? Slot : "button"
50
+
51
+ return (
52
+ <Comp
53
+ data-slot="button"
54
+ data-variant={variant}
55
+ data-size={size}
56
+ className={cn(buttonVariants({ variant, size, className }))}
57
+ {...props}
58
+ />
59
+ )
60
+ }
61
+
62
+ export { Button, buttonVariants }
@@ -0,0 +1,32 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
5
+ import { CheckIcon } from "lucide-react"
6
+
7
+ import { cn } from "@/lib/utils"
8
+
9
+ function Checkbox({
10
+ className,
11
+ ...props
12
+ }: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
13
+ return (
14
+ <CheckboxPrimitive.Root
15
+ data-slot="checkbox"
16
+ className={cn(
17
+ "peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
18
+ className
19
+ )}
20
+ {...props}
21
+ >
22
+ <CheckboxPrimitive.Indicator
23
+ data-slot="checkbox-indicator"
24
+ className="grid place-content-center text-current transition-none"
25
+ >
26
+ <CheckIcon className="size-3.5" />
27
+ </CheckboxPrimitive.Indicator>
28
+ </CheckboxPrimitive.Root>
29
+ )
30
+ }
31
+
32
+ export { Checkbox }
@@ -0,0 +1,246 @@
1
+ import { useMemo } from "react"
2
+ import { cva, type VariantProps } from "class-variance-authority"
3
+
4
+ import { cn } from "@/lib/utils"
5
+ import { Label } from "@/components/ui/label"
6
+ import { Separator } from "@/components/ui/separator"
7
+
8
+ function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
9
+ return (
10
+ <fieldset
11
+ data-slot="field-set"
12
+ className={cn(
13
+ "flex flex-col gap-6",
14
+ "has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
15
+ className
16
+ )}
17
+ {...props}
18
+ />
19
+ )
20
+ }
21
+
22
+ function FieldLegend({
23
+ className,
24
+ variant = "legend",
25
+ ...props
26
+ }: React.ComponentProps<"legend"> & { variant?: "legend" | "label" }) {
27
+ return (
28
+ <legend
29
+ data-slot="field-legend"
30
+ data-variant={variant}
31
+ className={cn(
32
+ "mb-3 font-medium",
33
+ "data-[variant=legend]:text-base",
34
+ "data-[variant=label]:text-sm",
35
+ className
36
+ )}
37
+ {...props}
38
+ />
39
+ )
40
+ }
41
+
42
+ function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
43
+ return (
44
+ <div
45
+ data-slot="field-group"
46
+ className={cn(
47
+ "group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4",
48
+ className
49
+ )}
50
+ {...props}
51
+ />
52
+ )
53
+ }
54
+
55
+ const fieldVariants = cva(
56
+ "group/field flex w-full gap-3 data-[invalid=true]:text-destructive",
57
+ {
58
+ variants: {
59
+ orientation: {
60
+ vertical: ["flex-col [&>*]:w-full [&>.sr-only]:w-auto"],
61
+ horizontal: [
62
+ "flex-row items-center",
63
+ "[&>[data-slot=field-label]]:flex-auto",
64
+ "has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
65
+ ],
66
+ responsive: [
67
+ "flex-col [&>*]:w-full [&>.sr-only]:w-auto @md/field-group:flex-row @md/field-group:items-center @md/field-group:[&>*]:w-auto",
68
+ "@md/field-group:[&>[data-slot=field-label]]:flex-auto",
69
+ "@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
70
+ ],
71
+ },
72
+ },
73
+ defaultVariants: {
74
+ orientation: "vertical",
75
+ },
76
+ }
77
+ )
78
+
79
+ function Field({
80
+ className,
81
+ orientation = "vertical",
82
+ ...props
83
+ }: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>) {
84
+ return (
85
+ <div
86
+ role="group"
87
+ data-slot="field"
88
+ data-orientation={orientation}
89
+ className={cn(fieldVariants({ orientation }), className)}
90
+ {...props}
91
+ />
92
+ )
93
+ }
94
+
95
+ function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
96
+ return (
97
+ <div
98
+ data-slot="field-content"
99
+ className={cn(
100
+ "group/field-content flex flex-1 flex-col gap-1.5 leading-snug",
101
+ className
102
+ )}
103
+ {...props}
104
+ />
105
+ )
106
+ }
107
+
108
+ function FieldLabel({
109
+ className,
110
+ ...props
111
+ }: React.ComponentProps<typeof Label>) {
112
+ return (
113
+ <Label
114
+ data-slot="field-label"
115
+ className={cn(
116
+ "group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50",
117
+ "has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4",
118
+ "has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10",
119
+ className
120
+ )}
121
+ {...props}
122
+ />
123
+ )
124
+ }
125
+
126
+ function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
127
+ return (
128
+ <div
129
+ data-slot="field-label"
130
+ className={cn(
131
+ "flex w-fit items-center gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50",
132
+ className
133
+ )}
134
+ {...props}
135
+ />
136
+ )
137
+ }
138
+
139
+ function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
140
+ return (
141
+ <p
142
+ data-slot="field-description"
143
+ className={cn(
144
+ "text-muted-foreground text-sm leading-normal font-normal group-has-[[data-orientation=horizontal]]/field:text-balance",
145
+ "last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5",
146
+ "[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
147
+ className
148
+ )}
149
+ {...props}
150
+ />
151
+ )
152
+ }
153
+
154
+ function FieldSeparator({
155
+ children,
156
+ className,
157
+ ...props
158
+ }: React.ComponentProps<"div"> & {
159
+ children?: React.ReactNode
160
+ }) {
161
+ return (
162
+ <div
163
+ data-slot="field-separator"
164
+ data-content={!!children}
165
+ className={cn(
166
+ "relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2",
167
+ className
168
+ )}
169
+ {...props}
170
+ >
171
+ <Separator className="absolute inset-0 top-1/2" />
172
+ {children && (
173
+ <span
174
+ className="bg-background text-muted-foreground relative mx-auto block w-fit px-2"
175
+ data-slot="field-separator-content"
176
+ >
177
+ {children}
178
+ </span>
179
+ )}
180
+ </div>
181
+ )
182
+ }
183
+
184
+ function FieldError({
185
+ className,
186
+ children,
187
+ errors,
188
+ ...props
189
+ }: React.ComponentProps<"div"> & {
190
+ errors?: Array<{ message?: string } | undefined>
191
+ }) {
192
+ const content = useMemo(() => {
193
+ if (children) {
194
+ return children
195
+ }
196
+
197
+ if (!errors?.length) {
198
+ return null
199
+ }
200
+
201
+ const uniqueErrors = [
202
+ ...new Map(errors.map((error) => [error?.message, error])).values(),
203
+ ]
204
+
205
+ if (uniqueErrors?.length == 1) {
206
+ return uniqueErrors[0]?.message
207
+ }
208
+
209
+ return (
210
+ <ul className="ml-4 flex list-disc flex-col gap-1">
211
+ {uniqueErrors.map(
212
+ (error, index) =>
213
+ error?.message && <li key={index}>{error.message}</li>
214
+ )}
215
+ </ul>
216
+ )
217
+ }, [children, errors])
218
+
219
+ if (!content) {
220
+ return null
221
+ }
222
+
223
+ return (
224
+ <div
225
+ role="alert"
226
+ data-slot="field-error"
227
+ className={cn("text-destructive text-sm font-normal", className)}
228
+ {...props}
229
+ >
230
+ {content}
231
+ </div>
232
+ )
233
+ }
234
+
235
+ export {
236
+ Field,
237
+ FieldLabel,
238
+ FieldDescription,
239
+ FieldError,
240
+ FieldGroup,
241
+ FieldLegend,
242
+ FieldSeparator,
243
+ FieldSet,
244
+ FieldContent,
245
+ FieldTitle,
246
+ }
@@ -0,0 +1,170 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { cva, type VariantProps } from "class-variance-authority"
5
+
6
+ import { cn } from "@/lib/utils"
7
+ import { Button } from "@/components/ui/button"
8
+ import { Input } from "@/components/ui/input"
9
+ import { Textarea } from "@/components/ui/textarea"
10
+
11
+ function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
12
+ return (
13
+ <div
14
+ data-slot="input-group"
15
+ role="group"
16
+ className={cn(
17
+ "group/input-group border-input dark:bg-input/30 relative flex w-full items-center rounded-md border shadow-xs transition-[color,box-shadow] outline-none",
18
+ "h-9 min-w-0 has-[>textarea]:h-auto",
19
+
20
+ // Variants based on alignment.
21
+ "has-[>[data-align=inline-start]]:[&>input]:pl-2",
22
+ "has-[>[data-align=inline-end]]:[&>input]:pr-2",
23
+ "has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3",
24
+ "has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3",
25
+
26
+ // Focus state.
27
+ "has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot=input-group-control]:focus-visible]:ring-[3px]",
28
+
29
+ // Error state.
30
+ "has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",
31
+
32
+ className
33
+ )}
34
+ {...props}
35
+ />
36
+ )
37
+ }
38
+
39
+ const inputGroupAddonVariants = cva(
40
+ "text-muted-foreground flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium select-none [&>svg:not([class*='size-'])]:size-4 [&>kbd]:rounded-[calc(var(--radius)-5px)] group-data-[disabled=true]/input-group:opacity-50",
41
+ {
42
+ variants: {
43
+ align: {
44
+ "inline-start":
45
+ "order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]",
46
+ "inline-end":
47
+ "order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]",
48
+ "block-start":
49
+ "order-first w-full justify-start px-3 pt-3 [.border-b]:pb-3 group-has-[>input]/input-group:pt-2.5",
50
+ "block-end":
51
+ "order-last w-full justify-start px-3 pb-3 [.border-t]:pt-3 group-has-[>input]/input-group:pb-2.5",
52
+ },
53
+ },
54
+ defaultVariants: {
55
+ align: "inline-start",
56
+ },
57
+ }
58
+ )
59
+
60
+ function InputGroupAddon({
61
+ className,
62
+ align = "inline-start",
63
+ ...props
64
+ }: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
65
+ return (
66
+ <div
67
+ role="group"
68
+ data-slot="input-group-addon"
69
+ data-align={align}
70
+ className={cn(inputGroupAddonVariants({ align }), className)}
71
+ onClick={(e) => {
72
+ if ((e.target as HTMLElement).closest("button")) {
73
+ return
74
+ }
75
+ e.currentTarget.parentElement?.querySelector("input")?.focus()
76
+ }}
77
+ {...props}
78
+ />
79
+ )
80
+ }
81
+
82
+ const inputGroupButtonVariants = cva(
83
+ "text-sm shadow-none flex gap-2 items-center",
84
+ {
85
+ variants: {
86
+ size: {
87
+ xs: "h-6 gap-1 px-2 rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-3.5 has-[>svg]:px-2",
88
+ sm: "h-8 px-2.5 gap-1.5 rounded-md has-[>svg]:px-2.5",
89
+ "icon-xs":
90
+ "size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
91
+ "icon-sm": "size-8 p-0 has-[>svg]:p-0",
92
+ },
93
+ },
94
+ defaultVariants: {
95
+ size: "xs",
96
+ },
97
+ }
98
+ )
99
+
100
+ function InputGroupButton({
101
+ className,
102
+ type = "button",
103
+ variant = "ghost",
104
+ size = "xs",
105
+ ...props
106
+ }: Omit<React.ComponentProps<typeof Button>, "size"> &
107
+ VariantProps<typeof inputGroupButtonVariants>) {
108
+ return (
109
+ <Button
110
+ type={type}
111
+ data-size={size}
112
+ variant={variant}
113
+ className={cn(inputGroupButtonVariants({ size }), className)}
114
+ {...props}
115
+ />
116
+ )
117
+ }
118
+
119
+ function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
120
+ return (
121
+ <span
122
+ className={cn(
123
+ "text-muted-foreground flex items-center gap-2 text-sm [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
124
+ className
125
+ )}
126
+ {...props}
127
+ />
128
+ )
129
+ }
130
+
131
+ function InputGroupInput({
132
+ className,
133
+ ...props
134
+ }: React.ComponentProps<"input">) {
135
+ return (
136
+ <Input
137
+ data-slot="input-group-control"
138
+ className={cn(
139
+ "flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent",
140
+ className
141
+ )}
142
+ {...props}
143
+ />
144
+ )
145
+ }
146
+
147
+ function InputGroupTextarea({
148
+ className,
149
+ ...props
150
+ }: React.ComponentProps<"textarea">) {
151
+ return (
152
+ <Textarea
153
+ data-slot="input-group-control"
154
+ className={cn(
155
+ "flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",
156
+ className
157
+ )}
158
+ {...props}
159
+ />
160
+ )
161
+ }
162
+
163
+ export {
164
+ InputGroup,
165
+ InputGroupAddon,
166
+ InputGroupButton,
167
+ InputGroupText,
168
+ InputGroupInput,
169
+ InputGroupTextarea,
170
+ }
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+
3
+ import { cn } from "@/lib/utils";
4
+
5
+ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
6
+ return (
7
+ <input
8
+ type={type}
9
+ data-slot="input"
10
+ className={cn(
11
+ "file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
12
+ "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
13
+ "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
14
+ className
15
+ )}
16
+ {...props}
17
+ />
18
+ );
19
+ }
20
+
21
+ export { Input };
@@ -0,0 +1,22 @@
1
+ import * as React from "react"
2
+ import * as LabelPrimitive from "@radix-ui/react-label"
3
+
4
+ import { cn } from "@/lib/utils"
5
+
6
+ function Label({
7
+ className,
8
+ ...props
9
+ }: React.ComponentProps<typeof LabelPrimitive.Root>) {
10
+ return (
11
+ <LabelPrimitive.Root
12
+ data-slot="label"
13
+ className={cn(
14
+ "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
15
+ className
16
+ )}
17
+ {...props}
18
+ />
19
+ )
20
+ }
21
+
22
+ export { Label }