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

Commit 40e1f2d

Browse files
Splaktarjelbourn
authored andcommitted
docs(mdThemingProvider): add missing documentation (#11209)
the APIs were covered some in the guide, but not in the service docs update existing docs for consistency Relates to #2965. Relates to #9475. Relates to #9476. Relates to #10458. Relates to #10458.
1 parent 5320d22 commit 40e1f2d

File tree

1 file changed

+146
-102
lines changed

1 file changed

+146
-102
lines changed

src/core/services/theming/theming.js

Lines changed: 146 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -119,42 +119,7 @@ function detectDisabledThemes($mdThemingProvider) {
119119
*/
120120

121121
/**
122-
* @ngdoc method
123-
* @name $mdThemingProvider#registerStyles
124-
* @param {string} styles The styles to be appended to AngularJS Material's built in theme css.
125-
*/
126-
/**
127-
* @ngdoc method
128-
* @name $mdThemingProvider#setNonce
129-
* @param {string} nonceValue The nonce to be added as an attribute to the theme style tags.
130-
* Setting a value allows the use of CSP policy without using the unsafe-inline directive.
131-
*/
132-
133-
/**
134-
* @ngdoc method
135-
* @name $mdThemingProvider#setDefaultTheme
136-
* @param {string} themeName Default theme name to be applied to elements. Default value is `default`.
137-
*/
138-
139-
/**
140-
* @ngdoc method
141-
* @name $mdThemingProvider#alwaysWatchTheme
142-
* @param {boolean} watch Whether or not to always watch themes for changes and re-apply
143-
* classes when they change. Default is `false`. Enabling can reduce performance.
144-
*/
145-
146-
/**
147-
* @ngdoc method
148-
* @name $mdThemingProvider#enableBrowserColor
149-
* @param {Object=} options Options object for the browser color<br/>
150-
* `theme` - A defined theme via `$mdThemeProvider` to use the palettes from. Default is `default` theme. <br/>
151-
* `palette` - Can be any one of the basic material design palettes, extended defined palettes and 'primary',
152-
* 'accent', 'background' and 'warn'. Default is `primary`. <br/>
153-
* `hue` - The hue from the selected palette. Default is `800`<br/>
154-
* @returns {Function} remove function of the browser color
155-
*/
156-
157-
/* Some Example Valid Theming Expressions
122+
* Some Example Valid Theming Expressions
158123
* =======================================
159124
*
160125
* Intention group expansion: (valid for primary, accent, warn, background)
@@ -175,7 +140,6 @@ function detectDisabledThemes($mdThemingProvider) {
175140
* {{foreground-2}} - used for secondary text/divider
176141
* {{foreground-3}} - used for disabled text
177142
* {{foreground-4}} - used for dividers
178-
*
179143
*/
180144

181145
// In memory generated CSS rules; registered by theme.name
@@ -279,7 +243,7 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
279243
/**
280244
* Adds `theme-color` and `msapplication-navbutton-color` meta tags with the color parameter
281245
* @param {string} color Hex value of the wanted browser color
282-
* @returns {Function} Remove function of the meta tags
246+
* @returns {function} Remove function of the meta tags
283247
*/
284248
var setBrowserColor = function (color) {
285249
// Chrome, Firefox OS and Opera
@@ -294,20 +258,18 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
294258
};
295259

296260
/**
297-
* Enables browser header coloring
298-
* for more info please visit:
299-
* https://developers.google.com/web/fundamentals/design-and-ui/browser-customization/theme-color
300-
*
301-
* The default color is `800` from `primary` palette of the `default` theme
302-
*
303-
* options are:
304-
* `theme` - A defined theme via `$mdThemeProvider` to use the palettes from. Default is `default` theme
305-
* `palette` - Can be any one of the basic material design palettes, extended defined palettes and 'primary',
306-
* 'accent', 'background' and 'warn'. Default is `primary`
307-
* `hue` - The hue from the selected palette. Default is `800`
308-
*
309-
* @param {Object=} options Options object for the browser color
310-
* @returns {Function} remove function of the browser color
261+
* @ngdoc method
262+
* @name $mdThemingProvider#enableBrowserColor
263+
* @description
264+
* Enables browser header coloring. For more info please visit
265+
* <a href="https://developers.google.com/web/fundamentals/design-and-ui/browser-customization/theme-color">
266+
* Web Fundamentals</a>.
267+
* @param {object=} options Options for the browser color, which include:<br/>
268+
* - `theme` - `{string}`: A defined theme via `$mdThemeProvider` to use the palettes from. Default is `default` theme. <br/>
269+
* - `palette` - `{string}`: Can be any one of the basic material design palettes, extended defined palettes, or `primary`,
270+
* `accent`, `background`, and `warn`. Default is `primary`.<br/>
271+
* - `hue` - `{string}`: The hue from the selected palette. Default is `800`.<br/>
272+
* @returns {function} Function that removes the browser coloring when called.
311273
*/
312274
var enableBrowserColor = function (options) {
313275
options = angular.isObject(options) ? options : {};
@@ -340,18 +302,33 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
340302
},
341303

342304
/**
343-
* Easy way to disable theming without having to use
344-
* `.constant("$MD_THEME_CSS","");` This disables
345-
* all dynamic theme style sheet generations and injections...
305+
* @ngdoc method
306+
* @name $mdThemingProvider#disableTheming
307+
* @description
308+
* An easier way to disable theming without having to use `.constant("$MD_THEME_CSS","");`.
309+
* This disables all dynamic theme style sheet generations and injections.
310+
* @param {boolean=} isDisabled Disable all dynamic theme style sheet generations and injections
311+
* if `true` or `undefined`.
346312
*/
347313
disableTheming: function(isDisabled) {
348314
themeConfig.disableTheming = angular.isUndefined(isDisabled) || !!isDisabled;
349315
},
350316

317+
/**
318+
* @ngdoc method
319+
* @name $mdThemingProvider#registerStyles
320+
* @param {string} styles The styles to be appended to AngularJS Material's built in theme CSS.
321+
*/
351322
registerStyles: function(styles) {
352323
themeConfig.registeredStyles.push(styles);
353324
},
354325

326+
/**
327+
* @ngdoc method
328+
* @name $mdThemingProvider#setNonce
329+
* @param {string} nonceValue The nonce to be added as an attribute to the theme style tags.
330+
* Setting a value allows the use of CSP policy without using the unsafe-inline directive.
331+
*/
355332
setNonce: function(nonceValue) {
356333
themeConfig.nonce = nonceValue;
357334
},
@@ -360,10 +337,21 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
360337
themeConfig.generateOnDemand = onDemand;
361338
},
362339

340+
/**
341+
* @ngdoc method
342+
* @name $mdThemingProvider#setDefaultTheme
343+
* @param {string} theme Default theme name to be applied to elements. Default value is `default`.
344+
*/
363345
setDefaultTheme: function(theme) {
364346
defaultTheme = theme;
365347
},
366348

349+
/**
350+
* @ngdoc method
351+
* @name $mdThemingProvider#alwaysWatchTheme
352+
* @param {boolean} alwaysWatch Whether or not to always watch themes for changes and re-apply
353+
* classes when they change. Default is `false`. Enabling can reduce performance.
354+
*/
367355
alwaysWatchTheme: function(alwaysWatch) {
368356
alwaysWatchTheme = alwaysWatch;
369357
},
@@ -379,16 +367,71 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
379367
_rgba: rgba
380368
};
381369

