Skip to content

Instantly share code, notes, and snippets.

@01matreece
Created May 24, 2025 21:10
Show Gist options
  • Save 01matreece/5a3f670b538e9e3dc4afb7ebd57b57e3 to your computer and use it in GitHub Desktop.
Save 01matreece/5a3f670b538e9e3dc4afb7ebd57b57e3 to your computer and use it in GitHub Desktop.
AI Generated React Component with Tailwind CSS

AI Generated React Component

This component was generated by AI. You can run it in CodeSandbox or any React environment with Tailwind CSS.

Component Code

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>
  )
}
import React from "react";
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>
)
}
export default function App() {
return (
<div className="p-8 max-w-4xl mx-auto">
<h1 className="text-2xl font-bold mb-4">AI Generated Component Demo</h1>
<div className="border p-4 rounded-lg shadow-sm">
<TestComponent />
</div>
</div>
);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>AI Generated React Component</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./styles.css";
const rootElement = document.getElementById("root");
const root = createRoot(rootElement);
root.render(
<StrictMode>
<App />
</StrictMode>
);
{
"name": "ai-generated-component",
"version": "1.0.0",
"description": "React component generated by AI",
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "^5.0.1",
"tailwindcss": "^3.3.0",
"@tailwindcss/typography": "^0.5.9",
"postcss": "^8.4.23",
"autoprefixer": "^10.4.14"
},
"devDependencies": {
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [require('@tailwindcss/typography')],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment