Patterns

Pattern presets for series, bands and backgrounds — PatternPreset, the full preset list, and PatternTile for custom tiles

Preview

Installation

pnpm dlx shadcn@latest add @bklit/patterns

Usage

PatternPreset renders an SVG <pattern> definition. Put it inside any chart's children, give it a unique id, and reference it with fill="url(#id)" on a series, slice, segment or link.

import { Area, AreaChart, Grid, PatternArea, PatternPreset, XAxis } from "@bklitui/ui/charts";

<AreaChart data={data}>
  <PatternPreset id="desktop-pattern" preset="diagonal-up" color="var(--chart-1)" />
  <Grid horizontal />
  <PatternArea dataKey="desktop" fill="url(#desktop-pattern)" />
  <Area dataKey="desktop" fillOpacity={0} strokeWidth={2} />
  <XAxis />
</AreaChart>

Pattern ids are global to the document. If the same chart can render more than once on a page, build the id with useId().

Components with a built-in pattern prop take a preset id directly, with no PatternPreset needed: Background, Band, ReferenceArea, Weekends, Deadline, brush selectionPattern, RadialDotBar patterns, and heatmap levelStyles.

<Background pattern="grid" scale={2} />
<Band upperKey="high" lowerKey="low" fillType="pattern" pattern="diagonal-down" />

Presets

Every preset is painted in a single color (color). Base names repeat every 6px. -sparse variants double the spacing and -dense variants halve it.

Lines

vertical6px tile
vertical-dense3px tile
horizontal6px tile
horizontal-dense3px tile
diagonal-up6px tile
diagonal-up-sparse12px tile
diagonal-down6px tile
diagonal-down-sparse12px tile

Grids

grid6px tile

Dashed & dotted lines

vertical-dashed6px tile
horizontal-dashed6px tile
horizontal-dashed-dense6px tile
grid-dashed6px tile
grid-dotted6px tile

Dots

dots6px tile
dots-sparse12px tile
diagonal-dots-up6px tile
diagonal-dots-up-sparse12px tile
diagonal-dots-down6px tile
diagonal-dots-down-sparse12px tile

Circles

circles-dense6px tile
circles12px tile
circles-sparse24px tile

Tiles

blocks6px tile
checkerboard-xs6px tile
checkerboard-sm8px tile
checkerboard12px tile
checkerboard-lg24px tile
checkerboard-inset12px tile
FamilyPresets
Linesvertical, vertical-dense, horizontal, horizontal-dense, diagonal-up, diagonal-up-sparse, diagonal-down, diagonal-down-sparse
Gridsgrid
Dashed & dotted linesvertical-dashed, horizontal-dashed, horizontal-dashed-dense, grid-dashed, grid-dotted
Dotsdots, dots-sparse, diagonal-dots-up, diagonal-dots-up-sparse, diagonal-dots-down, diagonal-dots-down-sparse
Circlescircles-dense, circles, circles-sparse
Tilesblocks, checkerboard-xs, checkerboard-sm, checkerboard, checkerboard-lg, checkerboard-inset

"none" is also accepted and renders nothing. The list is exported as PATTERN_PRESET_IDS (ids, including "none") and PATTERN_PRESETS ({ id, label, family, size } for each preset, without "none"). Use them to build your own pattern picker.

PatternPreset props

PropTypeDefaultDescription
idstringrequiredPattern id. Reference it as fill="url(#id)"
presetPatternPresetId"diagonal-up"Preset to draw
colorstringvar(--chart-1)Pattern color
scalenumber1Tile size multiplier. Line width scales with it
strokeWidthnumber1Line width for line presets, in tile units (multiplied by scale)
opacitynumber1Opacity of the pattern (not the tile background)
tileBackgroundstring—Solid fill painted under the pattern in each tile
default
scale={2}
strokeWidth={2}
opacity={0.4}
tileBackground
<PatternPreset id="a" preset="diagonal-up" /><PatternPreset id="b" preset="diagonal-up" scale={2} /><PatternPreset id="c" preset="diagonal-up" strokeWidth={2} /><PatternPreset id="d" preset="diagonal-up" opacity={0.4} /><PatternPreset  id="e"  preset="diagonal-up"  tileBackground="color-mix(in oklch, var(--chart-1) 12%, transparent)"  />

renderPatternPreset(preset, id, options) returns the same definition as a function call. Use it where you need a ReactNode, for example inside a render prop:

import { renderPatternPreset } from "@bklitui/ui/charts";

<FunnelChart
  data={data}
  renderPattern={(id, color) =>
    renderPatternPreset("diagonal-up", id, { color: "rgba(255,255,255,0.35)", tileBackground: color, scale: 1.5 })
  }
/>

Custom tiles

PatternTile wraps your own artwork in a square, repeating pattern. Draw inside a size × size box and paint with currentColor so color controls it. It takes id, size (default 48), scale, color, opacity and background.

import { PatternTile } from "@bklitui/ui/charts";<PatternTile id="plus" size={12} color="var(--chart-2)">  <path d="M5.5 3h1v6h-1zM3 5.5h6v1h-6z" fill="currentColor" /></PatternTile><Bar dataKey="revenue" fill="url(#plus)" stroke="var(--chart-2)" />

Legacy ids and options

The old preset ids still work and map to the new presets:

Legacy idRenders as
diagonaldiagonal-up
crossgrid
accentdiagonal-up, in #e879f9 unless you set color

horizontal, vertical, dots and circles keep their names but now use the new artwork. The radius, complement, fill and dotFill options (and the pattern* props built from them, such as patternRadius) are deprecated and have no effect. Use resolvePatternPresetId(id) to convert any id to a current one. Unknown ids resolve to "none".

PatternLines, PatternCircles, PatternWaves and PatternHexagons, the primitives ported from @visx/pattern, are still exported but deprecated. Use PatternPreset, or PatternTile for artwork that no preset covers.

Credits

Patterns adapted from Nucleo's free SVG patterns (nucleoapp.com/svg-patterns).