Replies: 2 comments 1 reply
-
First step, these boxes should use their corresponding background container token ( .box {
background: var(--md-sys-color-tertiary-container);
color: var(--md-sys-color-on-tertiary-container);
}
A tertiary container's foreground color content is
Check out our "How do I change the color of a button?" FAQ. The tl;dr is to map the component's key tone colors to another system key tone color. Buttons use the primary key tone, so we can map this to appropriate system colors for a tertiary container. .tertiary .button {
/* Remap the "primary" tokens to "on-tertiary-container" */
--md-sys-color-primary: var(--md-sys-color-on-tertiary-container);
/* The opposite of "on-tertiary-container" is "tertiary-container" */
--md-sys-color-on-primary: var(--md-sys-color-tertiary-container);
} Example playground: https://lit.dev/playground/#gist=3530adee2c9f86629000644f547a46fa
When you set component tokens instead of system tokens, yes, you need to set each state. We generally recommend changing the system token mapping rather than individual component tokens because of this. In some spots (like shape), we don't have system tokens so component tokens must be used. There are other use cases for component tokens too, such as re-mapping what system tokens they use by default. For example, changing all buttons to use the "secondary" color by default. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
For context, here are a few button types on different backgrounds:
Light mode:
Dark mode:
More context:
This is an app I am building, and I have noticed that this is the default way that various buttons look on different surfaces. The purple box is coloured tertiary, so I would like to be able to set some variable on the buttons to make them re-colour themselves for that type of surface.
I see the variables I have to set (eg: https://github.com/material-components/material-web/blob/main/tokens/_md-comp-outlined-button.scss) but I also see
label-text-color
andpressed-label-text-color
etc, and I'm wondering the following:Beta Was this translation helpful? Give feedback.
All reactions