Using sx pragma with Emotion - Global component for global styles
See original GitHub issueHello,
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:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The Emotion
Global
component’sstyles
prop accepts a function, where you can use values from thetheme
context –<Global styles={theme => ({ })} />
Uh amazing, had to pass it through tho 😅