Styled Decorator
See original GitHub issueCould you add in the following code where appropriate:
styled.decorator = (strings, ...values) => (Component) => styled(Component)(strings, ...values);
So that we can begin using styled-components in the following way:
@styled.decorator`
padding: 10px;
background: blue;
font-size: 12px;
`
export class SomeThing extends React.Component {
render() {
return <div className={this.props.className}>Hello World</div>;
}
}
It would look much cleaner than writing:
class SomeThingComponent extends React.Component {
render() {
return <div className={this.props.className}>Hello World</div>;
}
}
export const SomeThing = styled(SomeThingComponent)`
padding: 10px;
background: blue;
font-size: 12px;
`
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:15 (6 by maintainers)
Top Results From Across the Web
Decorators - Storybook - JS.ORG
A decorator is a way to wrap a story in extra “rendering” functionality. Many addons define decorators to augment your stories with extra...
Read more >THELIFESTYLEDCO™ | Full-Service Interior Design ...
THELIFESTYLEDCO™ is a full-service interior design firm and lifestyle shops based in Arizona, and rooted in our trademarked aesthetic, Organic Desert ...
Read more >Interior Design Styles 101: The Ultimate Guide To Defining ...
Check out Decorilla's ultimate guide to decoding everything you need to know about the top 20 interior design styles for 2023!
Read more >Style By Emily Henderson
Biggest Design Mistakes · Budget Ideas · Design Trends · Makeovers · Design Rules · Whats on My Body · How to style...
Read more >Decorating Styles on Houzz: Tips From the Experts
Get expert advice on a wide variety of decorating styles, including modern, traditional, eclectic, coastal and rustic decor styles.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t think we’re going to support this officially I’m afraid, for the reasons stated above. I’m not convinced this adds any value to the library, in fact I think it takes away from the value of using it.
It’s simply not possible and not supported, because it would allow users to easily go against or enforced best practices and methodologies.
By default we do offer passing in any component into the styled factory function, and that can be used as an escalation e hatch or even to make this possible with a helper, but it’s mainly for complex stacks of components and third party components.
It’s not recommended to use this frequently, as building up your component structures from bottom to top leads to cleaner architectures that scales. At the bottom you’ll find pure presentational components, above them structural ones, and at the top container/smart components. This can of course be nested and combined in different ways.
But by allowing this pattern by default, we’d be recommending to put the presentational components, like a stylesheet, at any position of this component stack, which is less desirable.
So if you really want to do this, we’re not stopping you. But try to keep this in mind, and we believe you’ll likely find more scalable styling code as a result.