Age Verification
ProNewA full-screen age gate that asks yes or no, a date of birth or a birth year, in four layouts, with a denied screen and a remembered answer for returning visitors.
Installation
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
Props
| Prop | Type | Default |
|---|---|---|
| mode | "confirm" | "birthdate" | "year"`confirm` asks yes or no, `birthdate` asks for the full date, `year` only for the year of birth. | "confirm" |
| minAge | numberThe age a visitor must have reached. | 18 |
| layout | "card" | "split" | "panel" | "bare"`card` is a centred card, `split` a form beside a photo, `panel` a dark glass panel and `bare` text straight on the backdrop. | "card" |
| title | string | "Are you of legal age?" |
| message | React.ReactNode | — |
| logo | React.ReactNodeYour logo, above the title. | — |
| image | stringPhoto URL: the backdrop, or the side picture in the `split` layout. | — |
| confirmLabel | stringLabel of the yes button. Defaults to "I am 18 or older" with your `minAge`. | — |
| denyLabel | stringLabel of the no button. | — |
| submitLabel | stringLabel of the button under the date fields. | "Enter" |
| dateOrder | "mdy" | "dmy" | "ymd"Order of the date fields in `birthdate` mode. | "mdy" |
| footer | React.ReactNodeSmall print under the buttons, e.g. a link to your terms. | — |
| color | stringColor of the main button. | — |
| buttonTextColor | stringText color on the main button. | — |
| remember | booleanKeeps a yes for `rememberDays`, so returning visitors are not asked again. | true |
| rememberToggle | booleanShows a "Remember me" checkbox so the visitor decides. | false |
| rememberDays | numberHow long a yes is kept. A no is kept for one day at most. | 30 |
| storageKey | string | nulllocalStorage key the answer is kept under. Pass `null` to keep nothing. | "age-verification" |
| deniedTitle | string | "Sorry, you can’t come in" |
| deniedMessage | React.ReactNode | — |
| allowRetry | booleanLets a visitor who was turned away go back and answer again. | true |
| exitHref | stringAdds a "Leave site" link to the denied screen. | — |
| onVerify | () => voidCalled when the visitor passes. | — |
| onDeny | () => voidCalled when the visitor is too young or says no. | — |
| open | booleanShows or hides the gate yourself. Overrides the stored answer. | — |
| contained | booleanCovers the nearest `relative` parent instead of the window, and does not trap focus. For previews. | false |
| className | string | — |
Accessibility
- The gate is a modal dialog: focus is trapped inside, Escape and outside clicks do nothing, and focus goes back to the page once the visitor passes.
- Date fields are a labelled group of numeric inputs with autocomplete hints; they advance as they fill and Backspace steps back.
- A date that is not real is announced as an alert, the fields are marked invalid and focus returns to the one to fix.
- The denied screen takes focus when it replaces the form, so it is read at once. Under reduced motion nothing scales or shakes.