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

Commit f776bf7

Browse files
xyngjosephperrott
authored andcommitted
feat(theming): add ability to specify hues as options to defineTheme (#11428)
1 parent 8aaa37a commit f776bf7

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

src/core/services/theming/theming.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
574574
* @description
575575
* Service that makes an element apply theming related <b>classes</b> to itself.
576576
*
577+
* For more information on the hue objects, their default values, as well as valid hue values, please visit <a ng-href="Theming/03_configuring_a_theme#specifying-custom-hues-for-color-intentions">the custom hues section of Configuring a Theme</a>.
578+
*
577579
* <hljs lang="js">
578580
* // Example component directive that we want to apply theming classes to.
579581
* app.directive('myFancyDirective', function($mdTheming) {
@@ -585,7 +587,27 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
585587
*
586588
* $mdTheming.defineTheme('myTheme', {
587589
* primary: 'blue',
590+
* primaryHues: {
591+
* default: '500',
592+
* hue-1: '300',
593+
* hue-2: '900',
594+
* hue-3: 'A100'
595+
* },
588596
* accent: 'pink',
597+
* accentHues: {
598+
* default: '600',
599+
* hue-1: '300',
600+
* hue-2: '200',
601+
* hue-3: 'A500'
602+
* },
603+
* warn: 'red',
604+
* // It's not necessary to specify all hues in the object.
605+
* warnHues: {
606+
* default: '200',
607+
* hue-3: 'A100'
608+
* },
609+
* // It's not necessary to specify custom hues at all.
610+
* background: 'grey',
589611
* dark: true
590612
* });
591613
* // Your directive's custom code here.
@@ -670,9 +692,13 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
670692
* @param {object} options Theme definition options
671693
* Options are:<br/>
672694
* - `primary` - `{string}`: The name of the primary palette to use in the theme.<br/>
695+
* - `primaryHues` - `{object=}`: Override hues for primary palette.<br/>
673696
* - `accent` - `{string}`: The name of the accent palette to use in the theme.<br/>
697+
* - `accentHues` - `{object=}`: Override hues for accent palette.<br/>
674698
* - `warn` - `{string}`: The name of the warn palette to use in the theme.<br/>
699+
* - `warnHues` - `{object=}`: Override hues for warn palette.<br/>
675700
* - `background` - `{string}`: The name of the background palette to use in the theme.<br/>
701+
* - `backgroundHues` - `{object=}`: Override hues for background palette.<br/>
676702
* - `dark` - `{boolean}`: Indicates if it's a dark theme.<br/>
677703
* @returns {Promise<string>} A resolved promise with the new theme name.
678704
*/
@@ -711,16 +737,16 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
711737
var theme = registerTheme(name);
712738

713739
if (options.primary) {
714-
theme.primaryPalette(options.primary);
740+
theme.primaryPalette(options.primary, options.primaryHues);
715741
}
716742
if (options.accent) {
717-
theme.accentPalette(options.accent);
743+
theme.accentPalette(options.accent, options.accentHues);
718744
}
719745
if (options.warn) {
720-
theme.warnPalette(options.warn);
746+
theme.warnPalette(options.warn, options.warnHues);
721747
}
722748
if (options.background) {
723-
theme.backgroundPalette(options.background);
749+
theme.backgroundPalette(options.background, options.backgroundHues);
724750
}
725751
if (options.dark){
726752
theme.dark();

src/core/services/theming/theming.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,35 @@ describe('$mdTheming service', function() {
760760
expect($mdTheming.THEMES.hasOwnProperty('test')).toBeTruthy();
761761
}));
762762

763+
it('supports setting palette options when registering theme on the fly', inject(function ($mdTheming) {
764+
expect($mdTheming.THEMES.hasOwnProperty('testHues')).toBeFalsy();
765+
766+
$mdTheming.defineTheme('testHues', {
767+
primary: 'red',
768+
primaryHues: {
769+
default: '300'
770+
},
771+
accent: 'blue',
772+
accentHues: {
773+
default: '600'
774+
},
775+
warn: 'yellow',
776+
warnHues: {
777+
default: '200'
778+
},
779+
background: 'amber',
780+
backgroundHues: {
781+
default: '800'
782+
},
783+
});
784+
785+
expect($mdTheming.THEMES.hasOwnProperty('testHues')).toBeTruthy();
786+
expect($mdTheming.THEMES.testHues.colors.primary.hues.default).toBe('300');
787+
expect($mdTheming.THEMES.testHues.colors.accent.hues.default).toBe('600');
788+
expect($mdTheming.THEMES.testHues.colors.warn.hues.default).toBe('200');
789+
expect($mdTheming.THEMES.testHues.colors.background.hues.default).toBe('800');
790+
}));
791+
763792
it('supports changing browser color on the fly', function() {
764793
var name = 'theme-color';
765794
var primaryPalette = $mdThemingProvider._THEMES.default.colors.primary.name;

0 commit comments

Comments
 (0)