Add sx prop to Themed components
See original GitHub issueAs of v0.6, the Styled
component was renamed to Themed
. After renaming all imports and updating theme-ui, the sx
styles on my Themed
components are no longer applied unless I explicitly state @jsxImportSource theme-ui
(auto runtime) or @jsx jsx
(classic). The sx
object is also no longer recognized by VS Code as an instance of ThemeUIStyleObject
for Themed
, whereas it is properly reflected for Box
, Image
, etc.
This seems to be a regression made somewhere between 0.5 and 0.6, as all my Styled
components worked as intended up until the 0.6 release. Tested and confirmed on all 0.6 versions.
Example code:
import { Box, Flex, Image, Themed } from 'theme-ui'
export default () => (
<Flex sx={{ width: 100vw, height: 100vh, justifyContent: 'center', alignItems: 'center' }}>
<Box sx={{ flexGrow: 1 }}>
<Image ... />
<Themed.h1 sx={{ textAlign: 'center', textTransform: 'uppercase' }}>Enter Site</Themed.h1>
</Box>
</Flex>
)
Expected:
Actual:
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
The `sx` Prop - Theme UI
The sx prop lets you style elements inline, using values from your theme. To use the sx prop, add the custom /** @jsxImportSource...
Read more >The sx prop - MUI System
The sx prop is a shortcut for defining custom styles that has access to the theme. The sx prop lets you work with...
Read more >Theme Styling with the sx Prop - Sam Rose
Theme UI introduces a powerful styling feature, the sx prop. This prop lets you style elements inline using values from your theme. You...
Read more >Passing sx prop to a custom component - reactjs
In the documentation they just cast the type to const. You can add them as follows using the spread operator: }, sxProps &&...
Read more >MUI V5: The SX Prop - YouTube
In this video I go over React Material UI's new SX prop that comes built into every MUI V5 component. We go over...
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 FreeTop 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
Top GitHub Comments
My mistake, I was testing going back and forth between classic/pragma and automatic/
@jsxImportSource
and must have gotten confused along the way. I went back and tested on a 0.3 site and confirmed thatThemed.X
never had asx
prop without using the pragma.IMO the
sx
prop onThemed.X
components should work without a pragma and without a custom Babel config, just asBox
does now. Using the Babel config suggested in #1335 on a Gatsby site brokegatsby-plugin-mdx
(I removed"importSource": "theme-ui"
to fix this), so I have only added@jsxImportSource theme-ui
to pages that necessitate use of thesx
prop on non-Theme UI components. Currently that includes pages that useThemed.X
- confusing, right? I avoid using the pragma most of the time by aliasing toBox
, i.e.<Box as='article' sx={...}>
or<Box as={GatsbyLink} sx={...}>
, but doing<Box as='h1' variant='styles.h1' sx={...}>
defeats the purpose of having<Themed.h1 sx={...}>
in the first place, so I end up declaring the import source for files that useThemed.X
. AfterThemed.X
has a nativesx
prop, I won’t need to declare@jsxImportSource theme-ui
anywhere.As an aside, it would be cool if
Themed.X
got the variant and style props likeBox
as well.I’m using JS.