# Section Grid

> A grid whose cells share one line between them, with a mark on every crossing and columns that change at breakpoints.

- Category: Structure (Rails, rules and section grids that lay out a whole page.)
- Registry item: `section-grid`
- Live preview with controls: https://fancyborders.vercel.app/docs/components/section-grid

## Installation

```bash
npx shadcn@latest add https://fancyborders.vercel.app/r/section-grid.json
```

With the registry namespace: `npx shadcn@latest add @fancyborders/section-grid`.

The CLI also adds what `section-grid` is built on: `frame`.

Files it adds: `components/ui/frame.tsx`, `components/ui/section-grid.tsx`, and its CSS goes into the global stylesheet after the Tailwind import.

## Usage

The code for the preview at its default settings:

```tsx
import { SectionGrid } from "@/components/ui/section-grid";

<SectionGrid mark="plus" outline className="section-cols-3">
  <div className="p-5">Rails</div>
  <div className="p-5">Rules</div>
  <div className="p-5">Grids</div>
  <div className="p-5">Marks</div>
  <div className="p-5">Dashes</div>
  <div className="p-5">Fills</div>
</SectionGrid>
```

## Examples

### Columns at breakpoints

The column utilities take variants. When the last row is not full, the space left over stays open.

```tsx
import { SectionGrid } from "@/components/ui/section-grid";

const STATS = [
  ["1.2M", "requests"],
  ["48ms", "median response"],
  ["99.98%", "uptime"],
  ["312", "deploys"],
  ["0", "incidents"],
];

export default function GridResponsive() {
  return (
    <SectionGrid
      outline
      mark="square"
      className="w-full max-w-lg section-cols-1 sm:section-cols-2 lg:section-cols-3"
    >
      {STATS.map(([value, label]) => (
        <div key={label} className="p-5">
          <p className="text-2xl font-semibold tracking-tight">{value}</p>
          <p className="mt-1 font-mono text-xs text-foreground/60">{label}</p>
        </div>
      ))}
    </SectionGrid>
  );
}
```

### Cells as links

Lines sit in the gaps between cells, so a background on a cell never covers them.

```tsx
import { SectionGrid } from "@/components/ui/section-grid";

const LINKS = ["Docs", "Components", "Theming", "GitHub"];

export default function GridHover() {
  return (
    <SectionGrid outline className="w-full max-w-md section-cols-2 sm:section-cols-4">
      {LINKS.map((name) => (
        <a
          key={name}
          href="#"
          className="px-4 py-6 text-center font-mono text-xs transition-colors hover:bg-foreground/5"
        >
          {name} →
        </a>
      ))}
    </SectionGrid>
  );
}
```

## Good to know

- Set the columns with section-cols-1 to section-cols-8 rather than grid-cols-*. The grid counts its cells to find the last column and the last row, which is how it draws every line once and none on its outer edge.
- Every direct child is a cell. The lines are each cell's ::after and the marks its ::before, and cells are given position: relative.
- The counting assumes one track per cell. On a cell that spans, set --fb-cell-right and --fb-cell-bottom to 1 or 0 to say whether it has a line to its right and beneath it.
- Directly inside page rails the grid stops at the rails instead of crossing them.

## API reference

### SectionGrid

```tsx
import { SectionGrid } from "@/components/ui/section-grid";
```

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"solid" \| "dashed" \| "dotted"` | `"solid"` | Line style of the lines between cells, and of the outline. |
| `mark` | `"plus" \| "square" \| "dot" \| false` | `false` | Mark drawn on every crossing of two lines. |
| `markSize` | `number \| string` | `11, 7 or 5` | Width and height of each mark. The default depends on the mark: plus, square, dot. |
| `outline` | `boolean` | `false` | Draw a border around the whole grid as well. |

Also accepts every Frame prop and every div attribute. Set the columns with a class from section-cols-1 to section-cols-8.
