Skip to content

[doc] Add differences between styled and sx - #28685

Merged
mnajdova merged 11 commits into
mui:masterfrom
eric-burel:patch-2
Oct 28, 2021
Merged

mnajdova merged 11 commits into
mui:masterfrom
eric-burel:patch-2

Conversation

@eric-burel

@eric-burel eric-burel commented Sep 29, 2021 •

Copy link
Copy Markdown
Contributor

See #28678

This PR explains the difference between sx and styled.

Note: there is also an underlying issue, because it seems to me that TypeScript currently doesn't catch when you use mx or similar shortcuts into styled, while it shouldn't accept those.

@mnajdova mnajdova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, left some feedback to address. Let me know what you think!

Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
@mnajdova

Copy link
Copy Markdown
Member

Note: there is also an underlying issue, because it seems to me that TypeScript currently doesn't catch when you use mx or similar shortcuts into styled, while it shouldn't accept those.

I will need to investigate this further, but it seems like it may come from this line: https://github.com/mui-org/material-ui/blob/master/packages/mui-system/src/createStyled.d.ts#L20 (which is needed for supporting the nested selectors as far as I remember).

Co-authored-by: Marija Najdova <mnajdova@gmail.com>
@mui-pr-bot

mui-pr-bot commented Sep 29, 2021 •

Copy link
Copy Markdown

No bundle size changes

Generated by 🚫 dangerJS against 6e410dc

@eric-burel

Copy link
Copy Markdown
Contributor Author

I've tried to bring some improvements, let me know if that's better. I've added infos about the theme because that's not obvious either

Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
@mnajdova
mnajdova requested a review from mbrookes September 30, 2021 08:11

@mnajdova mnajdova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied some small changes, the content itself looks good to me. Let's wait for @mbrookes review and we can merge. Thanks a lot for the contribution @eric-burel 🙏

@mui mui deleted a comment from mnajdova Oct 1, 2021
Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved
Comment thread docs/src/pages/system/styled/styled.md Resolved

@mnajdova mnajdova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@mnajdova
mnajdova dismissed mbrookes’s stale review October 28, 2021 08:53

Comments addressed

@mnajdova
mnajdova merged commit e428472 into mui:master Oct 28, 2021
@mnajdova mnajdova changed the title [doc] add differences between styled and sx [doc] Add differences between styled and sx Oct 28, 2021
})
// Note: for direct theme access without modification, you can also use a shortcut by providing the key as a string
const MyStyledButton = (props) => (
<button sx={{backgroundColor: "primary.main"}}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious - do host elements (lowercase button) accept an sx prop?

@zannager zannager added the docs Improvements or additions to the documentation. label Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to the documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants