Output svg as a string #1594
-
Hi! // we need all the icons
import { icons } from 'lucide';
...
// inside the template
${when((x) => x.icon,
html`<span :innerHTML="${x => svgMarkup(icons[x.icon])}"></span>`
)}
my previous prototype code was simpler but less efficient since it relied on creating the element just to serialize it... ${when((x) => x.icon,
html`<span :innerHTML="${x => createElement(icons[x.icon]).outerHTML}"></span>`
)} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hmm, yeah I think iconNode to SVG string utility is a bit out of scope for the regular lucide package. So the code will look something like this: const iconElement = createElement(icons[x.icon])
const template = document.createElement("template");
template.append(iconElement)
${when((x) => x.icon, new ViewTemplate(template, {}))} So not sure if this works, I never tested this. Good look! |
Beta Was this translation helpful? Give feedback.
That makes sense. Yeah I think the serializing iconNodes to strings is out of scope for the lucide package. But maybe this is something for a
@lucide/utils
packages, see my idea in #1607 (comment)