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.

Using sx pragma with Emotion - Global component for global styles

See original GitHub issue

Hello,

I am trying to use the sx pragma with the Global styles component from emotion to allow me to insert some global styles. Specifically I am wanting to set a global link variable that can be changed through the theme-ui theme spec. Something like this:

"a": {
color: "link.link"
},
"a:visited": {
color: "link.visited"
},
"a:active": {
color: "link.active"
},
"a:focus": {
color: "link.focus"
border: "2px dotted #000"
}

Currently my global styles looks like this:

<Global
          styles={css`
            html {
              box-sizing: border-box;
            }

            *,
            *:before,
            *:after {
              box-sizing: inherit;
            }

            body {
              margin: 0;
              padding: 0;
            }
          `}
        />

I would like to do something like this:

<Global
          sx= {{
         ...styles go here...with access to theme-ui theme files.
        }}
        />

Is this possible?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
jxnblkcommented, Jul 27, 2019

The Emotion Global component’s styles prop accepts a function, where you can use values from the theme context – <Global styles={theme => ({ })} />

1reaction
CanRaucommented, Jan 8, 2020

Uh amazing, had to pass it through tho 😅

<Global styles={theme => theme.styles.Global(theme)} />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Global Styles - Emotion
You can use the Global component to do this. It accepts a styles prop which accepts the same values as the css prop...
Read more >
The `sx` Prop - Theme UI
The sx prop lets you style elements inline, using values from your theme. ... This is intended as a complete replacement for the...
Read more >
MUI v5 with Emotion - NetworkSynapse
If this is your first time hearing about Emotion, let's quickly introduce you. Emotion is a fairly new CSS-in-JS styling library which is...
Read more >
Theme UI with Storybook: A great way to create a components ...
It is called pragma comment, and this is required for the sx property to be used in normal HTML elements. Inside of the...
Read more >
Replacing Styled Components with a 1KB alternative Goober
Goober does this by utilising a custom pragma pattern which is already used in cases like the css prop in emotion or sx...
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