# Fact Grid

> A few numbers about one thing, such as a customer's plan and seats, as small tiles.

Page: https://uicontext.com/docs/components/fact-grid

Group: Records.

## When to use

A few numbers about one thing, such as a customer's plan and seats, as small tiles. Use [Stat](https://uicontext.com/docs/components/stat.md) instead when the numbers are a dashboard's headline, with trends.

## Usage

```ts
import { FactGrid } from "./ui/uicontext/components/FactGrid.ts"

export const Account = <M>(h: Html.H<M>) =>
	FactGrid(h, { label: "Account", facts: [{ label: "Plan", value: "Business" }, { label: "Seats", value: "48 of 50", tone: "warning" }] })
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### An account at a glance

The example the page opens with: Fact Grid in “An account at a glance”.

```ts title="src/demo.ts" source="www/src/examples/fact-grid/demo.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { FactGrid } from "./ui/uicontext/components/FactGrid.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ wrap: { inlineSize: "min(100%, 30rem)" } })

// a customer's account at a glance, in a help desk's side panel
export const AccountFacts = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.wrap)).children(
		FactGrid(h, {
			label: "Northwind Traders",
			facts: [
				{ label: "Plan", value: "Business", hint: "Annual, renews 1 March" },
				{ label: "Seats", value: "48 of 50", tone: "warning", hint: "2 left" },
				{ label: "Lifetime value", value: "$148,200" },
				{ label: "Open tickets", value: "3", hint: "1 breached SLA", tone: "danger" },
				{ label: "CSAT", value: "94%", tone: "success", hint: "+3 pts this quarter" },
				{ label: "Customer since", value: "Aug 2021" },
			],
		}),
	)
```

### Plain, inside a card

`variant: "plain"` drops the tile borders; `columns` caps how many fit in a row.

```ts title="src/plain.ts" source="www/src/examples/fact-grid/plain.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { FactGrid } from "./ui/uicontext/components/FactGrid.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, corner, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"

const styles = stylex.create({
	card: { display: "grid", gap: space.lg, inlineSize: "min(100%, 36rem)", padding: space.lg, borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel },
	title: { margin: 0, fontSize: font.base, fontWeight: 600 },
})

// an agent's usage this month, plain inside its card, four across with larger values
export const AgentUsage = <M>(h: Html.H<M>) =>
	h.section.attrs(sx(styles.card)).children(
		h.h3.attrs(sx(styles.title)).children("Support triage agent · December"),
		FactGrid(h, {
			label: "Usage this month",
			variant: "plain",
			size: "lg",
			columns: 4,
			facts: [
				{ label: "Runs", value: "12,408", hint: "+18% vs Nov" },
				{ label: "Success rate", value: "97.2%", tone: "success" },
				{ label: "Median time", value: "4.1s" },
				{ label: "Cost", value: "$318.40", hint: "Budget $500" },
			],
		}),
	)
```

## API reference

**Options**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | — | What the facts are about: "Account", "This agent". |
| `facts` (required) | `Fact<Message>[]` | — | The tiles, in order. |
| `columns` | `number` | `3` | The most tiles in a row; 3 by default. |
| `minWidth` | `number` | `120` | A tile's narrowest width, in px, before the row wraps; 120 by default. |
| `variant` | `"tiles" \| "plain"` | — | `tiles` (the default) on a bordered surface, or `plain` with no border, for inside a card. |
| `size` | `"md" \| "lg"` | — | A larger value, for the facts at the top of a page. |
| `style` | `Style` | — | — |

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/fact-grid
```

With npm: `npx shadcn@latest add checkfu/uicontext/fact-grid`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/fact-grid`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/fact-grid`.

It writes these files:

- `src/ui/uicontext/components/FactGrid.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/FactGrid.ts](https://github.com/checkfu/uicontext/blob/main/src/FactGrid.ts)

## Related

- [Data Grid](https://uicontext.com/docs/components/data-grid.md) (`data-grid`): A spreadsheet-like grid for editing records, with typed columns, sorting and grouping.
- [Pivot Table](https://uicontext.com/docs/components/pivot-table.md) (`pivot-table`): Records summed two ways, such as revenue by region and quarter, with totals on both edges and cells tinted by size.
- [Table](https://uicontext.com/docs/components/table.md) (`table`): A simple read-only table with a caption, row headers and an empty state.
- [Group Header](https://uicontext.com/docs/components/group-header.md) (`group-header`): The line over a group of rows with its count, sticky while they scroll, folding the group.
- [Description List](https://uicontext.com/docs/components/description-list.md) (`description-list`): A record's facts as label and value pairs, in rows or columns, with Copy for ids.
- [Order Summary](https://uicontext.com/docs/components/order-summary.md) (`order-summary`): What an order comes to: its lines, then subtotal, discount, shipping, tax and the total.
