Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs][material-ui] Improve theme.applyStyles() docs #44658

Merged
merged 12 commits into from
Dec 20, 2024

Conversation

DiegoAndai
Copy link
Member

@DiegoAndai DiegoAndai commented Dec 5, 2024

Closes #44488

Preview for changed pages is here: #44658 (comment)

Add docs to address the four concerns raised in #44488:

  1. Sx and Styled can't override styles that use theme.applyStyles due to specificity
    -> Add specificity warning and example

  2. theme.applyStyles doesn't support template literal syntax so the css selector has to either be extracted to a var or hardcoded
    -> Add section explaining how to override theme.applyStyles to cover this and any other custom case

  3. Docs are inconsistent on recommendations. Docs say to use spread syntax on theme.applyStyles, then the actual code files say to not use spread syntax. ie. Docs, Code
    -> Use same convention in docs as in code source

  4. applyStyles isn't a valid replacement for controlling the theme of specific components. If you only specify dark theme styles with applyStyles, then adding .mode-light to a component won't apply those styles since .mode-dark has higher specificity. Refer to link for example
    -> Can be covered following the override theme.applyStyles section

@DiegoAndai DiegoAndai added docs Improvements or additions to the documentation package: material-ui Specific to @mui/material customization: theme Centered around the theming features labels Dec 5, 2024
@DiegoAndai DiegoAndai requested a review from siriwatknp December 5, 2024 16:34
@DiegoAndai DiegoAndai self-assigned this Dec 5, 2024
@DiegoAndai DiegoAndai force-pushed the improve-applystyles-docs branch from 6a340d7 to c68a51b Compare December 5, 2024 16:53
* ```
*
* @example
* 2. using with `sx` prop:
* ```jsx
* <Box sx={theme => [
Copy link
Member Author

@DiegoAndai DiegoAndai Dec 5, 2024

Choose a reason for hiding this comment

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

This doesn't work, sx prop doesn't accept (theme) => array as styled does.

@DiegoAndai DiegoAndai force-pushed the improve-applystyles-docs branch from bb63799 to 557a511 Compare December 5, 2024 17:18
@DiegoAndai DiegoAndai changed the title [docs][material-ui] Improve applyStyles docs [docs][material-ui] Improve theme.applyStyles() docs Dec 5, 2024
@@ -229,18 +229,29 @@ import Button from '@mui/material/Button';
</Button>;
```

### Codemod
Copy link
Member Author

Choose a reason for hiding this comment

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

This section wasn't removed, it was just moved below

DiegoAndai and others added 2 commits December 20, 2024 14:37
Co-authored-by: Sycamore <71297412+samuelsycamore@users.noreply.github.com>
Signed-off-by: Diego Andai <diego@mui.com>
@DiegoAndai DiegoAndai merged commit 4ffeaeb into mui:master Dec 20, 2024
22 checks passed
@DiegoAndai
Copy link
Member Author

We discussed @siriwatknp's review directly, and I applied the agreed changes.

@DiegoAndai DiegoAndai deleted the improve-applystyles-docs branch December 20, 2024 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features docs Improvements or additions to the documentation package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[docs][system] Sx and Styled can't override applyStyles css
4 participants