382-
// Example: $mdThemingProvider.definePalette('neonRed', { 50: '#f5fafa', ... });
370+
/**
371+
* @ngdoc method
372+
* @name $mdThemingProvider#definePalette
373+
* @description
374+
* In the event that you need to define a custom color palette, you can use this function to
375+
* make it available to your theme for use in its intention groups.<br>
376+
* Note that you must specify all hues in the definition map.
377+
* @param {string} name Name of palette being defined
378+
* @param {object} map Palette definition that includes hue definitions and contrast colors:
379+
* - `'50'` - `{string}`: HEX color
380+
* - `'100'` - `{string}`: HEX color
381+
* - `'200'` - `{string}`: HEX color
382+
* - `'300'` - `{string}`: HEX color
383+
* - `'400'` - `{string}`: HEX color
384+
* - `'500'` - `{string}`: HEX color
385+
* - `'600'` - `{string}`: HEX color
386+
* - `'700'` - `{string}`: HEX color
387+
* - `'800'` - `{string}`: HEX color
388+
* - `'900'` - `{string}`: HEX color
389+
* - `'A100'` - `{string}`: HEX color
390+
* - `'A200'` - `{string}`: HEX color
391+
* - `'A400'` - `{string}`: HEX color
392+
* - `'A700'` - `{string}`: HEX color
393+
* - `'contrastDefaultColor'` - `{string}`: `light` or `dark`
394+
* - `'contrastDarkColors'` - `{string[]}`: Hues which should use dark contrast colors (i.e. raised button text).
395+
* For example: `['50', '100', '200', '300', '400', 'A100']`.
396+
* - `'contrastLightColors'` - `{string[]}`: Hues which should use light contrast colors (i.e. raised button text).
397+
* For example: `['500', '600', '700', '800', '900', 'A200', 'A400', 'A700']`.
398+
*/
383399
function definePalette(name, map) {
384400
map = map || {};
385401
PALETTES[name] = checkPaletteValid(name, map);
386402
return themingProvider;
387403
}
388404

