Skip to content

Commit

Permalink
add runtime theme docs
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Oct 17, 2024
1 parent 064fa67 commit 8503bef
Showing 1 changed file with 32 additions and 0 deletions.
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 @@ declare global {
}
}
```

### 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>
);
}
```

0 comments on commit 8503bef

Please sign in to comment.