Lab Svg Defs
A drop-in <defs> block that registers a coordinated set of gradients, patterns, and filters used by "lab" / "workbench" style backgrounds — a soft tinted glow, a top-to-bottom node sheen, a corner vignette, and a 20×20 dot-grid pattern.
All IDs are prefixed so multiple instances coexist on the same page without colliding.
Customize
Defs
0.10
0.30
Installation
npx shadcn@latest add https://craftbits.dev/r/lab-svg-defs.jsonUsage
import { LabSvgDefs, labSvgRefs } from "@craft-bits/core";
const r = labSvgRefs("my-lab");
<svg>
<LabSvgDefs id="my-lab" />
<rect width="100%" height="100%" fill={r.grid} />
<rect width="100%" height="100%" fill={r.vignette} />
<g filter={r.glow}>
<circle r={20} fill="var(--cb-accent)" />
<circle r={20} fill={r.nodeGrad} />
</g>
</svg>Understanding the component
- Drop inside
<svg>. LabSvgDefs renders an SVG<defs>element. It must live inside an<svg>to register its gradients, patterns, and filters. - Unique
idprefix. Every gradient / pattern / filter is prefixed with theidyou provide (or a stable sanitizeduseId()if you omit it). Multiple lab visualizations on the same page never clobber each other's defs. - Four pieces, one prefix.
glow(tinted Gaussian-blur bloom),nodeGrad(top-to-bottom sheen),vignette(soft corner darkening), andgrid(20×20 dot pattern). Each one is reachable bylabSvgRefs(prefix). - Theme-aware defaults.
gridColorandglowColordefault tovar(--cb-fg-muted)andvar(--cb-accent)so the defs adapt to the active theme.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | auto | Prefix for gradient / pattern / filter IDs. Auto-generated via useId() if omitted. |
gridColor | string | var(--cb-fg-muted) | Dot color for the grid pattern. |
gridOpacity | number | 0.1 | Dot opacity for the grid pattern. |
glowColor | string | var(--cb-accent) | Tint color for the glow filter. |
glowOpacity | number | 0.3 | Tint opacity for the glow filter. |
Accessibility
<defs>is non-rendered SVG content — it has no a11y surface of its own.- The
<svg>that hosts LabSvgDefs should still carryrole="img"andaria-labeldescribing the visualization.
Credits
- Extracted from:
terminal-dreams(src/components/recipe-lab/shared/LabSvgDefs.tsx).