Please use Desktop to view and interact with components
Blocks500mseaseOut
Contact Form
Contact form section with animated inputs, validation, and form handling
contactforminputsvalidationshadcn
Useto navigate between components
Preview
Get In Touch
Fill out the form below and we'll get back to you as soon as possible.
This component requires shadcn/ui
This component uses shadcn/ui components. Make sure you have shadcn/ui set up in your project.
- Install shadcn/ui:
npx shadcn-ui@latest init - Install required components based on the imports in the code (e.g.,
npx shadcn-ui@latest add button) - Ensure your
tailwind.config.tsandglobals.cssare configured as per shadcn/ui documentation
Code
TypeScript + React
'use client'
import { useState } from 'react'
import { motion } from 'framer-motion'
import { Card } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Textarea } from '@/components/ui/textarea'
import { Label } from '@/components/ui/label'
import { Send, Mail, Phone, MessageSquare } from 'lucide-react'
export function ContactFormSection() {
const [formData, setFormData] = useState({
name: '',
email: '',
phone: '',
message: '',
})
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
// Handle form submission
console.log('Form submitted:', formData)
}
const handleChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => {
setFormData({
...formData,
[e.target.name]: e.target.value,
})
}
const containerVariants = {
hidden: { opacity: 0 },
visible: {
opacity: 1,
transition: {
staggerChildren: 0.1,
},
},
}
const itemVariants = {
hidden: { opacity: 0, x: -20 },
visible: {
opacity: 1,
x: 0,
transition: { duration: 0.5 },
},
}
return (
<section className="px-4 py-20 md:py-24">
<div className="mx-auto max-w-6xl">
<motion.div
initial={{ opacity: 0, y: -20 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true }}
transition={{ duration: 0.6 }}
className="mb-12 text-center"
>
<h2 className="mb-4 text-3xl font-bold md:text-4xl">
Get In Touch
</h2>
<p className="text-muted-foreground">
Fill out the form below and we'll get back to you as soon as
possible.
</p>
</motion.div>
<motion.div
variants={containerVariants}
initial="hidden"
whileInView="visible"
viewport={{ once: true }}
>
<Card className="border-2 p-6 md:p-8">
<form onSubmit={handleSubmit} className="space-y-6">
<motion.div variants={itemVariants} className="grid gap-4 md:grid-cols-2">
<div className="space-y-2">
<Label htmlFor="name">Full Name</Label>
<Input
id="name"
name="name"
type="text"
placeholder="John Doe"
value={formData.name}
onChange={handleChange}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input
id="email"
name="email"
type="email"
placeholder="john@example.com"
value={formData.email}
onChange={handleChange}
className="pl-10"
required
/>
</div>
</div>
</motion.div>
<motion.div variants={itemVariants} className="space-y-2">
<Label htmlFor="phone">Phone Number</Label>
<div className="relative">
<Phone className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input
id="phone"
name="phone"
type="tel"
placeholder="+1 (555) 123-4567"
value={formData.phone}
onChange={handleChange}
className="pl-10"
/>
</div>
</motion.div>
<motion.div variants={itemVariants} className="space-y-2">
<Label htmlFor="message">Message</Label>
<div className="relative">
<MessageSquare className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
<Textarea
id="message"
name="message"
placeholder="Tell us about your project..."
value={formData.message}
onChange={handleChange}
className="min-h-[120px] pl-10"
required
/>
</div>
</motion.div>
<motion.div variants={itemVariants}>
<Button type="submit" size="lg" className="w-full group gap-2">
Send Message
<Send className="h-4 w-4 transition-transform group-hover:translate-x-1" />
</Button>
</motion.div>
</form>
</Card>
</motion.div>
</div>
</section>
)
}
How to Use
- 1Install Framer Motion:
npm install framer-motion - 2Set up shadcn/ui: Install shadcn/ui components used in this code. Check the imports in the code above and install the required components (e.g.,
npx shadcn-ui@latest add button card) - 3Copy the code from above
- 4Paste it into your project and customize as needed
- 5Colors are customizable via Tailwind CSS classes. The default theme uses dark mode colors defined in your globals.css file