-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strategy for associating styles to components rather than at the parent level? #57
Comments
What example are you referring to? We have been talking about how to solve this problem as well and are planning on taking the approach that A possible solution to your issue would be to use a post processor on the html. Something like https://emailcomb.com/ |
The example I'm referring to is just this, where a file is read in: https://github.com/wix-incubator/mjml-react-example/blob/master/src/email.js#L18 A post processor feels like a good stopgap but it still doesn't allow me to couple styles with components, so I'll probably keep looking around for a good solution. Thanks! |
yeah agreed. Same reason we aren't doing it |
@kprokopczyk we've started using https://github.com/styled-components/styled-components with mjml-react. This is our "react to mjml" script:
How to use styled components:
This works with deeply nested components. Unfortunately it requires Based on this repo having basically no support. I'm thinking about just implementing my own version with a bunch more functionality like |
@IanEdington Did you end up developing / open-sourcing anything to help with styled-components adoption? |
@gajus not yet but I could... let me get back to you |
I would appreciate that. I spent couple of hours playing with styled-components and Mjml and couldn't make it work. |
@gajus I got the go ahead to open source a couple of our mjml tools. I should be able to get them up early next week |
Please ping in this thread if / when you share those tools. 🙏 |
Sorry for the delay on this. I'm trying to prioritize this work. |
Any chance you could share whatever MVP you've got, even it isn't polished? |
@IanEdington please let us know when you share this! <3 Thank you! |
@IanEdington Any luck? |
Hey all, sorry for leaving you hanging. We have support for this in https://github.com/Faire/mjml-react version 3+ This issue has a short overview of how we use style-components Faire/mjml-react#70 TLDR: We've added |
Amazing! Thanks @IanEdington! |
I have a base template component that i pass my components to and render them inside
MjmlBody
:So I'm reading in css files and rendering the styles in
MjmlHead
, much like your example. For media queries, each of my templates includes ALL the styles, even styles targeted to components that a given template does not include. Since some email clients clip emails over a certain size, I want to only include styles that are relevant to the components included in a given template. Additionally, if I delete a component I want all its style definitions to go with it.I'm wondering if you have any strategies for moving css to the component level so that only the styles associated with the
children
are rendered in head. Like ideally i'd like my components organized like this, with css tied to each component:Thanks for any tips.
The text was updated successfully, but these errors were encountered: