Data displayListingCardInset
Searchastronomic.dev# ListingCardInset
For homes or places in a grid: the photo inset in a card, with the price and the facts under it.
Interactive: inline script.
## Usage
```astro
import ListingCardInset from "@astronomic-dev/ui/components/ListingCardInset.astro";
```
## Examples
### A home for sale
The photo inset in the card, the status and Save on it, then the price, the title, the address, the facts and the foot line. A ring on hover, and the photo zooms a little where motion is allowed.
```astro
---
import ListingCardInset from "@astronomic-dev/ui/components/ListingCardInset.astro";
import { fields, listings } from "../_data/vega.ts";
---
<div class="max-w-sm">
<ListingCardInset listing={listings[0]} fields={fields} imageSizes="24rem" />
</div>
```
### A rental
A rent shows "/mo" in a quieter span after the amount; the foot line starts with the move-in date.
```astro
---
import ListingCardInset from "@astronomic-dev/ui/components/ListingCardInset.astro";
import { fields, listings } from "../_data/vega.ts";
const rental = listings.find((home) => home.mode === "rent")!;
---
<div class="max-w-sm">
<ListingCardInset listing={rental} fields={fields} mode="rent" imageSizes="24rem" />
</div>
```
### A long title and address
A long word in the title breaks inside the card, and the address wraps, so nothing runs out at 320px.
```astro
---
import ListingCardInset from "@astronomic-dev/ui/components/ListingCardInset.astro";
import { fields, listings } from "../_data/vega.ts";
const victorian = listings.find((home) => home.id === "AR-27233")!;
const home = { ...victorian, title: "The Pennsylvania Street Carriagehouseandgardenstudiocottage", address: "1290 Pennsylvania St, Unit 2 (rear carriage house), Denver" };
---
<div class="max-w-xs p-4">
<ListingCardInset listing={home} fields={fields} imageSizes="20rem" />
</div>
```
### A grid of homes
Under a section heading, in auto-fit columns: one at 320 and 390, two from about 40rem, three from about 60rem. The first home is in twice, so its two Save buttons flip together.
```astro
---
import ListingCardInset from "@astronomic-dev/ui/components/ListingCardInset.astro";
import { fields, listings } from "../_data/vega.ts";
// The first home again at the end: two cards for one listing, whose Save buttons flip together.
const homes = [...listings.slice(0, 5), listings[0]];
---
<section aria-labelledby="homes-heading" class="grid gap-blocks p-6">
<h2 id="homes-heading" class="m-0 text-section heading-face">Homes in Denver</h2>
{/* Auto-fit columns of at least 18rem: one at 320 and 390, two from about 40rem, three from about 60rem. */}
<ul role="list" class="m-0 grid list-none grid-cols-[repeat(auto-fit,minmax(min(100%,18rem),1fr))] gap-cards p-0">
{
homes.map((home) => (
<li class="grid">
<ListingCardInset listing={home} fields={fields} imageSizes="(min-width: 60rem) 25rem, (min-width: 40rem) 50vw, 100vw" />
</li>
))
}
</ul>
</section>
```
## Props
### ListingCardInset
| 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>. A search or a map marks a card with data-hot (on hover or focus of its pin), which shows the same ring as hover.
## 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.
ListingCardInset
FreeFor homes or places in a grid: the photo inset in a card, with the price and the facts under it.
- File
- ListingCardInset.astro
- Group
- Data display
- Kind
- Interactive: inline script
- Examples
- 4
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
A home for sale
The photo inset in the card, the status and Save on it, then the price, the title, the address, the facts and the foot line. A ring on hover, and the photo zooms a little where motion is allowed.
This preview did not load.
examples/listingcardinset/main.astro
---
import ListingCardInset from "@astronomic-dev/ui/components/ListingCardInset.astro";
import { fields, listings } from "../_data/vega.ts";
---
<div class="max-w-sm">
<ListingCardInset listing={listings[0]} fields={fields} imageSizes="24rem" />
</div>A rental
A rent shows "/mo" in a quieter span after the amount; the foot line starts with the move-in date.
This preview did not load.
examples/listingcardinset/rental.astro
---
import ListingCardInset from "@astronomic-dev/ui/components/ListingCardInset.astro";
import { fields, listings } from "../_data/vega.ts";
const rental = listings.find((home) => home.mode === "rent")!;
---
<div class="max-w-sm">
<ListingCardInset listing={rental} fields={fields} mode="rent" imageSizes="24rem" />
</div>A long title and address
A long word in the title breaks inside the card, and the address wraps, so nothing runs out at 320px.
This preview did not load.
examples/listingcardinset/long-title.astro
---
import ListingCardInset from "@astronomic-dev/ui/components/ListingCardInset.astro";
import { fields, listings } from "../_data/vega.ts";
const victorian = listings.find((home) => home.id === "AR-27233")!;
const home = { ...victorian, title: "The Pennsylvania Street Carriagehouseandgardenstudiocottage", address: "1290 Pennsylvania St, Unit 2 (rear carriage house), Denver" };
---
<div class="max-w-xs p-4">
<ListingCardInset listing={home} fields={fields} imageSizes="20rem" />
</div>A grid of homes
Under a section heading, in auto-fit columns: one at 320 and 390, two from about 40rem, three from about 60rem. The first home is in twice, so its two Save buttons flip together.
This preview did not load.
examples/listingcardinset/grid.astro
---
import ListingCardInset from "@astronomic-dev/ui/components/ListingCardInset.astro";
import { fields, listings } from "../_data/vega.ts";
// The first home again at the end: two cards for one listing, whose Save buttons flip together.
const homes = [...listings.slice(0, 5), listings[0]];
---
<section aria-labelledby="homes-heading" class="grid gap-blocks p-6">
<h2 id="homes-heading" class="m-0 text-section heading-face">Homes in Denver</h2>
{/* Auto-fit columns of at least 18rem: one at 320 and 390, two from about 40rem, three from about 60rem. */}
<ul role="list" class="m-0 grid list-none grid-cols-[repeat(auto-fit,minmax(min(100%,18rem),1fr))] gap-cards p-0">
{
homes.map((home) => (
<li class="grid">
<ListingCardInset listing={home} fields={fields} imageSizes="(min-width: 60rem) 25rem, (min-width: 40rem) 50vw, 100vw" />
</li>
))
}
</ul>
</section>