Can I use tailwind classes ( like colors ) into the styled-components ? I want to use some classes instead of CSS styles to style my components this is the way add class in styled-components:
JavaScript
x
6
1
const Button = styled.button.attrs(props => ({
2
className: "small",
3
}))`
4
/* other styles */
5
`;
6
so unlike styles, attrs className is only one single string, and I want to add classes for size, color, display and etc. I have to concat them all every time, is there a better way ?
Advertisement
Answer
You can use macro, I suggest trying twin.macro
:
JavaScript
1
9
1
import tw, { styled } from 'twin.macro'
2
3
const Input = styled.input`
4
color: purple;
5
${tw`border rounded`}
6
${({ hasHover }) => hasHover && tw`hover:border-black`}
7
`
8
const Component = () => <Input hasHover />
9