The Email Compose Card provides a polished interface for composing emails with recipient management, inline editing, and validation. Perfect for AI agents that need to draft and send emails.
Preview
import { EmailComposeCard } from "@/components/ui/email-compose-card" ;
const emailData = {
to: [ "[email protected] " ],
subject: "Project Update" ,
body: "Hi there, \n\n I wanted to share the latest updates on our project. We've made significant progress this week... \n\n Best regards"
};
function handleSend ( data ) {
console . log ( "Sending email:" , data );
// Your email sending logic
}
export default function Example () {
return (
< EmailComposeCard
emailData = { emailData }
onSend = { handleSend }
/>
);
}
Installation
npx shadcn@latest add "https://ui.heygaia.io/r/email-compose-card"
Install dependencies
npm install @heroui/react zod
Add icons component
Copy the icons wrapper component from icons
Copy the source code
Copy email-compose-card.tsx to your components directory
This component currently uses HeroUI components. A shadcn/ui migration is planned for future updates.
Usage
Basic Usage
import { EmailComposeCard } from "@/components/ui/email-compose-card" ;
const emailData = {
to: [ "[email protected] " ],
subject: "Hello" ,
body: "Your message here"
};
< EmailComposeCard
emailData = { emailData }
onSend = { ( data ) => console . log ( data ) }
/>
Draft Email
const draftEmail = {
to: [ "[email protected] " ],
subject: "Q1 Review" ,
body: "Draft content..." ,
draft_id: "draft_123456"
};
< EmailComposeCard
emailData = { draftEmail }
onSend = {async ( data ) => {
await sendDraft ( data . draft_id , data );
} }
/>
Reply to Thread
const replyEmail = {
to: [ "[email protected] " ],
subject: "Re: Meeting Notes" ,
body: "Thanks for the notes..." ,
thread_id: "thread_789"
};
< EmailComposeCard emailData = { replyEmail } />
Multiple Recipients
Props
The email data object Show EmailData properties
Array of recipient email addresses. These are shown as suggestions that users can select from.
Email body content. Supports multi-line text with \n for line breaks.
Unique identifier for draft emails
Thread ID for email replies
CC recipients (not currently displayed in UI)
BCC recipients (not currently displayed in UI)
Whether the body contains HTML content
onSend
(data: EmailData) => void | Promise<void>
Callback function called when the send button is clicked. Receives the complete email data including selected recipients.
Additional CSS classes to apply to the card
Features
Recipient Management
Smart Suggestions : Provided email addresses appear as clickable chips
Custom Emails : Users can add additional recipients not in the suggestion list
Email Validation : Real-time validation using Zod schema
Visual Selection : Selected recipients are highlighted and can be toggled
Inline Editing
Subject : Click the edit icon to modify the subject line
Body : Click the edit icon to switch to a textarea for full editing
Auto-focus : Input fields automatically focus when entering edit mode
Keyboard Support : Press Enter to save changes
Form Validation
The component uses Zod for comprehensive validation:
At least one recipient required
All recipients must be valid email addresses
Subject must be 1-200 characters
Body must be 1-10,000 characters
Visual States
Loading State : Shows spinner while sending
Draft Badge : Displays when draft_id is present
Reply Badge : Displays when thread_id is present
Disabled State : Send button disabled when no recipients selected
Recipient Selection Modal
The modal provides an intuitive interface for managing recipients:
Click suggested emails to toggle selection
Add custom emails using the input field
Press Enter or click + to add custom emails
See selected count in the Done button
Click Done to apply changes
Email Format
The body field supports multi-line text with \n for line breaks:
const body = `Hi there,
This is paragraph one.
This is paragraph two.
Best regards,
Your Name` ;
The component preserves whitespace and line breaks using whitespace-pre-line CSS.
Styling
The card uses a clean, flat design with:
Zinc color palette for light/dark mode compatibility
Rounded corners (rounded-3xl)
Subtle dividers between sections
Smooth transitions on interactions
ScrollShadow for overflow content
Accessibility
Semantic HTML structure
ARIA labels on icon-only buttons
Keyboard navigation support
Focus management in edit mode
Form validation with error messages
For AI agent use cases, provide the recipient emails in the to array as suggestions. Users can then select which ones to actually send to.
This component handles the UI for email composition. You’ll need to implement the actual email sending logic in the onSend callback.