Skip to content

Pattern Components

Pattern components combine multiple UI components into reusable patterns.

Complete contact form with validation:

---
import ContactForm from '@/components/patterns/ContactForm.astro';
---
<ContactForm
action="/api/contact"
successMessage="Thanks! We'll be in touch soon."
/>
  • Name, email, and message fields
  • Client-side validation
  • Honeypot spam protection
  • Success/error states
  • Accessible form structure
PropTypeDefaultDescription
actionstring'/api/contact'Form submission endpoint
successMessagestring'Thank you...'Success message
errorMessagestring'Something went wrong...'Error message

Email subscription form:

---
import NewsletterForm from '@/components/patterns/NewsletterForm.astro';
---
<NewsletterForm
action="/api/newsletter"
placeholder="Enter your email"
buttonText="Subscribe"
/>
  • Single email field
  • Inline button layout
  • Loading state
  • Success/error feedback
PropTypeDefaultDescription
actionstring'/api/newsletter'Submission endpoint
placeholderstring'Enter your email'Input placeholder
buttonTextstring'Subscribe'Button text

Wrapper for consistent form field layouts:

---
import FormField from '@/components/patterns/FormField.astro';
---
<FormField
label="Email"
name="email"
type="email"
required
hint="We'll never share your email"
/>
PropTypeDefaultDescription
labelstringField label
namestringInput name
typestring'text'Input type
requiredbooleanfalseRequired field
hintstringHelper text
errorstringError message
---
import PageLayout from '@/layouts/PageLayout.astro';
import ContactForm from '@/components/patterns/ContactForm.astro';
---
<PageLayout title="Contact">
<section class="py-16">
<div class="container max-w-xl">
<h1 class="text-4xl font-bold mb-8">Contact Us</h1>
<ContactForm />
</div>
</section>
</PageLayout>
<section class="bg-surface-invert py-16">
<div class="container max-w-md text-center">
<h2 class="text-2xl font-bold text-on-invert mb-4">
Stay Updated
</h2>
<p class="text-on-invert-muted mb-6">
Get the latest news delivered to your inbox.
</p>
<NewsletterForm />
</div>
</section>
<form action="/api/signup" method="post" class="space-y-4">
<FormField
label="Full Name"
name="name"
required
/>
<FormField
label="Email"
name="email"
type="email"
required
/>
<FormField
label="Company"
name="company"
hint="Optional"
/>
<Button type="submit" fullWidth>
Create Account
</Button>
</form>