Astro Hexagon Pattern
A hexagon background that fills its container. The hover effect is optional.
Installation
bunx --bun shadcn@latest add @gnostic/hexagon-patternnpx shadcn@latest add @gnostic/hexagon-patternpnpm dlx shadcn@latest add @gnostic/hexagon-patternCopy the files
src/components/patterns/hexagon-pattern/hexagon-pattern.astrosrc/components/patterns/hexagon-pattern/hexagon-pattern.tssrc/components/patterns/hexagon-pattern/index.tssrc/components/patterns/hexagon-pattern/types.ts
Usage
The component is the box. Give it a height. The script fills that box with
hexagon rows. Content in the slot sits above the field. Give text relative z-10
when the text must stay above the hexagons.
import { HexagonPattern } from "@/components/patterns/hexagon-pattern"
<HexagonPattern class="h-72" />
hoverEffect adds the hover color classes. Leave it unset for a static field.
<HexagonPattern hoverEffect class="h-72" />
hexagonSize is the width of one hexagon, in pixels. hexagonMargin is the
gap. That gap is also the border thickness. hexagonColor paints each hexagon.
gapColor paints the space between them. Leave gapColor unset to use bg-muted.
hoverFill and hoverStroke are the colors used while the pointer is over a
hexagon. They apply only when hoverEffect is true.
Each preview has a Hover effect switch. The switch adds or removes the
same classes as hoverEffect.
Examples
Large hexagons
hexagonSize sets the width. A larger size uses fewer cells.
Small hexagons
A smaller size uses more cells. Lower hexagonMargin to keep the gap thin.
Gradient overlay
A gradient layer covers part of the field. pointer-events-none lets the
pointer reach the hexagons that remain visible.
Custom colors
gapColor, hexagonColor, hoverFill, and hoverStroke accept any CSS color.
The two fields below use different sets of those colors.
Without the hover effect
Leave hoverEffect unset. The switch at the top can still turn the classes on.
API Reference
HexagonPatternProps
hexagonSize?number
Width of one hexagon, in pixels. The height is 1.1 times this width.
number75hexagonMargin?number
Space between hexagons, in pixels. This space is also the border thickness.
number3hoverEffect?boolean
Change each hexagon color when the pointer is over it.
booleanfalsehexagonColor?string
CSS color of each hexagon.
string"var(--background)"gapColor?string
CSS color of the space between hexagons. Leave this unset to use the `bg-muted` class. A caller `bg-*` class can replace that class.
stringhoverFill?string
CSS color of the hexagon fill while the pointer is over it. Used when `hoverEffect` is true.
string"var(--muted)"hoverStroke?string
CSS color of the hexagon border while the pointer is over it. Used when `hoverEffect` is true.
string"color-mix(in oklch, var(--foreground) 18%, var(--background))"hexagonClass?string
Extra classes for each hexagon. Use this to replace a fill or a hover color.
stringSee the registry source for the component source.