Svg Defs
A drop-in <defs> block that registers the canonical arrow markers (default + highlighted) and the three glow filter tiers (subtle / medium / bright) for SVG-native nodes.
Before centralizing these, every graph renderer hand-rolled its own <marker> and <filter> with subtly different geometry. SvgDefs eliminates that drift.
Customize
Markers & filters
medium
Installation
npx shadcn@latest add https://craftbits.dev/r/svg-defs.jsonUsage
import { SvgDefs, svgMarkers } from "@craft-bits/core";
const m = svgMarkers("my-graph");
<svg>
<SvgDefs id="my-graph" hex="#4A7BF7" />
<line markerEnd={m.arrow} ... />
<line markerEnd={m.arrowHl} ... />
<circle filter={m.glowMedium} ... />
</svg>Understanding the component
- Drop inside
<svg>. SvgDefs renders an SVG<defs>element. It must live inside an<svg>to register its markers and filters. - Unique
idprefix. Every marker / filter is prefixed with theidyou provide (or a stableuseId()if you omit it). Multiple SVGs on the same page can coexist without clobbering each other's defs. - Two arrows, three glows.
arrow(muted foreground) andarrowHl(hexaccent) for directed edges;glowSubtle/glowMedium/glowBrightfor SVG-native node halos. - Pair with
svgMarkers(id). It returnsurl(#…)strings ready formarkerStart/markerEnd/filterprops — no template literals at the call site.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
hex | string | required | Accent hex for the highlighted arrow and glow tint. |
id | string | auto | Prefix for marker / filter IDs. Auto-generated via useId() if omitted. |
Accessibility
<defs>is non-rendered SVG content — it has no a11y surface of its own.- The
<svg>that hosts SvgDefs should still carryrole="img"andaria-labeldescribing the visualization.
Credits
- Extracted from:
algoflashcards(src/lessons/primitives/graph/SvgDefs.tsx).