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] Add runtime theme section for Material Pigment CSS #44137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/data/material/experimental-api/pigment-css/pigment-css.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,35 @@
}
}
```

### Runtime theme

:::info

**Caveat**

- Avoid using the runtime theme unless you have a compelling reason.
- The runtime theme contains [**only serializable values**](https://developer.mozilla.org/en-US/docs/Glossary/Serializable_object) (some functions still exist in `breakpoints` and `transitions` for internal logic inside components but may be removed in the future).
- The runtime theme will not change between modes (light and dark) because it is pre-compiled at build time. To render something based on the theme structure and its values, use `theme.vars.*` to refer to CSS variables instead.

Check warning on line 353 in docs/data/material/experimental-api/pigment-css/pigment-css.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.Will] Avoid using 'will'. Raw Output: {"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "docs/data/material/experimental-api/pigment-css/pigment-css.md", "range": {"start": {"line": 353, "column": 21}}}, "severity": "WARNING"}

:::

To access the runtime theme, use the `useTheme` hook:

```js
import { useTheme } from '@mui/material-pigment-css';

function MyComponent() {
const theme = useTheme();

return (
<div>
{Object.entries(theme.vars.palette.primary).map(([key, value]) => (
<div key={key} style={{ width: 40, height: 40, background: value }}>
{key}: {value}
</div>
))}
</div>
);
}
```
Loading