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.

Possible to use styled syntax from '@emotion/styled' with theme-ui?

See original GitHub issue

Hello,

I wrote some Gatsby themes using Styled Components and their baked in ThemeProvider API to create something similar, but less robust, than theme-ui. Now that themes have officially been released it seems that the “way-to-go” is using the Theme-UI framework and accompanying set of tools. I originally chose Styled Components because I liked the ability to write ‘normal’ CSS using the const Header = styled.header syntax. Coming from more of a CSS/HTML background this made sense to me and let me continue using semi-colons which I was used to while allowing me to also use design tokens which I could pass down to child themes and starter sites using component shadowing.

I am planning to migrate the work I have done to the Theme-UI and Emotion styling systems and was wondering if there was any way to do this while keep the syntax and format I am familiar with, e.g. styled.div or styled.(Img)? And if I do this can I still refer back to the theme-ui theme like I have been doing with the ThemeProvider from styled components? Or is it really best to transition to the {sx} pragma you talk about in the docs? My strong preference is to write old-school normal CSS but with the power of CSS-in-JS.

You can see a bit of what I am trying to do in this repository:

https://github.com/ehowey/gatsby-theme-catalyst-core

It is on NPM but the package on there is a bit out of date as I have been working on it locally in a Yarn workspace.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chaddjohnsoncommented, Jun 22, 2020

I get the following error when using theme-ui with emotion.

const SomeText = styled.div`
  color: ${props => props.theme.colors.primary};
`
Property 'colors' does not exist on type 'object'

Old thread, but for completeness, using the css helper like so should let you reference the theme.

0reactions
arnaudjnncommented, Apr 30, 2020

I get the following error when using theme-ui with emotion.

const SomeText = styled.div`
  color: ${props => props.theme.colors.primary};
`
Property 'colors' does not exist on type 'object'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Styled Components - Emotion
You can create dynamic styles that are based on props and use them in styles. import styled from '@emotion/styled' import { css }...
Read more >
Motivation - Theme UI
Styled System is a much lower-level API that is not in any way coupled to React or Emotion. For example, Styled System works...
Read more >
Styled-components vs. Emotion for handling CSS
Why use Emotion for writing CSS? ... In general, Emotion is more developer-friendly than other libraries. The biggest advantage of Emotion is its ......
Read more >
styled() - MUI System
The styled function is an extension of the styled utility provided by the underlying style library used – either Emotion or styled-components. It...
Read more >
How To Use Emotion for Styling in React | DigitalOcean
Step 3 — Using the styled Components ... emotion also supports a styled component to create an element and style it. It can...
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