You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/data/material/components/buttons/buttons-pt.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ Note that the documentation [avoids](/material-ui/guides/api/#native-properties)
71
71
72
72
{{"demo": "ColorButtons.js"}}
73
73
74
-
Além de usar as cores de botão padrão, você pode adicionar outras personalizadas ou desativar as que não forem necessárias. See the [Adding new colors](/material-ui/customization/palette/#adding-new-colors)example for more info.
74
+
Além de usar as cores de botão padrão, você pode adicionar outras personalizadas ou desativar as que não forem necessárias. See the [Adding new colors](/material-ui/customization/palette/#custom-colors)examples for more info.
Copy file name to clipboardexpand all lines: docs/data/material/components/buttons/buttons.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ Note that the documentation [avoids](/material-ui/guides/api/#native-properties)
77
77
78
78
{{"demo": "ColorButtons.js"}}
79
79
80
-
In addition to using the default button colors, you can add custom ones, or disable any you don't need. See the [Adding new colors](/material-ui/customization/palette/#adding-new-colors)example for more info.
80
+
In addition to using the default button colors, you can add custom ones, or disable any you don't need. See the [Adding new colors](/material-ui/customization/palette/#custom-colors)examples for more info.
Copy file name to clipboardexpand all lines: docs/data/material/customization/palette/palette.md
+133-140
Original file line number
Diff line number
Diff line change
@@ -2,29 +2,51 @@
2
2
3
3
<pclass="description">The palette enables you to modify the color of the components to suit your brand.</p>
4
4
5
-
## Palette colors
5
+
## Color tokens
6
6
7
-
The theme exposes the following palette colors (accessible under `theme.palette.`):
7
+
Palette colors are represented by four tokens:
8
8
9
-
-_primary_ - used to represent primary interface elements for a user. It's the color displayed most frequently across your app's screens and components.
10
-
-_secondary_ - used to represent secondary interface elements for a user. It provides more ways to accent and distinguish your product. Having it is optional.
11
-
-_error_ - used to represent interface elements that the user should be made aware of.
12
-
-_warning_ - used to represent potentially dangerous actions or important messages.
13
-
-_info_ - used to present information to the user that is neutral and not necessarily important.
14
-
-_success_ - used to indicate the successful completion of an action that user triggered.
9
+
-`main`: The main shade of the color
10
+
-`light`: A lighter shade of `main`
11
+
-`dark`: A darker shade of `main`
12
+
-`contrastText`: Text color, intended to contrast with `main`
15
13
16
-
If you want to learn more about color, you can check out [the color section](/material-ui/customization/color/).
14
+
Here's how Material UI's default theme defines the primary color tokens:
17
15
18
-
## Default values
16
+
```js
17
+
constprimary= {
18
+
main:'#1976d2',
19
+
light:'#42a5f5',
20
+
dark:'#1565c0',
21
+
contrastText:'#fff',
22
+
};
23
+
```
24
+
25
+
See the [Color](/material-ui/customization/color/) documentation for details on the Material Design color system.
26
+
27
+
## Default colors
28
+
29
+
The theme exposes the following default palette colors (accessible under `theme.palette.*`):
30
+
31
+
-`primary` - for primary interface elements.
32
+
-`secondary` - for secondary interface elements.
33
+
-`error` - for elements that the user should be made aware of.
34
+
-`warning` - for potentially dangerous actions or important messages.
35
+
-`info` - for highlighting neutral information.
36
+
-`success` - for indicating the successful completion of an action that the user triggered.
19
37
20
-
You can explore the default values of the palette using [the theme explorer](/material-ui/customization/default-theme/?expand-path=$.palette) or by opening the dev tools console on this page (`window.theme.palette`).
38
+
See Material Design's [Color System](https://m2.material.io/design/color/the-color-system.html) for details on color usage and guidelines.
39
+
40
+
### Values
41
+
42
+
You can explore the default palette values using [the theme explorer](/material-ui/customization/default-theme/?expand-path=$.palette), or by opening the dev tools console on this page (`window.theme.palette`).
The default palette uses the shades prefixed with `A` (`A200`, etc.) for the secondary palette color,
25
47
and the un-prefixed shades for the other palette colors.
26
48
27
-
## Customization
49
+
###Customization
28
50
29
51
You may override the default palette values by including a palette object as part of your theme.
30
52
If any of the:
@@ -38,173 +60,128 @@ If any of the:
38
60
39
61
palette color objects are provided, they will replace the default ones.
40
62
41
-
The palette color value can either be a [color](/material-ui/customization/color/#2014-material-design-color-palettes) object, or an object with one or more of the keys specified by the following TypeScript interface:
63
+
This can be achieved by either using a color object or by providing the colors directly:
42
64
43
-
```ts
44
-
interfacePaletteColor {
45
-
light?:string;
46
-
main:string;
47
-
dark?:string;
48
-
contrastText?:string;
49
-
}
50
-
```
65
+
#### Using a color object
51
66
52
-
### Using a color object
67
+
The most direct way to customize a palette color is to import and apply one or more [color objects](/material-ui/customization/color/#2014-material-design-color-palettes), as shown below:
53
68
54
-
The simplest way to customize a palette color is to import one or more of the provided colors
To modify each color directly, provide an object with one or more of the color tokens.
74
+
Only the `main` token is required; `light`, `dark`, and `contrastText` are optional, and if not provided, then their values are calculated automatically:
67
75
68
-
### Providing the colors directly
76
+
{{"demo": "ManuallyProvidePaletteColor.js" }}
69
77
70
-
If you wish to provide more customized colors, you can either create your own palette color,
71
-
or directly supply colors to some or all of the `theme.palette` keys:
The `contrastText` token is calculated using the `contrastThreshold` value, to maximize the contrast between the background and the text.
75
81
76
-
consttheme=createTheme({
77
-
palette: {
78
-
primary: {
79
-
// light: will be calculated from palette.primary.main,
80
-
main:'#ff4400',
81
-
// dark: will be calculated from palette.primary.main,
82
-
// contrastText: will be calculated to contrast with palette.primary.main
83
-
},
84
-
secondary: {
85
-
light:'#0066ff',
86
-
main:'#0044ff',
87
-
// dark: will be calculated from palette.secondary.main,
88
-
contrastText:'#ffcc00',
89
-
},
90
-
// Provide every color token (light, main, dark, and contrastText) when using
91
-
// custom colors for props in Material UI's components.
92
-
// Then you will be able to use it like this: `<Button color="custom">`
93
-
// (For TypeScript, you need to add module augmentation for the `custom` value)
94
-
custom: {
95
-
light:'#ffa726',
96
-
main:'#f57c00',
97
-
dark:'#ef6c00',
98
-
contrastText:'rgba(0, 0, 0, 0.87)',
99
-
},
100
-
// Used by `getContrastText()` to maximize the contrast between
101
-
// the background and the text.
102
-
contrastThreshold:3,
103
-
// Used by the functions below to shift a color's luminance by approximately
104
-
// two indexes within its tonal palette.
105
-
// E.g., shift from Red 500 to Red 300 or Red 700.
106
-
tonalOffset:0.2,
107
-
},
108
-
});
109
-
```
82
+
A higher contrast threshold value increases the point at which a background color is considered light, and thus given a dark `contrastText`.
83
+
Note that the contrast threshold follows a non-linear curve, and defaults to a value of 3 which indicates a minimum contrast ratio of 3:1.
110
84
111
-
As in the example above, if the palette color contains custom colors using any of the
112
-
"main", "light", "dark" or "contrastText" keys, these map as follows:
85
+
{{"demo": "ContrastThreshold.js" }}
113
86
114
-
- If the "dark" and / or "light" keys are omitted, their value(s) will be calculated from "main",
115
-
according to the "tonalOffset" value.
116
-
- If "contrastText" is omitted, its value will be calculated to contrast with "main",
117
-
according to the "contrastThreshold" value.
87
+
### Tonal offset
118
88
119
-
Both the "tonalOffset" and "contrastThreshold" values may be customized as needed.
120
-
The "tonalOffset" value can either be a number between 0 and 1, which will apply to both light and dark variants, or an object with light and dark variants specified by the following TypeScript type:
89
+
The `light` and `dark` tokens are calculated using the `tonalOffset` value, to shift the `main` color's luminance.
90
+
A higher tonal offset value will make `light` tokens lighter, and `dark` tokens darker.
121
91
122
-
```ts
123
-
typePaletteTonalOffset=
124
-
|number
125
-
| {
126
-
light:number;
127
-
dark:number;
128
-
};
129
-
```
92
+
:::warning
93
+
This only applies when working with custom colors—it won't have any effect on the [default values](#default-values).
94
+
:::
130
95
131
-
A higher value for "tonalOffset" will make calculated values for "light" lighter, and "dark" darker.
132
-
A higher value for "contrastThreshold" increases the point at which a background color is considered
133
-
light, and given a dark "contrastText". Note that "contrastThreshold" follows a non-linear curve, and
134
-
starts with a value of 3 (requiring a minimum contrast ratio of 3:1).
96
+
For example, the tonal offset default value `0.2` shifts the luminance by approximately two indexes, so if the `main` token is `blue[500]`, then the `light` token would be `blue[300]` and `dark` would be `blue[700]`.
135
97
136
-
### Accessibility
98
+
The tonal offset value can be either a number between 0 and 1 (which would apply to both `light` and `dark` tokens) or an object with `light` and `dark` keys specified:
137
99
138
-
To meet the minimum contrast of at least 4.5:1 as defined in [WCAG 2.1 Rule 1.4.3](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html), create a custom theme with `contrastThreshold: 4.5`.
If you need to manipulate colors, `@mui/material/styles` provides [a set of utilities](https://github.com/mui/material-ui/blob/master/packages/mui-material/src/styles/index.d.ts#L52-L67) to help with this.
117
+
The following example uses the `alpha` and `getContrastRatio` utilities to define tokens using opacity:
162
118
163
-
consttheme=createTheme({
164
-
status: {
165
-
danger:'#e53e3e',
166
-
},
167
-
palette: {
168
-
primary: {
169
-
main:'#0971f1',
170
-
darker:'#053e85',
171
-
},
172
-
neutral: {
173
-
main:'#64748B',
174
-
contrastText:'#fff',
175
-
},
176
-
},
177
-
});
119
+
{{"demo": "UsingStylesUtils.js" }}
120
+
121
+
### Generate tokens using augmentColor utility
122
+
123
+
Alternatively, you can generate the `light`, `dark` and `contrastText` tokens using the palette's `augmentColor` utility, which is the same function used for the default palette colors.
124
+
This requires creating the theme in two steps and providing the `main` token on which the other will be based on:
125
+
126
+
{{"demo": "UsingAugmentColor.js" }}
127
+
128
+
The [contrast threshold](#contrast-threshold) and [tonal offset](#tonal-offset) values will apply for the colors defined using this utility.
129
+
130
+
### Using in components
131
+
132
+
After adding a custom color, you will be able to use it in components just like you do with default palette colors:
133
+
134
+
```js
135
+
<Button color="custom">
178
136
```
179
137
180
138
### TypeScript
181
139
182
-
You have to use [module augmentation](/material-ui/guides/typescript/#customization-of-theme) to add new variables to the `Palette` and `PaletteOptions`.
140
+
If you're using TypeScript, then you need to use [module augmentation](/material-ui/guides/typescript/#customization-of-theme) for custom colors.
141
+
142
+
To add a custom color to the palette, you must add it to the `Palette` and `PaletteOptions` interfaces:
183
143
184
144
<!-- tested with packages/mui-material/test/typescript/augmentation/paletteColors.spec.ts -->
185
145
186
146
```ts
187
147
declaremodule'@mui/material/styles' {
188
-
interfaceTheme {
189
-
status: {
190
-
danger:React.CSSProperties['color'];
191
-
};
148
+
interfacePalette {
149
+
custom:Palette['primary'];
192
150
}
193
151
194
-
interfaceThemeOptions {
195
-
status: {
196
-
danger:React.CSSProperties['color'];
197
-
};
152
+
interfacePaletteOptions {
153
+
custom?:PaletteOptions['primary'];
198
154
}
155
+
}
156
+
```
199
157
200
-
interfacePalette {
201
-
neutral:Palette['primary'];
202
-
}
158
+
To use a custom color for the `color` prop of a component, you must add it to the component's `PropsColorOverrides` interface.
159
+
The example below shows how to do this with a Button component:
203
160
204
-
interfacePaletteOptions {
205
-
neutral:PaletteOptions['primary'];
161
+
<!-- tested with packages/mui-material/test/typescript/augmentation/paletteColors.spec.ts -->
162
+
163
+
```ts
164
+
declaremodule'@mui/material/Button' {
165
+
interfaceButtonPropsColorOverrides {
166
+
custom:true;
206
167
}
168
+
}
169
+
```
170
+
171
+
## Adding color tokens
172
+
173
+
To add a new [color token](#color-tokens), include it in the color's object as follows:
207
174
175
+
{{"demo": "AddingColorTokens.js" }}
176
+
177
+
### TypeScript
178
+
179
+
If you're using TypeScript, then you'll need to use [module augmentation](/material-ui/guides/typescript/#customization-of-theme) to add the new color token to the `PaletteColor` and `SimplePaletteColorOptions` interfaces as follows:
180
+
181
+
<!-- tested with packages/mui-material/test/typescript/augmentation/paletteColors.spec.ts -->
To learn how to add colors outside of `theme.palette`, see [Theming—Custom variables](/material-ui/customization/theming/#custom-variables).
198
+
199
+
## Accessibility
200
+
201
+
To meet the minimum contrast of at least 4.5:1 as defined in [WCAG 2.1 Rule 1.4.3](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html), create a custom theme with a [contrast threshold](#contrast-threshold) value of 4.5 as follows:
0 commit comments