To achieve type-safety, flexibility and small bundle size, we've implemented a lazy-loaded icons mechanism based on:
generate-iconsscript (to create types and icon chunks)icons.gen.ts- the generated part that provides the APIIconcomponent that leverages the generated code and lazy-loads the chunks
To use an icon in your component, import it from @workflow-builder/icons and pass the name prop:
import { Icon } from "@workflow-builder/icons";
<Icon name="Acorn" />You may provide more props and extend their type directly in the icon file.
- Add new icon sources to
ICON_SOURCESingenerate-iconsfile:
const ICON_SOURCES: IconSource[] = [
//...
{
path: '../../../assets/icons/',
},
{
path: '../../node_modules/some-cool-icons/dist/svg'
}
];-
Generate the icons using
pnpm i. It will trigger thepreparescript of@workflow-builder/iconspackage. -
Commit the newly generated
icons.gen.tsfile