shadcn.io is not affiliated with official shadcn/ui
Shipping Options Dialog Block for React
A homeware shop's shipping dialog shown open: four delivery methods with arrival dates counted in business days from a fixed order date, prices in whole cents, a free-shipping bar and a button that names the choice.
Installation
Overview
Let people see when a parcel arrives before they pay for how it travels, with this shipping dialog for React with Base UI. It opens from the Cart page of Stoopfield, a homeware shop: the page's header holds an outline Change shipping Button, and the cart, a top bar with a bag count, three items and a totals block, is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The dialog lists four methods as radio rows, Standard, Express, Next day and Pick-up point, each with its carrier, the days it takes, the dates it would arrive and its price. The dates are not typed: they are counted in business days from the order date, Friday 9 October, skipping weekends, so Standard reads "Wed 14 to Fri 16 Oct" and Express "Mon 12 to Tue 13 Oct". Under them a free-shipping line with a Progress bar says how far the order is from $75.00, and a tea towel can be added or removed to watch Standard turn free. The only Shine Button names the choice, "Use Express", and writes the method, the shipping line and the new total on the drawn cart. For preview the dialog is drawn open in place when the page loads; the header button opens the real Dialog, with the same rows. For shops, marketplaces, rentals and any checkout with delivery options.
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 cart: a native dialog element that isn't modal, so nothing is trapped, hidden or focused, and the page around the preview keeps working. The Change shipping 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 ShippingFields component and share the block's draft, so a method chosen in the copy is chosen in the real one, and Cancel puts it back to what the cart has. In your app keep the Dialog and drop the copy: the "in-place" state, the scrim and the dialog element inside the frame.
How are the delivery dates worked out?
By businessDay, a small helper that starts at the order date, AS_OF, and steps forward one calendar day at a time, counting only Monday to Friday. Each method has a fastest and a slowest number of business days, so Standard is 3 to 5, and the two results are written from typed weekday and month names, which keeps the text identical on the server and in every browser. Public holidays are not counted: in your app take the dates from your carrier's API or add your calendar of closed days to the helper. Change AS_OF and every date moves with it.
How are the prices and the free-shipping line worked out?
Every price is whole cents formatted with Intl.NumberFormat, so $4.99 is 499. The order total before shipping, SUBTOTAL, is a constant, and the line, the bar and Standard's price all come from it: below FREE_OVER the line says how much more to add and Standard costs its own price, at or above it Standard reads "Free". Adding the tea towel raises the total by its price so you can watch the line cross the threshold; the cart behind the dialog shows the new subtotal, shipping and total once you use a method.
Is it accessible from the keyboard?
Yes. The methods are native radio buttons in a group, so the arrow keys move between them and Tab leaves the group; the real dialog is named by its title and described by its sentence, focus starts on the chosen method and stays inside until the dialog closes, and Escape, Cancel and the close button return focus to Change shipping. The tea towel button says whether it is pressed, and what changed is said in a polite message. The trigger is passed to DialogTrigger through render, and the dialog is controlled with open and onOpenChange. The copy shown on load moves no focus; Escape inside it, Cancel and its close button close it and put focus on the button.
What stays local in the demo, and how do I wire it up?
All of it. The methods, the carriers, the prices, the order total and the cart drawing are typed in this file, and Use Express only changes the drawn cart and says in a polite message that nothing ships. In your app load the methods and their prices from your carrier or checkout API for the person's address, keep businessDay only if your carrier gives you day counts rather than dates, and save the choice on the order from confirm.
How does it look on a phone?
The copy shown on load docks to the foot of the page as a bottom sheet, with the rows scrolling above the pinned Cancel and Use button. Each row keeps its name and price on one line and its dates and carrier under them, and the drawn cart keeps its totals under two items. The real dialog keeps the Dialog's own phone layout: a sheet stuck to the bottom of the screen.
Related
- Pro
A furniture shop's order sheet shown open: a five-step delivery timeline with days and times worked out from a fixed today, the delivery window drawn on a track with its estimate, and the scans of any step you press.
- 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
Payment Method Dialog
Payments and plansA ticket shop's order summary with its payment-method dialog shown open: a saved card, a bank transfer and an invoice as rows, each asking only for the one detail it needs, and a Pay with row behind the dialog that changes when you choose.
- 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
Add Profile Dialog
Account and securityA newsletter's writers page with its byline composer shown open: a name, what they write, a 120 character bio, a mark from six drawn glyphs or initials and a switch, beside a card that shows the byline as it will print.
- 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.