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.

[system] Support sx on all primitive elements

See original GitHub issue

Summary 💡

It would be great if we can support the sx props on the primitives with jsx pragma. That would basically help us to replace

<Box
  component="img"
  sx={{
    display: "block",
    mr: { sm: 3 },
    mx: { xs: "auto", sm: 0 },
    mb: { xs: 1, sm: 0 },
    width: { xs: "4rem", sm: "6rem" },
    height: { xs: "4rem", sm: "6rem" },
    borderRadius: "50%"
  }}
  src="https://material-ui.com/static/logo_raw.svg"
/>

with

<img
  sx={{
    display: "block",
    mr: { sm: 3 },
    mx: { xs: "auto", sm: 0 },
    mb: { xs: 1, sm: 0 },
    width: { xs: "4rem", sm: "6rem" },
    height: { xs: "4rem", sm: "6rem" },
    borderRadius: "50%"
  }}
  src="https://material-ui.com/static/logo_raw.svg"
/>

For instance https://xstyled.dev/docs/emotion/#use-css-prop or https://theme-ui.com/sx-prop. It seems that we could only support it with emotion, which is OK-ish as it’s the default engine 🙃.

Motivation 🔦

This would help us to move away from templates that would use the Box component everywhere. On the other hand, we plan to support the sx prop on all core components, so it may not be that bad, but still, I think this is something that will bring us in the right direction.

Raised in #23053

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:43
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
oliviertassinaricommented, Sep 29, 2021

There were also discussions about changing the prefered API from:

<Box component="footer" sx={{ display: "block" }}>
   My footer
</Box>

to

<x.footer sx={{ display: "block" }}>
  My footer
</x.footer>

inspired by https://xstyled.dev/. This is superior when you have long children. The closing tag is more helpful in the latter option (</x.footer> is more helpful than </Box>).

See https://github.com/mui-org/material-ui/pull/27207#issuecomment-880731270 for why it could be valuable for developers.

6reactions
yuchicommented, Oct 24, 2020

There’s no need for a pragma, you can release a Babel macro in a similar fashion to Styled Components’.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[system] Support sx on all primitive elements #23220 - GitHub
// just an example of importing primitives import { mui } from '@material-ui/core/primitives'; // remain the same const styles = (theme: Theme) ...
Read more >
MUI on Twitter: "v5.0.0-alpha.14 is out ! Extend the system with ...
Extend the system with a new `sx` prop Upgrade Popper.js from v1 to v2 ... [system] Support sx on all primitive elements ·...
Read more >
MUI System - Overview
MUI System is a set of CSS utilities to help you build custom designs more efficiently when working with MUI component libraries like...
Read more >
COUNTING PRIMITIVE ELEMENTS IN FREE GROUPS - UPC
Note that this notion does not depend on the set of generators because for every other finite generating system Y ,. 6. Page...
Read more >
XML Schema Part 2: Datatypes Second Edition - W3C
The type system defined in this specification provides a ... All ·minimally conforming· processors ·must· support year values with a minimum ...
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