Data displayListingCard
Searchastronomic.dev# ListingCard
To build your own card for a listing: a photo with a status and Save, the price, title, address and a strip of facts from your fields list.
Interactive: inline script.
## Usage
```astro
import ListingCard from "@astronomic-dev/ui/components/ListingCard.astro";
```
## Examples
### The shell
For your own listing card: the photo with the status and Save, the price, the title, the address, the facts from your fields list and the foot line. ListingCardInset and ListingRow are ready layouts of it; the class hooks set your own.
```astro
---
import ListingCard from "@astronomic-dev/ui/components/ListingCard.astro";
import { fields, listings } from "../_data/vega.ts";
---
<div class="max-w-sm">
<ListingCard listing={listings[1]} fields={fields} imageSizes="24rem" />
</div>
```
## Props
### ListingCard
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `listing` | `ListingCardData` | None | The listing, as plain data (lib/listing-card.ts): id, href and title; address, status, price ({ amount, period: "once" \| "month" }) and priceNote; values by field key; image ({ src, width, height, alt, srcset? }, ready URLs, so a search can fill the same card in the browser); badge, footStart and footEnd. Anything missing is left out, with no empty box. |
| `fields` | `ListingField[]` | None | Your fields list (lib/listing.ts). The fact strip shows each field with card not false that has a value, in list order, in its format. |
| `mode` | `string` | None | The search's mode, such as "buy" or "rent": each fact's label and price value follow the field's labels and period for it. Pass the same mode to fillListingCard() for cards a search adds. Default: each field's label, and a price once. |
| `save` | `boolean` | `true` | Shows a SaveButton on the photo's top end. It comes after the title link in the Tab order. |
| `saveList` | `string` | None | The SaveButton's list name. Default: its own, "homes". |
| `headingTag` | `"h2" \| "h3" \| "h4"` | `"h3"` | Element for the title, one level under the heading above the cards. |
| `imageComponent` | `ImageComponent` | None | Your image component, for a card the server renders on its own (a home page grid). A search's cards use the plain <img> with the listing's srcset, so leave it out there. |
| `imageSizes` | `string` | None | How wide the photo shows, as its sizes attribute, for the listing's srcset or your image component, such as "(min-width: 60rem) 25rem, 100vw". |
| `ratio` | `MediaRatio` | `"3/2"` | The photo's frame, width/height. |
| `mediaClass` | `string` | None | Classes for the photo's box, which holds the status and the badge. |
| `bodyClass` | `string` | None | Classes for the text column under (or beside) the photo. |
| `priceClass` | `string` | None | Classes for the price line: the amount, "/mo" and the note. |
| `priceNoteClass` | `string` | None | Classes for the note after the price, such as your own mark for a price cut. |
| `titleClass` | `string` | None | Classes for the title. |
| `factsClass` | `string` | None | Classes for the fact strip. |
| `footClass` | `string` | None | Classes for the foot line. |
| `class` | `string` | None | More classes on the <article>, merged with cn(), so yours win on conflicts. |
Any other attribute goes on the <article>.
## Accessibility
| Key | Action |
| --- | --- |
| Tab | Moves to the card's title link, then to its Save button. |
| Enter | On the title link: opens the listing. |
| Enter or Space | On Save: saves the listing, or takes it out of the saved list. |
- An <article> whose title is its one link: a click anywhere on the card follows it, and the focus ring goes round the whole card. The title alone names the link.
- The Save button comes right after the title link in the Tab order, and sits above the link, so it is its own control (see SaveButton).
- The facts are a description list: a screen reader reads each term with its value ("Beds, 3").
- The status and the badge on the photo are text in their own fill, so they read on any photo. Write the photo's alt, or "" when the title says it all.
- A missing fact, price or line leaves no empty cell and never prints "undefined".
- Tap targets: Save is 44px round.
ListingCard
FreeTo build your own card for a listing: a photo with a status and Save, the price, title, address and a strip of facts from your fields list.
- File
- ListingCard.astro
- Group
- Data display
- Kind
- Interactive: inline script
- Examples
- 1
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
The shell
For your own listing card: the photo with the status and Save, the price, the title, the address, the facts from your fields list and the foot line. ListingCardInset and ListingRow are ready layouts of it; the class hooks set your own.
This preview did not load.
main.astro
examples/listingcard/main.astro
---
import ListingCard from "@astronomic-dev/ui/components/ListingCard.astro";
import { fields, listings } from "../_data/vega.ts";
---
<div class="max-w-sm">
<ListingCard listing={listings[1]} fields={fields} imageSizes="24rem" />
</div>Minimal · Light