This component was generated by AI. You can run it in CodeSandbox or any React environment with Tailwind CSS.
import { Button } from "./components/ui/button"
import { Input } from "./components/ui/input"
import { Label } from "./components/ui/label"
import { Card, CardHeader, CardTitle, CardContent, CardFooter } from "./components/ui/card"
import { useState } from "react"
export default function ShadcnForm() {
const [name, setName] = useState("")
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
const [error, setError] = useState("")
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
if (!name || !email || !password) {
setError("Please fill in all fields")
return
}
// Handle form submission logic here
console.log({ name, email, password })
setError("")
setName("")
setEmail("")
setPassword("")
}
return (
<Card className="w-full max-w-md mx-auto">
<CardHeader>
<CardTitle>Sign Up</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<form onSubmit={handleSubmit}>
<div className="space-y-2">
<Label htmlFor="name">Name</Label>
<Input
id="name"
placeholder="Enter your name"
value={name}
onChange={(e) => setName(e.target.value)}
/>
</div>
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<Input
id="email"
type="email"
placeholder="Enter your email"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
</div>
<div className="space-y-2">
<Label htmlFor="password">Password</Label>
<Input
id="password"
type="password"
placeholder="Enter your password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
</div>
{error && (
<div className="text-red-500 font-medium">{error}</div>
)}
<Button type="submit" className="w-full">
Sign Up
</Button>
</form>
</CardContent>
<CardFooter className="text-center">
Already have an account? <a href="#" className="text-primary underline">Sign In</a>
</CardFooter>
</Card>
)
}