Twin.Macro with Storybook and SVGR Loader #545
-
Hello I'm using twin.macro with Styled-Components within Storybook and, I'm using SVGR Loader for svgs. When I'm adding tw and css props to my SVG component it does work normally, unless I'm using the component with a dynamic name. import React from 'react';
import tw, { TwStyle } from 'twin.macro';
import ArrowRightIcon from '../../../assets/arrow-right.svg';
const IconVariants = {
'arrow-right': ArrowRightIcon,
}
interface Props extends React.SVGAttributes<SVGElement> {
variant?: keyof typeof IconVariants;
extraCss: string | TwStyle | TwStyle[];
}
const Icon: React.FC<Props> = ({ variant = 'arrow-right', extraCss }) => {
const IconComponent = IconVariants[variant];
return (
<IconComponent tw="inline fill-current stroke-current" css={extraCss} />
); // <-- doesn't work
return (
<ArrowRightIcon tw="inline fill-current stroke-current" css={extraCss} />
); // <-- work
};
export default Icon; Here are the errors I get in Storybook, when I add just the I wonder if it is a twin.macro bug or if I'm doing things wrong. Thanks for the help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Hey there! |
Beta Was this translation helpful? Give feedback.
Hey there!
Could you also share an example of your
IconVariants
component so I can see how you're selecting the icon (and passing the props to it)?