@@ -119,42 +119,7 @@ function detectDisabledThemes($mdThemingProvider) {
119
119
*/
120
120
121
121
/**
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
158
123
* =======================================
159
124
*
160
125
* Intention group expansion: (valid for primary, accent, warn, background)
@@ -175,7 +140,6 @@ function detectDisabledThemes($mdThemingProvider) {
175
140
* {{foreground-2}} - used for secondary text/divider
176
141
* {{foreground-3}} - used for disabled text
177
142
* {{foreground-4}} - used for dividers
178
- *
179
143
*/
180
144
181
145
// In memory generated CSS rules; registered by theme.name
@@ -279,7 +243,7 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
279
243
/**
280
244
* Adds `theme-color` and `msapplication-navbutton-color` meta tags with the color parameter
281
245
* @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
283
247
*/
284
248
var setBrowserColor = function ( color ) {
285
249
// Chrome, Firefox OS and Opera
@@ -294,20 +258,18 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
294
258
} ;
295
259
296
260
/**
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.
311
273
*/
312
274
var enableBrowserColor = function ( options ) {
313
275
options = angular . isObject ( options ) ? options : { } ;
@@ -340,18 +302,33 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
340
302
} ,
341
303
342
304
/**
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`.
346
312
*/
347
313
disableTheming : function ( isDisabled ) {
348
314
themeConfig . disableTheming = angular . isUndefined ( isDisabled ) || ! ! isDisabled ;
349
315
} ,
350
316
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
+ */
351
322
registerStyles : function ( styles ) {
352
323
themeConfig . registeredStyles . push ( styles ) ;
353
324
} ,
354
325
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
+ */
355
332
setNonce : function ( nonceValue ) {
356
333
themeConfig . nonce = nonceValue ;
357
334
} ,
@@ -360,10 +337,21 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
360
337
themeConfig . generateOnDemand = onDemand ;
361
338
} ,
362
339
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
+ */
363
345
setDefaultTheme : function ( theme ) {
364
346
defaultTheme = theme ;
365
347
} ,
366
348
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
+ */
367
355
alwaysWatchTheme : function ( alwaysWatch ) {
368
356
alwaysWatchTheme = alwaysWatch ;
369
357
} ,
@@ -379,16 +367,71 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
379
367
_rgba : rgba
380
368
} ;
381
369
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
+ */
383
399
function definePalette ( name , map ) {
384
400
map = map || { } ;
385
401
PALETTES [ name ] = checkPaletteValid ( name , map ) ;
386
402
return themingProvider ;
387
403
}
388
404
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
+ */
392
435
function extendPalette ( name , map ) {
393
436
return checkPaletteValid ( name , angular . extend ( { } , PALETTES [ name ] || { } , map ) ) ;
394
437
}
@@ -407,10 +450,16 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
407
450
return map ;
408
451
}
409
452
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
+ */
414
463
function registerTheme ( name , inheritFrom ) {
415
464
if ( THEMES [ name ] ) return THEMES [ name ] ;
416
465
@@ -522,44 +571,45 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
522
571
* @ngdoc service
523
572
* @name $mdTheming
524
573
* @module material.core.theming
525
- *
526
574
* @description
527
- *
528
575
* Service that makes an element apply theming related <b>classes</b> to itself.
529
576
*
530
577
* <hljs lang="js">
578
+ * // Example component directive that we want to apply theming classes to.
531
579
* app.directive('myFancyDirective', function($mdTheming) {
532
580
* 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);
536
585
*
537
586
* $mdTheming.defineTheme('myTheme', {
538
587
* primary: 'blue',
539
588
* accent: 'pink',
540
589
* dark: true
541
- * })
590
+ * });
591
+ * // Your directive's custom code here.
542
592
* }
543
593
* };
544
594
* });
545
595
* </hljs>
546
- * @param {element= } element to apply theming to
596
+ * @param {element= } element Element that will have theming classes applied to it.
547
597
*/
548
598
549
599
/**
550
600
* @ngdoc property
551
601
* @name $mdTheming#THEMES
552
602
* @description
553
603
* 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.
555
605
*/
556
606
557
607
/**
558
608
* @ngdoc property
559
609
* @name $mdTheming#PALETTES
560
610
* @description
561
611
* 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.
563
613
*/
564
614
565
615
/**
@@ -596,48 +646,42 @@ function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
596
646
* @ngdoc method
597
647
* @name $mdTheming#setBrowserColor
598
648
* @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.
613
658
*/
614
659
615
660
/**
616
661
* @ngdoc method
617
662
* @name $mdTheming#defineTheme
618
663
* @description
619
- * Dynamically define a theme by an options object
664
+ * Dynamically define a theme by using an options object that contains palette names.
620
665
*
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.
631
675
*/
632
676
633
677
/* @ngInject */
634
678
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.
636
680
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
+ } ;
641
685
642
686
Object . defineProperty ( applyTheme , 'THEMES' , {
643
687
get : function ( ) {
0 commit comments