# Key–value

Source: https://ecosphere.dev/docs/data/key-value (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

A real dl for the facts of one record: term in muted ink, value in primary.

`import { EcoKeyValue } from "vue-ecosphere"`

## On its own

The label column hugs the longest term; a long value wraps inside its own column. Put num on figures so a column of them aligns.

Vue (vue-ecosphere):

```vue
<EcoKeyValue :items="[
  { term: 'Seats', value: '1,012', num: true },
  { term: 'Students', value: '916', num: true },
  { term: 'Spare', value: '96', num: true },
  { term: 'Largest section', value: 'Grade 9-B · 44' },
]" />
```

React (react-ecosphere):

```tsx
<EcoKeyValue
  items={[
    { term: "Seats", value: "1,012", num: true },
    { term: "Students", value: "916", num: true },
    { term: "Spare", value: "96", num: true },
    { term: "Largest section", value: "Grade 9-B · 44" },
  ]}
/>
```

## Inside a card

In a card body, under an eyebrow naming the record.

Vue (vue-ecosphere):

```vue
<div class="card">
  <div class="card__body">
    <p class="eyebrow">Admission record</p>
    <EcoKeyValue :items="admission" style="margin-top: 14px" />
  </div>
</div>
```

React (react-ecosphere):

```tsx
<div className="card">
  <div className="card__body">
    <p className="eyebrow">Admission record</p>
    <EcoKeyValue items={admission} style={{ marginTop: 14 }} />
  </div>
</div>
```

## Facts grid, with section headings

For a full record. A missing value is information: show the dash, never a blank dd or a dropped fact.

Vue (vue-ecosphere):

```vue
<EcoKeyValue grid title="Product" :items="[
  { term: 'Name', value: 'Ceramic pour-over kettle, 1.2 litre, matte stone glaze' },
  { term: 'SKU', value: 'SKU-CK12-STONE-0042-EU-RETAIL-2026-B', num: true },
  { term: 'Supplier', value: null },   // em dash + “Not recorded”
  { term: 'Fragile', value: true },    // “Yes”
]" />
<EcoKeyValue grid title="Stock and pricing" :items="stock" />
```

React (react-ecosphere):

```tsx
<EcoKeyValue
  grid
  title="Product"
  items={[
    { term: "Name", value: "Ceramic pour-over kettle, 1.2 litre, matte stone glaze" },
    { term: "SKU", value: "SKU-CK12-STONE-0042-EU-RETAIL-2026-B", num: true },
    { term: "Supplier", value: null }, // em dash + “Not recorded”
    { term: "Fragile", value: true },  // “Yes”
  ]}
/>
<EcoKeyValue grid title="Stock and pricing" items={stock} />
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `{ term, value?, num? }[]` | — | The facts, already formatted. Booleans read Yes / No; null, undefined or an empty string shows the muted dash. |
| `#default` | `slot` | — | Raw dt / dd pairs instead of items. |
| `grid` | `boolean` | false | Facts grid (kv--grid): term over value, as many columns as fit. |
| `title` | `string` | — | Section heading (kv__h) above the list. |
| `as` | `"h2" \| "h3" \| "h4"` | "h3" | Heading level for title. |
| `emptyText` | `string` | "Not recorded" | Screen-reader words for an empty value. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `{ term, value?, num? }[]` | — | The facts, already formatted. Booleans read Yes / No; null, undefined or an empty string shows the muted dash. |
| `children` | `ReactNode` | — | Raw dt / dd pairs instead of items. |
| `grid` | `boolean` | false | Facts grid (kv--grid): term over value, as many columns as fit. |
| `title` | `string` | — | Section heading (kv__h) above the list. |
| `as` | `"h2" \| "h3" \| "h4"` | "h3" | Heading level for title. |
| `emptyText` | `string` | "Not recorded" | Screen-reader words for an empty value. |
