FormsAreaCheck
Searchastronomic.dev# AreaCheck
For a service area: type a ZIP code and see yes, with a link to that town's page, or not yet. With no script, a link to your areas page.
Interactive: inline script.
## Usage
```astro
import AreaCheck from "@astronomic/ui-pro/components/AreaCheck.astro";
```
## Examples
### Type a ZIP, get an answer
Brassfield Plumbing's towns, inline. Yes names every area the ZIP is in, each a link to its page; not yet offers the number as a tel link. A 4-digit entry marks the field and shows its error.
```astro
---
import Card from "@astronomic-dev/ui/components/Card.astro";
import AreaCheck from "@astronomic/ui-pro/components/AreaCheck.astro";
import { plumbing } from "../_data/groundcrew.ts";
// Each town links to its area page (here, anchors on this page).
const areas = plumbing.areas.map((a) => ({ ...a, href: `#${a.name.toLowerCase().replaceAll(" ", "-")}` }));
---
<!-- Try 43081 (Westerville), 43016 (Dublin) or 43215 (not yet); a 4-digit entry shows the field's error. -->
<Card class="mx-auto w-full max-w-md">
<AreaCheck heading="Do we come to you?" areas={areas} fallbackHref="#areas" phone={plumbing.phone} />
</Card>
```
### Areas from a URL
source is a URL that serves { areas: [...] }, fetched once, the first time the field is used; inline areas are better for a short list. While it loads the button is busy and a waiting check says "Checking…". If the load fails, "Try again" and the link to the areas page show.
```astro
---
import Card from "@astronomic-dev/ui/components/Card.astro";
import AreaCheck from "@astronomic/ui-pro/components/AreaCheck.astro";
import { landscaping } from "../_data/groundcrew.ts";
// On a site, source is a URL that serves the areas JSON, such as "/areas.json". Here a data: URL with the same JSON
// stands in for it, so the example has nothing to host. It is fetched once, when the field is first used.
const json = JSON.stringify({ areas: landscaping.areas.map((a) => ({ ...a, href: `#${a.name.toLowerCase().replaceAll(" ", "-")}` })) });
const source = `data:application/json,${encodeURIComponent(json)}`;
---
<!-- Try 80120 (Littleton) or 80202 (not yet). -->
<Card class="mx-auto w-full max-w-md">
<AreaCheck heading="Is your yard in our area?" source={source} fallbackHref="#areas" phone={landscaping.phone} />
</Card>
```
### On the band
tone="band": the form takes the band's surface, edge and focus ring, and the field and buttons the band's colors.
```astro
---
import AreaCheck from "@astronomic/ui-pro/components/AreaCheck.astro";
import { cleaning } from "../_data/groundcrew.ts";
const areas = cleaning.areas.map((a) => ({ ...a, href: `#${a.name.toLowerCase().replaceAll(" ", "-")}` }));
---
<!-- Try 85233 (Gilbert) or 85001 (not yet). -->
<AreaCheck
class="mx-auto w-full max-w-lg"
tone="band"
headingTag="h3"
heading="Do we clean in your neighborhood?"
areas={areas}
fallbackHref="#areas"
phone={cleaning.phone}
checkText="Check my ZIP"
/>
```
### No area pages, no phone
In a 20rem column. With no href the towns are plain names, and with no phone the not-yet answer is noText alone, here with your own words.
```astro
---
import AreaCheck from "@astronomic/ui-pro/components/AreaCheck.astro";
import { construction } from "../_data/groundcrew.ts";
---
<!-- No area pages and no phone: the towns are plain names, and "not yet" ends there. Try 27511 (Cary) or 27601. -->
<div class="mx-auto w-full max-w-xs">
<AreaCheck
heading="Do we build in your town?"
headingTag="h3"
areas={construction.areas}
fallbackHref="#areas"
noText="Not yet in {zip}. Send us your project anyway; we sometimes travel for the right job."
/>
</div>
```
## Props
### AreaCheck
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `heading` | `string` | None | Required. The heading ("Do we come to you?"). It names the form. |
| `fallbackHref` | `string` | None | Required. Your areas page. With no script the form hides and a link to it shows; after a failed load it shows beside Try again. |
| `areas` | `{ name: string; href?: string; zips: string[] }[]` | None | The areas, inline: built into the page as JSON. Each needs a name and 5-digit ZIP codes (a bad one throws at build, naming the area); href links the name to the area's page. A ZIP in two areas names both. Pass areas or source, not both. |
| `source` | `string` | None | A URL that serves the same JSON, { areas: [...] }, for a long list. Fetched once, on the field's first focus or the first check; only a good load is kept. |
| `phone` | `string` | None | The number for the not-yet answer, as you write it; shown as a tel link in callText. Without it the answer is noText alone. |
| `headingTag` | `"h2" \| "h3"` | `"h2"` | The heading's level. |
| `fallbackText` | `string` | `"See the towns we serve"` | The fallback link's words. |
| `label` | `string` | `"Your ZIP code"` | The field's label. |
| `checkText` | `string` | `"Check"` | The button's words. |
| `yesText` | `string` | `"Yes, we work in {areas} ({zip})."` | The yes answer. {areas} is the list of names in the page's language ("Westerville and Worthington"), {zip} the ZIP. |
| `noText` | `string` | `"Not yet in {zip}."` | The not-yet answer. |
| `callText` | `string` | `"Call {phone} and we will tell you straight."` | After noText when there is a phone; {phone} is the tel link. |
| `invalidText` | `string` | `"Enter a 5-digit ZIP code."` | The field's error for an entry that is not a ZIP code (ZIP+4 is fine). |
| `failedText` | `string` | `"We could not check right now."` | When the source could not load. |
| `checkingText` | `string` | `"Checking…"` | While a check waits on the source. |
| `retryText` | `string` | `"Try again"` | The button that loads the source again after a failure. |
| `tone` | `"page" \| "band"` | `"page"` | The surface it sits on: page, or band (the band's colors, with its own edge and padding). |
| `fieldClass` | `string` | None | For recipes: more classes on the Field. |
| `resultClass` | `string` | None | For recipes: more classes on the answer line. |
| `class` | `string` | None | More classes on the form, merged with cn(), so yours win on conflicts. |
Any other attribute goes on the <form>.
## Accessibility
| Key | Action |
| --- | --- |
| Tab | Moves to the ZIP field, then to Check, then to any link in the answer |
| Enter | In the field or on Check: checks the ZIP |
| Enter or Space | On Try again: loads the areas again and checks the ZIP |
- With no script the form cannot answer, so it hides and a plain link to your areas page shows in its place: no dead form.
- A form named by its heading, with a labeled field (numeric keypad, postal-code autofill). The answer is a status line, so a screen reader reads it without moving focus; the same ZIP checked twice is read twice.
- An entry that is not a ZIP marks the field invalid (aria-invalid, with the Field's error line tied to it) and moves focus to it.
- While the areas load, the form and the button are aria-busy (never disabled), and a check that waits says "Checking…". After a failure, "Try again" and the areas link show; only the latest check's answer is ever written.
- Answers are written as text and links, never as HTML, so an area name can never inject markup. The button, Try again and the links are each at least 44px tall.
AreaCheck
ProFor a service area: type a ZIP code and see yes, with a link to that town's page, or not yet. With no script, a link to your areas page.
- File
- AreaCheck.astro
- Group
- Forms
- Kind
- Interactive: inline script
- Examples
- 4
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Type a ZIP, get an answer
Brassfield Plumbing's towns, inline. Yes names every area the ZIP is in, each a link to its page; not yet offers the number as a tel link. A 4-digit entry marks the field and shows its error.
This preview did not load.
examples/areacheck/main.astro
---
import Card from "@astronomic-dev/ui/components/Card.astro";
import AreaCheck from "@astronomic/ui-pro/components/AreaCheck.astro";
import { plumbing } from "../_data/groundcrew.ts";
// Each town links to its area page (here, anchors on this page).
const areas = plumbing.areas.map((a) => ({ ...a, href: `#${a.name.toLowerCase().replaceAll(" ", "-")}` }));
---
<!-- Try 43081 (Westerville), 43016 (Dublin) or 43215 (not yet); a 4-digit entry shows the field's error. -->
<Card class="mx-auto w-full max-w-md">
<AreaCheck heading="Do we come to you?" areas={areas} fallbackHref="#areas" phone={plumbing.phone} />
</Card>Areas from a URL
source is a URL that serves { areas: [...] }, fetched once, the first time the field is used; inline areas are better for a short list. While it loads the button is busy and a waiting check says "Checking…". If the load fails, "Try again" and the link to the areas page show.
This preview did not load.
examples/areacheck/source.astro
---
import Card from "@astronomic-dev/ui/components/Card.astro";
import AreaCheck from "@astronomic/ui-pro/components/AreaCheck.astro";
import { landscaping } from "../_data/groundcrew.ts";
// On a site, source is a URL that serves the areas JSON, such as "/areas.json". Here a data: URL with the same JSON
// stands in for it, so the example has nothing to host. It is fetched once, when the field is first used.
const json = JSON.stringify({ areas: landscaping.areas.map((a) => ({ ...a, href: `#${a.name.toLowerCase().replaceAll(" ", "-")}` })) });
const source = `data:application/json,${encodeURIComponent(json)}`;
---
<!-- Try 80120 (Littleton) or 80202 (not yet). -->
<Card class="mx-auto w-full max-w-md">
<AreaCheck heading="Is your yard in our area?" source={source} fallbackHref="#areas" phone={landscaping.phone} />
</Card>On the band
tone="band": the form takes the band's surface, edge and focus ring, and the field and buttons the band's colors.
This preview did not load.
examples/areacheck/band.astro
---
import AreaCheck from "@astronomic/ui-pro/components/AreaCheck.astro";
import { cleaning } from "../_data/groundcrew.ts";
const areas = cleaning.areas.map((a) => ({ ...a, href: `#${a.name.toLowerCase().replaceAll(" ", "-")}` }));
---
<!-- Try 85233 (Gilbert) or 85001 (not yet). -->
<AreaCheck
class="mx-auto w-full max-w-lg"
tone="band"
headingTag="h3"
heading="Do we clean in your neighborhood?"
areas={areas}
fallbackHref="#areas"
phone={cleaning.phone}
checkText="Check my ZIP"
/>No area pages, no phone
In a 20rem column. With no href the towns are plain names, and with no phone the not-yet answer is noText alone, here with your own words.
This preview did not load.
examples/areacheck/no-phone.astro
---
import AreaCheck from "@astronomic/ui-pro/components/AreaCheck.astro";
import { construction } from "../_data/groundcrew.ts";
---
<!-- No area pages and no phone: the towns are plain names, and "not yet" ends there. Try 27511 (Cary) or 27601. -->
<div class="mx-auto w-full max-w-xs">
<AreaCheck
heading="Do we build in your town?"
headingTag="h3"
areas={construction.areas}
fallbackHref="#areas"
noText="Not yet in {zip}. Send us your project anyway; we sometimes travel for the right job."
/>
</div>