question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating style object with styled components?

See original GitHub issue

I’ve been researching solutions for css in js solutions and styled-components by far looks better than anything out there, love the syntax and clean approach. Only issue for out project is the concept of “creating components by styling them”, hence I wanted to see if it is possible to create style objects with styled components i.e something like following

const myStyle = ` backgroundColor: red `

<MyComponent style={myStyle} />

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
geelencommented, Mar 23, 2017

That’s part of the Attrs constructor #365

styled(RadioButton).attrs({
  labelStyle: {
    inline: 'styles',
  }
})`
  css: rules;
`
3reactions
Haraldsoncommented, Dec 15, 2020

I think I understand the reason you refer to in your answer, @mxstbr; you don’t want to encourage bad practices.

However, a scenario I often find myself in, is having to somehow style third-party library components using React inline style attributes. In a lot of these cases, I already have a styled-component in my library, as this is the solution I have bought into and love. Being able to somehow transform/export those style definitions to style objects for third-party library consumption would be incredibly powerful and developer-friendly.

Not sure if any of this has changed over the course of the four last years, if so please enlighten me!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Usage - styled-components
styled -components generates an actual stylesheet with classes, and attaches those classes to the DOM nodes of styled components via the className prop....
Read more >
Styled Components Style Objects - Paul Scanlon
Styled Components Style Objects · Destructuring props · Decendent/Sibling selectors · Pseudo-classes · Spread operator · Unitless CSS values · With ...
Read more >
How To Use Styled-Components In React - Smashing Magazine
In React's own words, styled components are “visual primitives for components”, and their goal is to give us a flexible way to style...
Read more >
The Advanced Way to Style with Styled Components
This component accepts an inline style object that is then merged into the Styled Components styles by simply returning the object into the ......
Read more >
Advanced ways to write styled-components - Medium
In this example, you will create the item styled component and then the unordered list styled component. Within the unordered list style, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found