389-
// Returns an new object which is a copy of a given palette `name` with variables from
390-
// `map` overwritten
391-
// Example: var neonRedMap = $mdThemingProvider.extendPalette('red', { 50: '#f5fafafa' });
405+
/**
406+
* @ngdoc method
407+
* @name $mdThemingProvider#extendPalette
408+
* @description
409+
* Sometimes it is easier to extend an existing color palette and then change a few properties,
410+
* rather than defining a whole new palette.
411+
* @param {string} name Name of palette being extended
412+
* @param {object} map Palette definition that includes optional hue definitions and contrast colors:
413+
* - `'50'` - `{string}`: HEX color
414+
* - `'100'` - `{string}`: HEX color
415+
* - `'200'` - `{string}`: HEX color
416+
* - `'300'` - `{string}`: HEX color
417+
* - `'400'` - `{string}`: HEX color
418+
* - `'500'` - `{string}`: HEX color
419+
* - `'600'` - `{string}`: HEX color
420+
* - `'700'` - `{string}`: HEX color
421+
* - `'800'` - `{string}`: HEX color
422+
* - `'900'` - `{string}`: HEX color
423+
* - `'A100'` - `{string}`: HEX color
424+
* - `'A200'` - `{string}`: HEX color
425+
* - `'A400'` - `{string}`: HEX color
426+
* - `'A700'` - `{string}`: HEX color
427+
* - `'contrastDefaultColor'` - `{string}`: `light` or `dark`
428+
* - `'contrastDarkColors'` - `{string[]}`: Hues which should use dark contrast colors (i.e. raised button text).
429+
* For example: `['50', '100', '200', '300', '400', 'A100']`.
430+
* - `'contrastLightColors'` - `{string[]}`: Hues which should use light contrast colors (i.e. raised button text).
431+
* For example: `['500', '600', '700', '800', '900', 'A200', 'A400', 'A700']`.
432+
* @returns {object} A new object which is a copy of the given palette, `name`,
433+
* with variables from `map` overwritten.
434+
*/
392435
function extendPalette(name, map) {
393436
return checkPaletteValid(name, angular.extend({}, PALETTES[name] || {}, map) );
394437
}
@@ -407,10 +450,16 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
407450
return map;
408451
}
409452

410-
// Register a theme (which is a collection of color palettes to use with various states
411-
// ie. warn, accent, primary )
412-
// Optionally inherit from an existing theme
413-
// $mdThemingProvider.theme('custom-theme').primaryPalette('red');
453+
/**
454+
* @ngdoc method
455+
* @name $mdThemingProvider#theme
456+
* @description
457+
* Register a theme (which is a collection of color palettes); i.e. `warn`, `accent`,
458+
* `background`, and `primary`.<br>
459+
* Optionally inherit from an existing theme.
460+
* @param {string} name Name of theme being registered
461+
* @param {string=} inheritFrom Existing theme name to inherit from
462+
*/
414463
function registerTheme(name, inheritFrom) {
415464
if (THEMES[name]) return THEMES[name];
416465

@@ -522,44 +571,45 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
522571
* @ngdoc service
523572
* @name $mdTheming
524573
* @module material.core.theming
525-
*
526574
* @description
527-
*
528575
* Service that makes an element apply theming related <b>classes</b> to itself.
529576
*
530577
* <hljs lang="js">
578+
* // Example component directive that we want to apply theming classes to.
531579
* app.directive('myFancyDirective', function($mdTheming) {
532580
* return {
533-
* restrict: 'e',
534-
* link: function(scope, el, attrs) {
535-
* $mdTheming(el);
581+
* restrict: 'AE',
582+
* link: function(scope, element, attrs) {
583+
* // Initialize the service using our directive's element
584+
* $mdTheming(element);
536585
*
537586
* $mdTheming.defineTheme('myTheme', {
538587
* primary: 'blue',
539588
* accent: 'pink',
540589
* dark: true
541-
* })
590+
* });
591+
* // Your directive's custom code here.
542592
* }
543593
* };
544594
* });
545595
* </hljs>
546-
* @param {element=} element to apply theming to
596+
* @param {element=} element Element that will have theming classes applied to it.
547597
*/
548598

