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] Add default tokens viewer page #42916

Closed
wants to merge 69 commits into from

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Jul 12, 2024

Blocked by #42839

Similar to Joy UI, I think this is a very useful page for exploring the default CSS theme variables.

screencapture-localhost-3001-material-ui-customization-css-theme-variables-default-tokens-viewer-2024-07-12-17_57_01

@siriwatknp siriwatknp added docs Improvements or additions to the documentation package: material-ui Specific to @mui/material labels Jul 12, 2024
@siriwatknp siriwatknp marked this pull request as draft July 12, 2024 10:56
@mui-bot
Copy link

mui-bot commented Jul 12, 2024

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 15, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 18, 2024
@siriwatknp siriwatknp marked this pull request as ready for review July 18, 2024 13:42
Copy link
Member

@aarongarciah aarongarciah left a comment

Choose a reason for hiding this comment

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

Left some comments.

{{"component": "modules/material-ui/FontTokensViewer.js"}}

:::success
Using font variable is an alternative way to `theme.typography` when you cannot access the theme in Javascript.
Copy link
Member

Choose a reason for hiding this comment

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

Using font variable is an alternative way to theme.typography when you cannot access the theme in Javascript.

This applies to every generated CSS variable, not only typography variables, right? Should we move this info to the top of the file, before the "Colors" section?

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 applies to every generated CSS variable, not only typography variables, right

Yes, you are right.

Should we move this info to the top of the file, before the "Colors" section?

I think I will just remove it since this page is about listing the default variables. It might be better to add link to a different page for learning how to use them.


<p class="description">A preview of the default CSS theme variables for built-in light and dark color schemes</p>

The following tokens are generated when using `CssVarsProvider` in your application.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The following tokens are generated when using `CssVarsProvider` in your application.
The following tokens are generated when using [`CssVarsProvider`](/material-ui/customization/css-theme-variables/overview/).

@@ -0,0 +1,63 @@
# Default tokens viewer

<p class="description">A preview of the default CSS theme variables for built-in light and dark color schemes</p>
Copy link
Member

Choose a reason for hiding this comment

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

Observation: it's always weird to read about light/dark color schemes and then see variables unrelated to color.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point.


</codeblock>

## Shadows and overlays
Copy link
Member

Choose a reason for hiding this comment

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

Why "Shadows and overlays"? Aren't these just "shadows"?


Q: are me missing a section in the docs for this in the Customization > Tokens section?

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Q: are me missing a section in the docs for this in the Customization > Tokens section?

I've been having some trouble customizing the shadows and couldn't find much about it in the docs. The only page I found was under MUI System, which isn't ideal. I agree that we should have a page for it—especially since we have 25 shadow tokens, the least we could do is show them off 😅

cc @samuelsycamore

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to be clear, it's out-of-scope of this PR right?


The demo below is a [Paper](/material-ui/react-paper/) component with different level of elevations in light and dark color schemes:

{{"component": "modules/material-ui/ShadowsOverlaysViewer.js"}}
Copy link
Member

Choose a reason for hiding this comment

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

This section feels a bit weird: in all of the other sections I can see a list of the variables and their default values. I think we should have the list of variables in this section as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it feel inconsistent to me as well. I will switch back to a table-like format.


:::

## Spacing
Copy link
Member

Choose a reason for hiding this comment

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

Even if there's only one variable, maybe this section would benefit from having a codeblock like the other sections so users can quickly scan the variables across all sections consistently.

<TokensTable isCopied={isCopied}>
<thead>
<tr>
<th width="60%">Token</th>
Copy link
Member

Choose a reason for hiding this comment

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

Other tables in the page use "CSS variable", which I think makes more sense.

Suggested change
<th width="60%">Token</th>
<th width="60%">CSS variable</th>

Copy link
Member

Choose a reason for hiding this comment

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

Should we add a short paragraph to explain how to convert JS dot notation to CSS variables? e.g. theme.palette.common.black--mui-palette-common-black.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice!

Comment on lines +39 to +47
```js JS
theme.spacing(1, 2); // var(--mui-spacing) calc(2 * var(--mui-spacing))
```

```css CSS
.some-class {
margin: calc(var(--mui-spacing) * 2);
}
```
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this example is clear. Maybe users expect both snippets to be equivalent, and the first one using the multiple arity version of the function might cause confusion. I'd keep the example to the bare minimum.

@@ -0,0 +1,63 @@
# Default tokens viewer
Copy link
Member

Choose a reason for hiding this comment

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

I'd rename the page from "Default tokens viewer" to "CSS vars viewer" or "Default CSS vars viewer" (or something similar). The former can be more easily confused with the existing "Default theme viewer" page.

Also, a token is not the same as a CSS var. "token" is the concept, something we give a value to and then consume via CSS vars, sx prop, styled callbacks that access the theme, and whatever other consuming method we could have.

Copy link
Contributor

@zanivan zanivan left a comment

Choose a reason for hiding this comment

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

Overall, I like the idea of having these in the docs, and I believe it's a must. I don't know if this is the best approach, though.

I wonder if this information shouldn't be split into more pages, and each token having its own page under CSS Variables menu item, or live under the existing tokens' pages, in a CSS Variables section instead. As a user, I would expect to find the CSS Variables tokens in the Typography page. The way that's in here, the information feels a bit hidden from the users. cc @samuelsycamore @alelthomas


From a UX standpoint, nested scrolling is never a good thing. I'd go with a different design for these, something like Medusa UI does for colors, and be more 'visual' for the other tokens as well.

Leaving some examples:

Screenshot 2024-07-18 at 14 11 36 Screenshot 2024-07-18 at 14 10 35 Screenshot 2024-07-18 at 14 12 15

Should we discuss this structure on Figma and come up with some explorations before a PR?

Using font variable is an alternative way to `theme.typography` when you cannot access the theme in Javascript.
The font variable should be used with the CSS `font` property like this:

```css
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's related to this PR, but this border radius seems off. I think it's currently like this (12px 12px 6px 12px) to be concentric with the outer radius. However, it ends up looking like it could resize, similar to a TextArea component 🤔

Screenshot 2024-07-18 at 13 38 18

@aarongarciah
Copy link
Member

aarongarciah commented Jul 18, 2024

Having thought about this a bit more, I think we should give it some more thought and document the CSS vars closer to where we document the theme/tokens. Having two providers (ThemeProvider and CssVarsProvider), because the CSS vars are not available for every user. Still, I think it's doable if we clearly state that CSS vars are only for CssVarsProvider.

We already have the "Tokens" section (with different subsections: palette, typography, etc.) under "Customization". We can explore documenting the CSS vars in those subsections if we don't want to change much the structure now.

I'd also love to see how "Default theme viewer" could somehow display the corresponding CSS vars for the corresponding tokens. It gets tricky because the default theme shape is different depending on the provider.

TL;DR I think we should think about this a bit more instead of adding a new page.


PS: I think it's important that we don't call CSS vars tokens, so we all have the same mental model:

  • Tokens are defined in the theme: colors, shadows, fonts, etc..
  • Tokens get transformed into CSS vars (an potentially other formats).
  • Tokens can be consumed in the form of CSS vars, through styled, sx, etc.

@siriwatknp
Copy link
Member Author

@aarongarciah @zanivan Thanks for the comment, I totally agree about revisiting the place to move this info to.

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 package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants