-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
This was mentioned in #109 just over a year ago but with very little discussion around it so I hope you don't mind me raising it again.
I've been toying with the idea of switching a very large project over from styled-components to emotion for a while now. Today I bit the bullet and tried doing a mass conversion of thousands of components.
I was very pleased and surprised with how straightforward this was to do thanks to your similar APIs. However, the one feature I'm sorely missing is the ability to define default props; .attrs.
Again, in #109 this was raised but it looks like the suggested approach is to use recompose and withProps. Personally I think this would be better as part of the library.
Much of my conversion was a simple find and replace job, but converting .attrs required a comparatively disproportionate amount of effort. Having to depend on another library for the purpose of importing a single function is fine I suppose, but the syntax is also a bit jarring. The nice thing about the styled API is how readable it can be... however when a styled component with some logical defaults comes along it takes a bit more mental parsing than seems necessary.
Compare
const Input = styled.input`
border: thin solid red;
`;
const Password = styled(Input).attrs({ type: 'password' })`
color: blue;
`;or
const Input = styled.input`
border: thin solid red;
`;
const Password = styled(Input, { type: 'password' })`
color: blue;
`;with
const Input = styled.input`
border: thin solid red;
`;
const Password = withProps({ type: 'password' })(styled(Input)`
color: blue;
`);I know much of this is personal preference, but the withProps variation looks so unlike a 'normal' styled component yet the act of specifying some sensible default props isn't really that exotic, is it?
Anyway, just thought I'd put this out there. I know there is personal preference and library 'purity' as factors too. It just seems to me this would be a tiny addition but one which may help fellow wannabe styled components users like me take the leap.
Thanks.