shadcn.io is not affiliated with official shadcn/ui
Gift Card Dialog Block for React
A café's gift cards page with its builder dialog shown open: a card drawn in greys that reads as you build it, preset or custom amounts, three printed patterns, a recipient and a message, and delivery now or on a day picked in an inline calendar.
Installation
Overview
Let people give a gift card they have designed, with this gift-card dialog for React with Base UI. It opens from the gift cards page of Cuppery, a neighbourhood café: the page's header holds an outline Buy a gift card Button, and the café's menu board and a cart chip are drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The dialog is a builder. At the start a card drawn in greys is pinned and reads as you build it: the café's name, the amount, who it is to, the message, all over the printed pattern you chose, with the total and when it goes under it. At the end a Toggle Group takes the amount, $15, $25, $50 or a custom whole number from $5 to $200, a second one takes the pattern (beans, steam or stripe, drawn with gradients, no pictures), then come the recipient's name and email, a message with a counter, and a Segment Group for Send now or Pick a date, which opens an inline Calendar that closes every day up to the one the block treats as now. Add gift card, the only Shine Button, checks the form, queues one card and the cart chip behind the dialog counts it. For preview the dialog is drawn open in place when the page loads; the header button opens the real Dialog, with the same card and the same state. For cafés, shops, restaurants and any business that sells a present.
FAQ
Why is the dialog already open, and what do I keep?
So you can see it without a click. On load the dialog is a copy drawn in place over the page: a native dialog element that isn't modal, so nothing is trapped, hidden or focused, and the page around the preview keeps working. The Buy a gift card button opens the real Dialog, modal, with its focus trap, Escape and focus return, and the copy stays closed until a reload. Both show the same GiftFields component and share the block's state, so a name typed or a pattern chosen in the copy is there in the real one. In your app keep the Dialog and drop the copy: the "in-place" state, the scrim and the dialog element inside the frame.
How is the card drawn, and can I use real artwork?
The card is a box in the theme's greys with the pattern painted behind its text by a CSS gradient: beans are a tiled oval, steam is arcs rising from the foot, stripe is a diagonal hatch. They live in PATTERNS as class names, so a new pattern is one entry. To print real artwork, put an image behind the same text and keep the text over a solid band so it stays readable. The card repeats what the fields say, so screen readers skip it and read the fields.
What are the rules for the amount?
A preset is always good. Custom turns the number field on and moves focus into it; it must be a whole number from $5 to $200 (LOWEST and HIGHEST), checked when you press Add gift card, with its own message under the field, and the card and the total show dashes until the number is good. The field is always on the page, only switched off until you choose Custom, so choosing it moves nothing.
How does the delivery date work?
Send now says "Right away". Pick a date opens the calendar, shown as it would be on the day the block treats as now (AS_OF), with that day and every earlier day closed, whatever the visitor's own clock says; pressing Add gift card without a day says so under the calendar. The calendar is the catalog's own, inline in the dialog rather than a popup, which keeps it working inside a modal on every library. In your app disable days from your own cut-off, and let your server enforce it.
Does it charge anything or send the email?
No. Add gift card queues one card in the block's state, the polite status message says so ("queued, in this demo. No email goes out and nothing was charged.") and the cart chip behind the dialog counts it. In your app create the card on your server in add, send the email on the delivery day from there, and take payment through your payment provider; show a failure in the field it belongs to, with the dialog still open.
Is it accessible from the keyboard?
Yes. The real dialog is named by its title and described by its sentence, focus starts at the first choice and stays inside until it closes, and Escape, Cancel and the close button all return focus to Buy a gift card. The trigger is passed to DialogTrigger through render, and the dialog is controlled with open and onOpenChange. The amount and pattern are groups you move through with the arrow keys, each field's message is tied to it with aria-describedby, the message counter is for the eyes while the field announces its limit once, and one polite status message reports the result. The copy shown on load moves no focus; Escape inside it, Cancel and its close button close it and put focus on the header button.
Related
- Pro
Add Card Dialog
Payments and plansA transit wallet's payment methods page with its add-card dialog shown open: a card drawn in greys that fills in as you type, a number that groups itself and names its network, checks on the number, expiry and code, and an Add card button that keeps only the last four digits.
- Pro
Apply Coupon Dialog
Payments and plansA cookware shop's basket with its promo-code dialog shown open: one field that judges five typed codes with five different answers, applied codes kept as removable chips, and a summary that is worked out again after every change.
- Pro
A hardware shop's quantity dialog shown open: a number field with a button on each side over a four-tier price ladder that follows it, a hint to the next tier and totals worked out in whole cents.
- Pro
Add to Cart Dialog
Payments and plansA stool shop's product page with its add-to-cart dialog shown open: two heights that redraw the stool and move the price, three finishes with a sentence each, a quantity that stops at the stock left, and a total that follows the choices.
- Pro
Billing Address Dialog
Payments and plansAn invoice page with its billing-address dialog shown open: the form relabels, reorders and revalidates for the United States, the United Kingdom, Germany and Japan, a switch fills the company's address, and the address is printed the way an envelope would carry it.
- Pro
Guest Checkout Dialog
Payments and plansA cart with its identify-step dialog shown open: Guest, Sign in and Create account swap the fields under a segmented control, one button names the mode, and the cart's stepper moves on to Shipping once you continue.