Astro Grid Pattern
An SVG grid background that fills its container and can highlight selected squares.
Installation
bunx --bun shadcn@latest add @gnostic/grid-pattern
Usage
Place the pattern inside a parent that has a relative class. The grid pattern will fill the container via absolute inset-0, and will not intercept clicks or other events.
import { GridPattern } from "@/components/patterns/grid-pattern"
<div class="relative h-72 overflow-hidden">
<GridPattern />
</div>
Examples
Highlighted squares
squares accepts [column, row] pairs. Each pair fills one cell.
Dashed lines
Set strokeDasharray to change the grid stroke. "0" draws a solid line.
Pointer glow
The lines stay hidden until the pointer moves over them. The mask draws one grid cell. Hover Glow fades that mask in under the pointer. Leave the mask unset to paint a glow over a visible grid instead.
API Reference
GridPatternProps
width?number
Width of one grid square, in user units.
number60height?number
Height of one grid square, in user units.
number60x?number
Horizontal offset of the pattern.
number-1y?number
Vertical offset of the pattern.
number-1squares?Array<[x: number, y: number]>
Cells to fill, as `[column, row]` pairs.
Array<[x: number, y: number]>strokeDasharray?string
SVG stroke dash array for the grid lines. Use `"0"` for a solid line.
string"0"The default color uses fill-muted-foreground/30 and stroke-muted-foreground/30.
Pass a fill-* or stroke-* class, or set the fill or stroke directly on the SVG element.
See the registry source for the component source.