shadcn.io is not affiliated with official shadcn/ui
Card in Card Contact Block for React
A card-in-card contact section for a bookkeeping service: the details of the desk you pick beside a raised form with a live message counter.
Installation
Overview
A card-in-card contact section for React with Base UI. A muted shell with + marks on its corners holds two parts: at the end, a raised panel with the form, at the start the details of the chosen desk. A segmented choice of desk (general, billing or press) swaps the email, phone and hours beside it without moving anything, then name, email and a message with a live counter (500 characters) follow. Submitting checks every field, shows each problem under its field and moves focus to the first one; a valid message turns into a confirmation in the same space, which takes focus. The page's rails and top rule come from the Guides spine. It's built from Frame, Field, Input, Textarea, Segment Group, Guides and Shine Button, with CSS transitions for the entrances and your theme's tokens for every colour. For service businesses with more than one inbox.
FAQ
Where does the form send its data?
Nowhere yet. The submit handler waits 800 milliseconds, as a stand-in for a request, then shows the confirmation. Replace that timer in submit with your own call (your help desk, your inbox or a form endpoint): details holds the desk, name, email and message. Show the confirmation when the request succeeds, and an error line in the form when it doesn't.
How do I change the desks?
Edit DESKS at the top of the file: each desk has an id, a label, a one-line blurb, an email, a phone number (and its tel: link) and hours. All three desks sit in one grid cell, so the card keeps the height of the tallest and nothing moves when you switch; the ones not showing are invisible and out of the tab order. Picking a desk is also announced politely to screen readers.
How does the character counter work?
The textarea has maxLength set to 500 and the counter shows what is typed against it. The counter is part of the textarea's description, so a screen reader hears it when the field takes focus rather than on every key. In the last 50 characters it turns to the full text colour and weight. Change LIMIT to move the cap; SHORTEST is the shortest message the check accepts.
How does the form check what's typed?
The form has noValidate, so the browser's own bubbles stay away and the block shows its own messages. On submit, problems checks a name, an email address with an @ and a domain, and a message of at least 10 characters. Each problem appears under its field with an icon, the control gets aria-invalid and an aria-describedby that points to the message, and focus moves to the first one. Typing in a field clears its message.
Are the email addresses and phone numbers real?
No. The addresses use the .example domain, which is reserved for examples, and the phone numbers are in the 555-0100 to 555-0199 range set aside for fiction. Replace them in DESKS. Phone numbers keep their order in a right-to-left layout.
How does it fit on a phone?
The shell stacks: the form comes straight after the header, the desk's details after it. Name and email go one per row below sm, and the submit button goes full width. Nothing scrolls sideways at 320 pixels. The header and the card fade up once on load; with reduced motion they simply appear.
Related
- Pro
Details Panel Split Contact
Contact formsA contact split for a design studio: a tall tinted panel of email, phone and address with a copy button each, hours and profile links, beside a raised brief form.
- Pro
Minimal Contact Form
Contact formsThe calmest contact form, for a mail client: a centred heading and three fields on the page column with inline validation, a message counter and a one-line thank-you.
- Pro
Talk to Sales Contact
Contact formsA talk-to-sales split for a scheduling platform: what happens next as three numbered steps and a band of contact details beside a form that checks itself, shows each problem under its field and confirms in place.
- Pro
Live Thread Drawing Contact
Contact formsA contact split for a photo lab: a short form beside a framed drawing of the email thread, whose first bubble fills with your name and words as you type.
- Pro
Card Inset Metric Row CTA
Figures and statsA start-aligned card-in-card CTA for an API platform: a headline, one sentence and two calls to action, with three platform figures in a closing band across the foot of the panel.
- Pro
Answers First Contact
Contact formsA contact form that tries to answer first: five numbered answers in an accordion beside a form whose subject field opens the answers that match, then checks itself and confirms in place.