549599
/**
550600
* @ngdoc property
551601
* @name $mdTheming#THEMES
552602
* @description
553603
* Property to get all the themes defined
554-
* @returns {Object} All the themes defined with their properties
604+
* @returns {object} All the themes defined with their properties.
555605
*/
556606

557607
/**
558608
* @ngdoc property
559609
* @name $mdTheming#PALETTES
560610
* @description
561611
* Property to get all the palettes defined
562-
* @returns {Object} All the palettes defined with their colors
612+
* @returns {object} All the palettes defined with their colors.
563613
*/
564614

565615
/**
@@ -596,48 +646,42 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
596646
* @ngdoc method
597647
* @name $mdTheming#setBrowserColor
598648
* @description
599-
* Sets browser header coloring
600-
* for more info please visit:
601-
* https://developers.google.com/web/fundamentals/design-and-ui/browser-customization/theme-color
602-
*
603-
* The default color is `800` from `primary` palette of the `default` theme
604-
*
605-
* options are:<br/>
606-
* `theme` - A defined theme via `$mdThemeProvider` to use the palettes from. Default is `default` theme.<br/>
607-
* `palette` - Can be any one of the basic material design palettes, extended defined palettes and 'primary',
608-
* 'accent', 'background' and 'warn'. Default is `primary`<br/>
609-
* `hue` - The hue from the selected palette. Default is `800`
610-
*
611-
* @param {Object} options Options object for the browser color
612-
* @returns {Function} remove function of the browser color
649+
* Enables browser header coloring. For more info please visit
650+
* <a href="https://developers.google.com/web/fundamentals/design-and-ui/browser-customization/theme-color">
651+
* Web Fundamentals</a>.
652+
* @param {object=} options Options for the browser color, which include:<br/>
653+
* - `theme` - `{string}`: A defined theme via `$mdThemeProvider` to use the palettes from. Default is `default` theme. <br/>
654+
* - `palette` - `{string}`: Can be any one of the basic material design palettes, extended defined palettes, or `primary`,
655+
* `accent`, `background`, and `warn`. Default is `primary`.<br/>
656+
* - `hue` - `{string}`: The hue from the selected palette. Default is `800`.<br/>
657+
* @returns {function} Function that removes the browser coloring when called.
613658
*/
614659

615660
/**
616661
* @ngdoc method
617662
* @name $mdTheming#defineTheme
618663
* @description
619-
* Dynamically define a theme by an options object
664+
* Dynamically define a theme by using an options object that contains palette names.
620665
*
621-
* options are:<br/>
622-
* `primary` - The primary palette of the theme.<br/>
623-
* `accent` - The accent palette of the theme.<br/>
624-
* `warn` - The warn palette of the theme.<br/>
625-
* `background` - The background palette of the theme.<br/>
626-
* `dark` - Indicates if it's a dark theme.<br/>
627-
*
628-
* @param {String} name Theme name to define
629-
* @param {Object} options Theme definition options
630-
* @returns {Promise<string>} A resolved promise with the theme name
666+
* @param {string} name Theme name to define
667+
* @param {object} options Theme definition options
668+
* Options are:<br/>
669+
* - `primary` - `{string}`: The name of the primary palette to use in the theme.<br/>
670+
* - `accent` - `{string}`: The name of the accent palette to use in the theme.<br/>
671+
* - `warn` - `{string}`: The name of the warn palette to use in the theme.<br/>
672+
* - `background` - `{string}`: The name of the background palette to use in the theme.<br/>
673+
* - `dark` - `{boolean}`: Indicates if it's a dark theme.<br/>
674+
* @returns {Promise<string>} A resolved promise with the new theme name.
631675
*/
632676

633677
/* @ngInject */
634678
function ThemingService($rootScope, $mdUtil, $q, $log) {
635-
// Allow us to be invoked via a linking function signature.
679+
// Allow us to be invoked via a linking function signature.
636680
var applyTheme = function (scope, el) {
637-
if (el === undefined) { el = scope; scope = undefined; }
638-
if (scope === undefined) { scope = $rootScope; }
639-
applyTheme.inherit(el, el);
640-
};
681+
if (el === undefined) { el = scope; scope = undefined; }
682+
if (scope === undefined) { scope = $rootScope; }
683+
applyTheme.inherit(el, el);
684+
};
641685

642686
Object.defineProperty(applyTheme, 'THEMES', {
643687
get: function () {

0 commit comments

Comments
 (0)