-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(theming): add ability to specify hues as options to defineTheme #11428
feat(theming): add ability to specify hues as options to defineTheme #11428
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
We signed the cla. Google Group is: https://groups.google.com/forum/#!forum/interweber |
Thank you for making your first contribution to AngularJS Material! @xyng can you please verify that the email address associated with the git commit is a contributor in your Google Group and that it is also attached to your GitHub account. If that all looks good, please respond with "I signed it!". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for submitting this! It's off to a good start. I just had a few comments.
When you update this branch, please make sure to amend your commit (rather than create a new commit) and then force push to your branch. This will allow you to avoid having to squash your commits later.
src/core/services/theming/theming.js
Outdated
@@ -670,9 +670,13 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) { | |||
* @param {object} options Theme definition options | |||
* Options are:<br/> | |||
* - `primary` - `{string}`: The name of the primary palette to use in the theme.<br/> | |||
* - `primaryHues` - `{object} (Optional)`: Overwrite hues for primary palette.<br/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use =
at the end of the type to indicate that it is optional, i.e. {object=}
.
Let's use "Override" instead of "Overwrite".
src/core/services/theming/theming.js
Outdated
* - `warn` - `{string}`: The name of the warn palette to use in the theme.<br/> | ||
* - `warnHues` - `{object}`: Overwrite hues for warn palette.<br/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add an example to the main $mdTheming
docs where these new parameters are used?
Without that, it's not clear here what this object
would consist of.
$mdTheming.defineTheme('test', { | ||
primary: 'red', | ||
primaryHue: 300, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be primaryHues
right? The value should also be an object
?
@@ -752,8 +752,10 @@ describe('$mdTheming service', function() { | |||
it('supports registering theme on the fly', inject(function ($mdTheming) { | |||
expect($mdTheming.THEMES.hasOwnProperty('test')).toBeFalsy(); | |||
|
|||
// optional <color>Hue option for each color, as in normal theme definition. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After you make the other updates, please clarify this comment or remove it.
$mdTheming.defineTheme('test', { | ||
primary: 'red', | ||
primaryHue: 300, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably have a test that verifies that the correct hue was defined/used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have little experience with writing tests. I'll look into it and see what I can do.
e0e9945
to
03d5c1b
Compare
@@ -585,6 +585,9 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) { | |||
* | |||
* $mdTheming.defineTheme('myTheme', { | |||
* primary: 'blue', | |||
* primaryHues: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this doc makes things clear. The setPalette
function seems to have no docs itself.
Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are the default hues that can be overridden and the valid keys in those objects:
Light mode hue defaults
'accent': {
'default': 'A200',
'hue-1': 'A100',
'hue-2': 'A400',
'hue-3': 'A700'
},
'background': {
'default': '50',
'hue-1': 'A100',
'hue-2': '100',
'hue-3': '300'
}
Dark mode hue defaults
'background': {
'default': 'A400',
'hue-1': '800',
'hue-2': '900',
'hue-3': 'A200'
}
Here are the default hue values for any other palette that doesn't specify its hues. We should link to the docs that describe this via ng-href="Theming/03_configuring_a_theme"
{
'default': '500',
'hue-1': '300',
'hue-2': '800',
'hue-3': 'A100'
}
Here are the valid hue values (we should mention these (not list them) and point to the same Configuring a theme doc mentioned above)
'50', '100', '200', '300', '400', '500', '600',
'700', '800', '900', 'A100', 'A200', 'A400', 'A700'
I think that we should give an example that defines all of these hues for each of primary
, accent
, and warn
. We should have one of the examples (perhaps warn
) that only overrides 1 or 2 hues along with a mention about how these hues are optional. Then as mentioned above, we should link to the docs on configuring a theme as part of a brief description about the light/dark mode default hues (accent
and background
) and the default hues for all other palettes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for this thorough information. I really appreciate your feedback.
I tried to implement it as good as possible - though I'm not the best at writing docs.
Sadly, I'm running out of time for this. So if you should have other suggestions regarding documentation I'd like to ask you to make these changes directly, if that is possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it's non-trivial for me to make changes to your PR, but I do think that this is about ready to wrap up. Thank you for your cooperation.
03d5c1b
to
abefd6c
Compare
warn: 'yellow' | ||
}); | ||
|
||
expect($mdTheming.THEMES.hasOwnProperty('test')).toBeTruthy(); | ||
expect($mdTheming.THEMES.test.colors.primary.hues.default).toBe('300'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this should be enough to test the hue overrides. Suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion looks like it will work.
However, it would be helpful if, instead of changing this test, you could add a new test (it(...)
) that was similar but set and verified each of the different xHues
fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a new test case, following your suggestion. I agree that this is a better way of testing it.
Hopefully those comments were helpful. Please don't hesitate to ask for clarification or any other information that you may need. Thank you for your contributions! |
abefd6c
to
50badc2
Compare
CLAs look good, thanks! |
50badc2
to
a14e7f3
Compare
src/core/services/theming/theming.js
Outdated
@@ -574,6 +574,8 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) { | |||
* @description | |||
* Service that makes an element apply theming related <b>classes</b> to itself. | |||
* | |||
* For more Information on the `xHues` 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>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, out of respect for your limited time, I will hold off on some feedback, but I do want to fix one thing in this line.
Can you please change Information on the
xHues objects
to information on the hue objects
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :-)
* extend test of `$mdTheming` to include one palette with and one without hue. * add docs regarding new `paletteHues` option for `defineTheme` method of `$mdTheming`. Fixes angular#10335
a14e7f3
to
21e6268
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
$mdTheming
to include one palette with and one without hue.paletteHues
options fordefineTheme
method of$mdTheming
.Fixes #10335
PR Checklist
Please check that your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently, there is no possibility to apply hue-options to palettes when using
defineTheme
. This is described thoroughly in the following issue and Google Group.https://groups.google.com/forum/#!topic/ngmaterial/d-D3MNFl6wg
Issue Number: #10335
What is the new behavior?
paletteHues
options have been added to the options object. These are completely optional.Does this PR introduce a breaking change?
Other information
I opted to add an option for each palette instead of changing each palette option to be either of type string or object, as that would be more likely to break or be confusing.
However I'm willing to implement it that way if you desire.