Data displayFactStrip
Searchastronomic.dev# FactStrip
A ruled strip of a listing's facts, such as beds, baths and square feet; a missing fact leaves no empty cell.
Static: no JavaScript.
## Usage
```astro
import FactStrip from "@astronomic-dev/ui/components/FactStrip.astro";
```
## Examples
### A listing's facts
Beds, baths, square feet and year built from the fields list, ruled above, below and between. Four even columns from 16rem; below that as many as fit, so a value is never cut.
```astro
---
import FactStrip from "@astronomic-dev/ui/components/FactStrip.astro";
import { fields, listings } from "../_data/vega.ts";
---
<div class="max-w-md">
<FactStrip fields={fields} values={listings[0].values} />
</div>
```
### Long labels in a narrow strip
Longer terms, such as Bedrooms and Lot size, in a 16rem strip of four: a term wraps inside its cell, never past it.
```astro
---
import FactStrip from "@astronomic-dev/ui/components/FactStrip.astro";
import type { ListingField } from "@astronomic-dev/ui/lib/listing.ts";
// A fields list with longer terms than the demo's, in the narrowest strip that still shows four columns (16rem).
const fields: ListingField[] = [
{ key: "beds", label: "Bedrooms", format: "integer" },
{ key: "baths", label: "Bathrooms", format: "decimal" },
{ key: "lot", label: "Lot size", format: "area", unit: "sq ft" },
{ key: "year", label: "Year built", format: "year" },
];
---
<div class="max-w-3xs">
<FactStrip fields={fields} values={{ beds: 4, baths: 2.5, lot: 6250, year: 1926 }} />
</div>
```
### Missing facts
No baths and no year on file: those cells are left out, with no empty cell and no gap.
```astro
---
import FactStrip from "@astronomic-dev/ui/components/FactStrip.astro";
import { fields } from "../_data/vega.ts";
---
<div class="max-w-md">
{/* No year built and no baths on file: those cells are left out, with no gap. */}
<FactStrip fields={fields} values={{ beds: 2, sqft: 1120 }} />
</div>
```
## Props
### FactStrip
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `fields` | `ListingField[]` | None | Your fields list (lib/listing.ts): a cell for each field with card not false, in list order, its label as the term and its value in the field's format. |
| `values` | `ListingValues` | None | The listing's values by field key. A missing, empty or bad value hides its cell; with no cell at all, nothing renders. |
| `mode` | `string` | None | The search's mode, such as "buy" or "rent": each label and price value follow the field's labels and period for it. Default: each field's label, and a price once. |
| `class` | `string` | None | More classes on the strip, merged with cn(), so yours win on conflicts. |
| `cellClass` | `string` | None | Classes for each cell (a term and its value). |
Any other attribute goes on the strip's <div>.
## Accessibility
- A description list (<dl>): a screen reader reads each term with its value, such as "Beds, 3".
- The figures are of one width, so the values line up from card to card.
FactStrip
FreeA ruled strip of a listing's facts, such as beds, baths and square feet; a missing fact leaves no empty cell.
- File
- FactStrip.astro
- Group
- Data display
- Kind
- Static: no JavaScript
- Examples
- 3
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
A listing's facts
Beds, baths, square feet and year built from the fields list, ruled above, below and between. Four even columns from 16rem; below that as many as fit, so a value is never cut.
This preview did not load.
examples/factstrip/main.astro
---
import FactStrip from "@astronomic-dev/ui/components/FactStrip.astro";
import { fields, listings } from "../_data/vega.ts";
---
<div class="max-w-md">
<FactStrip fields={fields} values={listings[0].values} />
</div>Long labels in a narrow strip
Longer terms, such as Bedrooms and Lot size, in a 16rem strip of four: a term wraps inside its cell, never past it.
This preview did not load.
examples/factstrip/long-labels.astro
---
import FactStrip from "@astronomic-dev/ui/components/FactStrip.astro";
import type { ListingField } from "@astronomic-dev/ui/lib/listing.ts";
// A fields list with longer terms than the demo's, in the narrowest strip that still shows four columns (16rem).
const fields: ListingField[] = [
{ key: "beds", label: "Bedrooms", format: "integer" },
{ key: "baths", label: "Bathrooms", format: "decimal" },
{ key: "lot", label: "Lot size", format: "area", unit: "sq ft" },
{ key: "year", label: "Year built", format: "year" },
];
---
<div class="max-w-3xs">
<FactStrip fields={fields} values={{ beds: 4, baths: 2.5, lot: 6250, year: 1926 }} />
</div>Missing facts
No baths and no year on file: those cells are left out, with no empty cell and no gap.
This preview did not load.
examples/factstrip/missing.astro
---
import FactStrip from "@astronomic-dev/ui/components/FactStrip.astro";
import { fields } from "../_data/vega.ts";
---
<div class="max-w-md">
{/* No year built and no baths on file: those cells are left out, with no gap. */}
<FactStrip fields={fields} values={{ beds: 2, sqft: 1120 }} />
</div>