Replies: 1 comment
-
If anyone else finds this post and wants to do something similar, you can add custom icons like this: import { createReactComponent } from '@tabler/icons-react';
import { parseSync } from 'svgson';
import IconRaw from './icon.svg?raw';
const icon = parseSync(IconRaw);
const children = icon.children.map(({ name, attributes }, i) => {
attributes.key = `svg-${i}`;
attributes.strokeWidth = attributes['stroke-width'];
delete attributes['stroke-width'];
return [name, attributes];
});
const Icon = createReactComponent('outline', 'icon', 'icon', children);
export default Icon; Obviously there's some abstraction you can do if you want to do multiple icons. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Im my React projects, I'm starting to feel a need for custom project-specific icons. I would like them to follow the same syntax and feel as Tabler, so I need to convert whatever comes from the designer.
Currently, from an initial SVG, I had to do the following:
rsvg-convert
to scale the icon to 24x24svgo
to optimize the paths and remove the transformsexport const IconCustom = createReactComponent('custom', 'IconCustom', [])
d
,fill
andstrokeWidth
) from the SVG to the componentThis is somewhat unfullfillling. I would very much like to adopt what Tabler does in the build step -- iterate over SVGs, validate, clean-up, sane-check, convert them to components, export components, but I can't reuse anything from
build-icons.mjs
, since it's not exposed and not really suited for external icons.Ideally, I'd like to have something like this (I'm using Vite, but raw imports should work similarly elsewhere):
with
svgToIconData
being whatever is happening inbuild-icons.mjs
to producechildren
.Is there a way this could happen? Is there a better way than what I've described?
Beta Was this translation helpful? Give feedback.
All reactions