Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 7157b3b

Browse files
committed
docs(theming): update Defining Custom Palettes guide w/ new contrast settings
- change docs app's warn theme 500 value to 700 value to make flat warn buttons pass contrast checks - revert docs-red palette defaulting to `A700` since that breaks hover and focus styles - remove the override of the `.demo-toolbar` color since it is no longer needed after the toolbar contrast fixes
1 parent 4e3f7a7 commit 7157b3b

File tree

3 files changed

+60
-17
lines changed

3 files changed

+60
-17
lines changed

docs/app/css/style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ md-tabs.demo-source-tabs .active md-tab-label {
554554
md-toolbar.demo-toolbar {
555555
border-radius: 3px 3px 0 0;
556556
box-shadow: 0 1px rgba(255, 255, 255, 0.1);
557-
color: white;
558557
}
559558
md-toolbar.demo-toolbar md-tab-label {
560559
color: #99E4EE;

docs/app/js/app.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,15 @@ function(SERVICES, COMPONENTS, DEMOS, PAGES,
5454
'contrastDarkColors': '50 100 200 300 400 A100 A200',
5555
'contrastStrongLightColors': '500 600 700 800 900 A400 A700'
5656
}));
57+
5758
$mdThemingProvider.definePalette('docs-red', $mdThemingProvider.extendPalette('red', {
5859
'A100': '#DE3641'
5960
}));
6061

62+
$mdThemingProvider.definePalette('docs-warn', $mdThemingProvider.extendPalette('deep-orange', {
63+
'500': '#d32f2f' // Override 500 with 700 hue for improved contrast on flat buttons
64+
}));
65+
6166
$mdThemingProvider.theme('docs-dark', 'default')
6267
.primaryPalette('yellow')
6368
.dark();
@@ -77,9 +82,8 @@ function(SERVICES, COMPONENTS, DEMOS, PAGES,
7782

7883
$mdThemingProvider.theme('default')
7984
.primaryPalette('docs-blue')
80-
.accentPalette('docs-red', {
81-
'default': 'A700'
82-
});
85+
.accentPalette('docs-red')
86+
.warnPalette('docs-warn');
8387

8488
$mdThemingProvider.enableBrowserColor();
8589

docs/content/Theming/03_configuring_a_theme.md

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Configuring a theme
66

7-
By default your AngularJS Material application will use the default theme, a theme
7+
By default, your AngularJS Material application will use the default theme, a theme
88
that is pre-configured with the following palettes for intention groups:
99

1010
- *primary* - indigo
@@ -72,16 +72,24 @@ angular.module('myApp', ['ngMaterial'])
7272

7373
### Defining Custom Palettes
7474

75-
As mentioned before, AngularJS Material ships with the Material Design
76-
Spec's color palettes built in. In the event that you need to define a custom color palette, you can use `$mdThemingProvider` to define it, thereby making
77-
it available to your theme for use in its intention groups. Note that you must
78-
specify all hues in the definition map.
75+
As mentioned before, AngularJS Material ships with the Material Design Spec's color palettes built
76+
in. In the event that you need to define a custom color palette, you can use `$mdThemingProvider`
77+
to define it. This makes the palette available to your theme for use in its intention groups.
78+
Note that you must specify all hues in the definition map. If you only want to override a few hues,
79+
please extend a palette (above).
80+
81+
For a dark colored, custom palette, you should specify the default contrast color as `light`.
82+
For lighter hues in the palette, you may need to add them to the list of `contrastDarkColors` to
83+
meet contrast guidelines. Similarly, you may need to add darker hues to `contrastStrongLightColors`,
84+
which has been updated to the latest Material Design guidelines for
85+
[Color Usability](https://material.io/archive/guidelines/style/color.html#color-usability).
86+
The update to the guidelines changed primary text on dark backgrounds from 87% to 100% opacity.
7987

8088
<hljs lang="js">
8189
angular.module('myApp', ['ngMaterial'])
8290
.config(function($mdThemingProvider) {
8391

84-
$mdThemingProvider.definePalette('amazingPaletteName', {
92+
$mdThemingProvider.definePalette('amazingDarkPaletteName', {
8593
'50': 'ffebee',
8694
'100': 'ffcdd2',
8795
'200': 'ef9a9a',
@@ -96,17 +104,49 @@ angular.module('myApp', ['ngMaterial'])
96104
'A200': 'ff5252',
97105
'A400': 'ff1744',
98106
'A700': 'd50000',
99-
'contrastDefaultColor': 'light', // whether, by default, text (contrast)
100-
// on this palette should be dark or light
101-
102-
'contrastDarkColors': ['50', '100', //hues which contrast should be 'dark' by default
103-
'200', '300', '400', 'A100'],
104-
'contrastLightColors': undefined // could also specify this if default was 'dark'
107+
// By default, text (contrast) on this palette should be white with 87% opacity.
108+
'contrastDefaultColor': 'light',
109+
// By default, for these lighter hues, text (contrast) should be 'dark'.
110+
'contrastDarkColors': '50 100 200 300 400 500 600 A100 A200 A400',
111+
// By default, for these darker hues, text (contrast) should be white with 100% opacity.
112+
'contrastStrongLightColors': '700 800 900 A700'
105113
});
106114

107115
$mdThemingProvider.theme('default')
108-
.primaryPalette('amazingPaletteName')
116+
.primaryPalette('amazingDarkPaletteName')
117+
});
118+
</hljs>
119+
120+
For a light colored, custom palette, you should specify the default contrast color as `dark`.
121+
Then `contrastStrongLightColors` can be used if any hues are too dark for dark text.
122+
123+
<hljs lang="js">
124+
angular.module('myApp', ['ngMaterial'])
125+
.config(function($mdThemingProvider) {
109126

127+
$mdThemingProvider.definePalette('amazingLightPaletteName', {
128+
'50': '#f1f8e9',
129+
'100': '#dcedc8',
130+
'200': '#c5e1a5',
131+
'300': '#aed581',
132+
'400': '#9ccc65',
133+
'500': '#8bc34a',
134+
'600': '#7cb342',
135+
'700': '#689f38',
136+
'800': '#558b2f',
137+
'900': '#33691e',
138+
'A100': '#ccff90',
139+
'A200': '#b2ff59',
140+
'A400': '#76ff03',
141+
'A700': '#64dd17',
142+
// By default, text (contrast) on this palette should be dark with 87% opacity.
143+
'contrastDefaultColor': 'dark',
144+
// By default, for these darker hues, text (contrast) should be white with 100% opacity.
145+
'contrastStrongLightColors': '800 900'
146+
});
147+
148+
$mdThemingProvider.theme('default')
149+
.accentPalette('amazingLightPaletteName')
110150
});
111151
</hljs>
112152

0 commit comments

Comments
 (0)