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.

Support inlining styles

See original GitHub issue

Styled-components is great. It’s the approach that i’d like to use in several projects in react-native and web. The problem is, one of those projects involves a page written in react that gets rendered to an email. Best practices for email often involve inlining styles to support the wide variety of clients that render emails. I totally realize there’s some irony in requesting that styled-components support this. At this point, i’m curious as to a workaround where i can obtain the list of props for a given styled component to pass into an inline style prop (obviously this wouldn’t support media queries / hover etc… ).

If styled-components supported this, projects that render their email through react would be able to use styled components for their emails. This is super important as a lot of work goes into creating reusable css components across an entire project, and its important that style-guide components are consistent through emails and the work that goes into creating these clean reusable components can be carried into the much more difficult landscape of email html rendering.

const EmailHeader=styled.div`
  margin-top: ${gap.large};
  ${type.mediumSize()};
  color: ${color.phantomGrey};
`

export default function({user}) => (
    <div> 
      <EmailHeader inlined>Welcome to homeward! {user.name}</EmailHeader>
   </div>
)

Another idea

const EmailHeader=css`
  margin-top: ${gap.large};
  ${type.mediumSize()};
  color: ${color.phantomGrey};
`

export default function({user}) => (
    <div> 
      <EmailHeader style={...EmailHeader.cssRules}>Welcome to homeward! {user.name}</EmailHeader>
   </div>
)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
weaintplasticcommented, Aug 2, 2017

just in case someone stumbles over this and is looking for a solution: We’ve built a little library for rendering inline css for emails in javascript/react. https://github.com/researchgate/inline-stylesheet

3reactions
mxstbrcommented, Apr 1, 2017

We don’t want to add any configuration to styled-components for a variety of reasons. That being said, this does sound very useful.

I’m wondering, could we make this another package (styled-components-email?) which renders to inline styles rather than the DOM and then dynamically switch out the imports?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inline Styles in HTML - Codecademy
For this reason, HTML e-mail often contain lots of inline styles. Some of the styles included may be archaic, to support older e-mail-viewing...
Read more >
A Guide to CSS Inlining in Email - Litmus
“Inlining” styles move the CSS and associated formatting instructions from the style block in the head of your email into the body of...
Read more >
CSP Allow Inline Styles - Content Security Policy
When you enable CSP, it will block inline styles, but there are some ways that you can allow inline styles and still use...
Read more >
Inlining Css Styles - Vero - Getvero.com
When enabling the Inline CSS option, Vero will convert all css styles inside the <style> tags of your HTML to inline styles on...
Read more >
Inline Style in HTML – CSS Inline Styles - freeCodeCamp
Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons ......
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