Skip to content
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

Replace Radium with Emotion 👩‍🎤 #394

Merged
merged 6 commits into from
Mar 29, 2018
Merged

Replace Radium with Emotion 👩‍🎤 #394

merged 6 commits into from
Mar 29, 2018

Conversation

jstcki
Copy link
Contributor

@jstcki jstcki commented Mar 27, 2018

Replace Radium with Emotion to solve long-standing issues like not being able to statically render pages and rendering issues with media queries.

This PR is pretty much a direct translation of the Radium styles to Emotion, i.e. in most of the places I just replaced style={x} with className={css(x)}. In future updates we can migrate to template string styles or styled components if desired.

For the elements on Markdown pages I got rid of the complicated nested page styles generated in styles/typography.js in favor of styled elements (I didn't use react-emotion directly, as the use case here is slightly different and simpler).

@grossbart
Copy link
Contributor

👏

@jstcki jstcki changed the title [WIP] Replace Radium with Emotion 👩‍🎤 Replace Radium with Emotion 👩‍🎤 Mar 27, 2018
@jstcki jstcki requested review from grossbart and bldng March 27, 2018 20:24
Copy link
Contributor

@grossbart grossbart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, at least on the code level, I haven't looked at how it runs.

When I started the server, this circular dependency was brought to my attention:

(!) Circular dependency: src/components/Menu/ListItem.js -> src/components/Menu/NestedList.js -> src/components/Menu/ListItem.js
(!) Circular dependency: src/components/Menu/Menu.js -> src/components/Menu/ListItem.js -> src/components/Menu/NestedList.js -> src/components/Menu/Menu.js


const context = typeof global !== "undefined" ? global : {};

if (context.__CATALOG_EMOTION_INSTANCE__ === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was already wondering how to resolve a conflict of multiple Emotion instances – and then I saw this. Perfect.

[`${selector} b, strong`]: {
fontWeight: 700
},
[`${selector} a, a:visited`]: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the new Content/Markdown.js we no longer handle a:visited from what I can tell, but we should.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem necessary – at least in Chrome and FF 🤔

Also, these selectors didn't even work properly! They should've been ${selector} a, ${selector} a:visited etc.

...inlineElements(theme, `${selector} >`)
});

export const unorderedList = (theme, selector = "ul", level = 0, depth = 0) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see how nested lists are handled in the new Content/Markdown.js – does it still work? I think it should …

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each component "owns" its styling now. We don't need to select nested lists from the top like .cg-Page > ul > li > ul anymore.

List items just remove the top and bottom margin of their first/last child respectively.

@@ -52,8 +52,8 @@ class Loader extends React.Component {
render() {
const loader = this.state.visible ? styles.spinner : styles.hidden;

return <div style={loader} className="cg-Page-Loader" />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did .cg-Page-Loader not have styles before? I wanted to make sure we did not forget to remove these obsolete styles, but I could not find them ¯_(ツ)_/¯

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, all the .cg-* classes were either leftovers from before Radium or necessary for creating deep selectors like .cg-Page > p. There's no reference to cg- anywhere in the code anymore.

@jstcki
Copy link
Contributor Author

jstcki commented Mar 28, 2018

@grossbart Thanks for the review!

The circular dependency was already present before this PR. It hasn't been a problem so far, but we should remove it. But let's do that in another PR 😉

To check functionality you can compare https://deploy-preview-394--catalog-docs.netlify.com/ and https://docs.catalog.style – I've tried to reproduce the original styling accurately and I'm not aware of any discrepancies. A second pair of 👀would definitely be useful!

@jstcki jstcki merged commit 6594572 into master Mar 29, 2018
@jstcki jstcki deleted the emotion branch March 29, 2018 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants