Booking
A four-step wizard — dates, stay, guest and a code from a text message — with a total that recalculates as you go.
What it is built from
AppShellTopBarBannerStepperRangeCalendarTimePickerNumberInputRadioGroupFormFormFieldFormLayoutPhoneInputMaskedInputPinInputCardAccordionDescriptionListtoastuseMediaQuery
Try it
- Select dates: crossed-out days are booked, and a range cannot include them. Press “Continue” with nothing selected and the step reports the error.
- On the second step change the room or the number of guests: the total on the right recalculates. Set two guests in the “Garden room” and add a third: the step does not let you continue.
- Enter any ten-digit loyalty card number and the total shows a 10% discount. Enter only nine digits: the error appears under the field, and the discount hint stays above the error.
- The text-message code on the last step is always the same; the Gallery screen prints it. Enter a wrong code to see the error, the right one to reach the success page.
- Go back through the
Stepper: everything you typed is still there.
How it is built
Each step validates itself, and the errors live in FormField. Form has no validation of its own: it
stops the native submit and disables the fields while a request runs. The Gallery screen writes the rules, and
FormField receives the error text, marks the field as invalid and associates the message with it. PinInput,
TimePicker and NumberInput do the same without being passed anything. The rule hint on the card number is
pinned with hintPersistent: it stays when there is an error. The errors are derived from the answers rather than
stored: after the first failed attempt they are recalculated on every edit to the fields and disappear as soon as
the value is fixed.
Stepper never lets you jump ahead, and going back loses nothing. With onStepClick, only the steps you have
already completed are clickable: a future step needs data that does not exist yet. So the only way forward is one
button, and it validates the step. Every answer lives in the Gallery screen's state rather than in the fields, and
a step you return to is rendered with what it held. Dates are kept as ISO strings, YYYY-MM-DD: RangeCalendar
takes the range as strings and hands it back as the second argument of onChange, so the Gallery screen needs no
date package, and the number of nights is the difference of two strings.
RangeCalendar handles unavailable days. The calendar accepts isDateUnavailable and rejects any range that
includes a booked day; the Gallery screen only lists the booked days as ISO strings. Past dates are blocked by
minValue, which is also a string. The Gallery screen reads “today” after mount: the page is prerendered at build
time, and the build date would not match the date of the visit. On a phone the calendar shows one month; from 768 px
up, two side by side: the months prop sets the number, and the useMediaQuery hook switches it. The fields of the
“Stay” step (TimePicker, NumberInput and card-style Radio) sit in a FormLayout, which collapses them into one
column on a narrow screen.
The total is one component in two forms. On a wide screen it is a sticky Card on the right; below lg (1024 px)
the same lines are folded into an Accordion above the form, with the total in its title. The price is
computed from the state on every render, so the loyalty discount and breakfast appear in it at once.
PinInput takes the confirmation code: a pasted code is spread across the fields, and the component returns one
string.