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

refactor: migrate styled-components to emotion #309

Merged
merged 1 commit into from
Oct 3, 2022

Conversation

tien
Copy link
Member

@tien tien commented Oct 2, 2022

Emotion is a much newer CSS in JS Framework that is a superset of Styled Components, it does everything that Styled Component does, in addition:

  • Support in-line object styled CSS, giving much better TypeScript support & doesn't force you to name every single components of which you want to style:
<div css={{ background: "red", padding: "2rem" }} />
  • More performance & smaller size, here is one test for reference.
  • Support React 18 Concurrent React.
  • Is preferred as the successor to Styled Component by the community, for example Storybook team migrated to emotion from Styled Component. Also used by many other projects such as Chakra UI, WordPress UI, etc.

@netlify
Copy link

netlify bot commented Oct 2, 2022

Deploy Preview for talisman-web ready!

Name Link
🔨 Latest commit 04f7e89
🔍 Latest deploy log https://app.netlify.com/sites/talisman-web/deploys/633a298e5afb2300093669e6
😎 Deploy Preview https://deploy-preview-309--talisman-web.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@tien tien force-pushed the refactor/migrate-styled-components-to-emotion branch from 6fc1b3e to 04f7e89 Compare October 3, 2022 00:15
Copy link
Contributor

@jonathanpdunne jonathanpdunne left a comment

Choose a reason for hiding this comment

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

Tailwind would be awesome in the long term, but this change LGTM for now!

@tien tien merged commit 8114f88 into prod Oct 3, 2022
@tien tien deleted the refactor/migrate-styled-components-to-emotion branch October 3, 2022 12:09
@tien
Copy link
Member Author

tien commented Oct 3, 2022

Tailwind would be awesome in the long term, but this change LGTM for now!

Hey @jonathanpdunne I have had a quick chat with @alecdwm on this, actually.

It's down to personal preferences, of course. But I'm strongly leaning against using Tailwind for the following reasons:

I do prefer in-line styling to global styles as it promote composition of components rather than composition of styles.

But I dislike the CSS utility classes approach, where it's simply just hiding the underlying CSS & doesn't allow you to fully take advantage of what CSS has to offer.

Whereas there's no downside to just use CSS directly using Emotion like so: https://emotion.sh/docs/object-styles.

In my opinion, the following (with full TypeScript support):

<div css={{
  display: 'flex',
  flexDirection: 'column',
  backgroundColor: 'red',
  ':hover': {
    background: 'blue',
    flexDirection: 'row',
    padding: '1rem',
  },
  ':first-child': {
    borderRadius: "1rem",
    ':hover': {
      background: 'yellow',
    }
  },
}} />

Which get compiled to (result in much better debug experience)

<div class="css-1e2w6ik" />

Is much better and more readable than:

<div className="flex flex-col bg-red hover:bg-blue hover:row hover:p-1 first:rounded-2xl first:hover:bg-yellow"/>

You get the full power of CSS, much better knowledge over how CSS work.

An example where having full CSS capability is much better:

// Undoing the font size
<SomeComponentWithStyling css={{ fontSize: 'initial' }} />
// Tailwind would require knowing the exact default fontSize
<SomeComponentWithStyling className="text-xl" />

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.

None yet

2 participants