digitalfabrik/integreat-cms

View on GitHub
integreat_cms/static/src/js/utils/create-icons.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { icons } from "lucide";
import replaceElement from "lucide/dist/esm/replaceElement";

// This function renders all <i icon-name="..."> children of `root`
export const createIconsAt = (root: HTMLElement) => {
    const elementsToReplace = root.querySelectorAll("[icon-name]");
    Array.from(elementsToReplace).forEach((element) =>
        replaceElement(element as HTMLElement, {
            nameAttr: "icon-name",
            icons,
            attrs: { class: "inline-block" },
        })
    );
};