# Frame

> The primitive everything else is built from: an enclosure plus border, rule, corner-mark and fill layers you compose yourself.

- Category: Frames (Structural frames: brackets, rails, marks and hatching.)
- Registry item: `frame`
- Live preview with controls: https://fancyborders.vercel.app/docs/components/frame

## Installation

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

With the registry namespace: `npx shadcn@latest add @fancyborders/frame`.

Files it adds: `components/ui/frame.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 { Frame, FrameCorners, FrameRules } from "@/components/ui/frame";

<Frame className="p-6">
  <FrameRules overshoot={10} />
  <FrameCorners mark="plus" />
  Content
</Frame>
```

## Examples

### Tailwind tokens

Colour, line width and radius are ordinary utilities, so they take variants like hover and dark.

```tsx
import { Frame, FrameBorder, FrameCorners } from "@/components/ui/frame";

export default function FrameTokens() {
  return (
    <Frame className="w-full max-w-xs p-6 transition-colors frame-color-sky-500/50 frame-line-2 frame-mark-sky-500 frame-radius-xl hover:frame-color-sky-500">
      <FrameBorder variant="dashed" offset={-6} radius={8} />
      <FrameCorners mark="bracket" size={20} />
      <p className="font-mono text-sm">frame-color-sky-500/50</p>
    </Frame>
  );
}
```

### Custom corner marks

Pass children to FrameCorners to draw your own mark. It is drawn for the top-left corner and rotated onto the others.

```tsx
import { Frame, FrameBorder, FrameCorners } from "@/components/ui/frame";

export default function FrameCustomMark() {
  return (
    <Frame className="w-full max-w-xs p-6">
      <FrameBorder />
      <FrameCorners size={14} align="center">
        <svg viewBox="0 0 14 14" className="size-full fill-background">
          <path d="M7 1 13 7 7 13 1 7Z" stroke="currentColor" />
        </svg>
      </FrameCorners>
      <p className="font-mono text-sm">Diamond marks</p>
    </Frame>
  );
}
```

## Good to know

- Layers are absolutely positioned and never take part in layout, so they can go inside a frame in any order, before or after the content.
- Every layer reads its line width, colour and radius from the frame, so setting them once on the frame restyles all of them.

## API reference

### Frame

```tsx
import { Frame } from "@/components/ui/frame";
```

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `radius` | `number \| string` | `0` | Corner radius shared by the frame and its layers. |
| `line` | `number \| string` | `1` | Line width shared by borders, rules and marks. |
| `color` | `string` | `22% of the text colour` | Line colour for borders, rules and fills. |

Also accepts every div attribute, such as className and style.

### FrameBorder

```tsx
import { FrameBorder } from "@/components/ui/frame";
```

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"solid" \| "dashed" \| "dotted" \| "double"` | `"solid"` | The CSS border style. |
| `offset` | `number \| string` | `0` | Distance from the frame's edge. Positive is outward, negative inward. |
| `radius` | `number \| string` | – | Overrides the frame's radius for this layer. |
| `color` | `string` | – | Overrides the frame's line colour for this layer. |

Also accepts every div attribute, such as className and style.

### FrameRules

```tsx
import { FrameRules } from "@/components/ui/frame";
```

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `sides` | `("top" \| "right" \| "bottom" \| "left")[]` | `all four` | Which sides get a line. |
| `overshoot` | `number \| string \| { x?, y? }` | `0` | How far the lines run past the corners. x extends the horizontal lines, y the vertical ones. |
| `dash` | `number \| string` | `4` | Dash length. Setting dash or gap makes the lines dashed. |
| `gap` | `number \| string` | `4` | Space between dashes. |
| `march` | `boolean \| number` | `false` | Make the dashes travel clockwise. A number is the seconds a dash takes to reach the next one's place; true is 0.6. |
| `offset` | `number \| string` | `0` | Distance from the frame's edge. Positive is outward, negative inward. |
| `color` | `string` | – | Overrides the frame's line colour for this layer. |

Also accepts every div attribute, such as className and style.

### FrameCorners

```tsx
import { FrameCorners } from "@/components/ui/frame";
```

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `mark` | `"bracket" \| "square" \| "plus" \| "dot"` | `"bracket"` | Built-in mark. Ignored when children are given. |
| `children` | `ReactNode` | – | A custom mark, drawn for the top-left corner and repeated on the rest. |
| `corners` | `("tl" \| "tr" \| "br" \| "bl")[]` | `all four` | Which corners get a mark. |
| `size` | `number \| string` | `12, 7, 11 or 5` | Width and height of each mark. The default depends on the mark: bracket, square, plus, dot. |
| `thickness` | `number \| string` | – | Line width of the mark, when different from the frame's. |
| `align` | `"inside" \| "center"` | – | inside tucks the mark into the corner, center centres it on the frame's line. Brackets and custom marks default to inside. |
| `rotate` | `boolean` | `true` | Rotate each mark to face its corner. Turn off for upright content. |
| `offset` | `number \| string` | `0` | Distance from the frame's edge. Positive is outward, negative inward. |
| `radius` | `number \| string` | – | Radius of a bracket's corner, when different from the frame's. |
| `color` | `string` | – | Colour of the marks. Defaults to the text colour. |

Also accepts every div attribute, such as className and style.

### FrameFill

```tsx
import { FrameFill } from "@/components/ui/frame";
```

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `pattern` | `"hatch" \| "cross" \| "dots" \| "grid"` | `"hatch"` | The pattern painted behind the content. |
| `size` | `number \| string` | `6` | Spacing between lines or dots. |
| `thickness` | `number \| string` | `1` | Line width, or dot radius. |
| `angle` | `string` | `"135deg"` | Direction of the hatch lines. |
| `inset` | `number \| string` | `0` | Distance kept clear from the frame's edge. |
| `color` | `string` | – | Colour of the pattern. Defaults to the line colour. |

Also accepts every div attribute, such as className and style.
