Usage
Render Jedd Icons without a framework.
The @jedd-icons/core package exports each icon as plain icon data plus two
helpers — createElement for building SVG nodes imperatively, and createIcons
for replacing placeholder elements in the DOM.
createElement
createElement(iconNode, options) returns a live SVGSVGElement you can insert
anywhere:
import { ArrowDownLeft, createElement } from "@jedd-icons/core";
const svg = createElement(ArrowDownLeft, {
size: 32,
color: "#0f172a",
strokeWidth: 1.5,
});
document.getElementById("app").appendChild(svg);Icons are exported as PascalCase data objects (arrow-down-left →
ArrowDownLeft), not as functions — you pass the data to createElement. See
the options reference for every field.
createIcons (auto-replace)
createIcons scans the DOM for placeholder elements and swaps them for rendered
SVGs. Mark up your HTML with a data-jedd attribute naming the icon:
<i data-jedd="ArrowDownLeft"></i>
<i data-jedd="Check" data-jedd-size="40" data-jedd-color="tomato"></i>Then register the icons you use and call createIcons:
import { ArrowDownLeft, Check, createIcons } from "@jedd-icons/core";
createIcons({
icons: { ArrowDownLeft, Check },
attrs: { size: 32 }, // defaults for every replaced icon
});Per-element data-jedd-size, data-jedd-color, data-jedd-stroke-width and
data-jedd-absolute-stroke-width attributes override the shared attrs
defaults. data-jedd-absolute-stroke-width is on when present, so write
data-jedd-absolute-stroke-width="false" to turn off a shared
absoluteStrokeWidth: true for one icon:
<i data-jedd="Check" data-jedd-size="48" data-jedd-absolute-stroke-width></i>Watching for new icons
Set watch: true to install a MutationObserver that replaces placeholders
added after the initial call — useful for dynamically rendered content:
const stop = createIcons({
icons: { ArrowDownLeft, Check },
watch: true,
});
// Later, e.g. when the view that needed it unmounts:
stop();createIcons returns that function whether or not you watch, so you can call it
unconditionally. Each call with watch: true starts its own observer, so stop
the previous one before calling it again.
Unknown icon names are skipped with a console.warn — make sure every name
referenced by data-jedd is present in the icons map.