So, I’m using nextjs + svgr + tailwind in my app.
I’m dynamically changing size and color of my svgs, but I also want to add "flex-shrink-0 fill-current" globally to all my icons.
I want to render my icon with:
<AlertIcon className="text-red size-5" />
and to be sure it would also have "flex-shrink-0 fill-current" applied to it.
2
Answers
Yup, I simply added Icon component and put all logic there
src/components/Icon.tsx
src/icons/index.ts
Icon render
You could try adding a wrapper component around the icons and pass the size and color down as explicit props, along with whichever icon you wish to render.
Then in your SVG file, remove any fill or stroke attributes so Tailwind can modify those with classes. See Tailwind SVGs