@@ -16,8 +16,74 @@ angular.module('material.core.theming', ['material.core.theming.palette'])
16
16
* @module material.core.theming
17
17
*
18
18
* @description Provider to configure the `$mdTheming` service.
19
+ *
20
+ * ### Default Theme
21
+ * The `$mdThemingProvider` uses by default the following theme configuration:
22
+ *
23
+ * - Primary Palette: `Primary`
24
+ * - Accent Palette: `Pink`
25
+ * - Warn Palette: `Deep-Orange`
26
+ * - Background Palette: `Grey`
27
+ *
28
+ * If you don't want to use the `md-theme` directive on the elements itself, you may want to overwrite
29
+ * the default theme.<br/>
30
+ * This can be done by using the following markup.
31
+ *
32
+ * <hljs lang="js">
33
+ * myAppModule.config(function($mdThemingProvider) {
34
+ * $mdThemingProvider
35
+ * .theme('default')
36
+ * .primaryPalette('blue')
37
+ * .accentPalette('teal')
38
+ * .warnPalette('red')
39
+ * .backgroundPalette('grey');
40
+ * });
41
+ * </hljs>
42
+ *
43
+
44
+ * ### Dynamic Themes
45
+ *
46
+ * By default, if you change a theme at runtime, the `$mdTheming` service will not detect those changes.<br/>
47
+ * If you have an application, which changes its theme on runtime, you have to enable theme watching.
48
+ *
49
+ * <hljs lang="js">
50
+ * myAppModule.config(function($mdThemingProvider) {
51
+ * // Enable theme watching.
52
+ * $mdThemingProvider.alwaysWatchTheme(true);
53
+ * });
54
+ * </hljs>
55
+ *
56
+ * ### Custom Theme Styles
57
+ *
58
+ * Sometimes you may want to use your own theme styles for some custom components.<br/>
59
+ * You are able to register your own styles by using the following markup.
60
+ *
61
+ * <hljs lang="js">
62
+ * myAppModule.config(function($mdThemingProvider) {
63
+ * // Register our custom stylesheet into the theming provider.
64
+ * $mdThemingProvider.registerStyles(STYLESHEET);
65
+ * });
66
+ * </hljs>
67
+ *
68
+ * The `registerStyles` method only accepts strings as value, so you're actually not able to load an external
69
+ * stylesheet file into the `$mdThemingProvider`.
70
+ *
71
+ * If it's necessary to load an external stylesheet, we suggest using a bundler, which supports including raw content,
72
+ * like [raw-loader](https://github.com/webpack/raw-loader) for `webpack`.
73
+ *
74
+ * <hljs lang="js">
75
+ * myAppModule.config(function($mdThemingProvider) {
76
+ * // Register your custom stylesheet into the theming provider.
77
+ * $mdThemingProvider.registerStyles(require('../styles/my-component.theme.css'));
78
+ * });
79
+ * </hljs>
19
80
*/
20
81
82
+ /**
83
+ * @ngdoc method
84
+ * @name $mdThemingProvider#registerStyles
85
+ * @param {string } styles The styles to be appended to Angular Material's built in theme css.
86
+ */
21
87
/**
22
88
* @ngdoc method
23
89
* @name $mdThemingProvider#setNonce
@@ -143,6 +209,9 @@ var generateOnDemand = false;
143
209
var nonce = null ;
144
210
var disableTheming = false ;
145
211
212
+ // Custom styles registered to be used in the theming of custom components.
213
+ var registeredStyles = [ ] ;
214
+
146
215
function ThemingProvider ( $mdColorPalette ) {
147
216
PALETTES = { } ;
148
217
var THEMES = { } ;
@@ -170,18 +239,26 @@ function ThemingProvider($mdColorPalette) {
170
239
disableTheming = true ;
171
240
} ,
172
241
242
+ registerStyles : function ( styles ) {
243
+ registeredStyles . push ( styles ) ;
244
+ } ,
245
+
173
246
setNonce : function ( nonceValue ) {
174
247
nonce = nonceValue ;
175
248
} ,
249
+
176
250
setDefaultTheme : function ( theme ) {
177
251
defaultTheme = theme ;
178
252
} ,
253
+
179
254
alwaysWatchTheme : function ( alwaysWatch ) {
180
255
alwaysWatchTheme = alwaysWatch ;
181
256
} ,
257
+
182
258
generateThemesOnDemand : function ( onDemand ) {
183
259
generateOnDemand = onDemand ;
184
260
} ,
261
+
185
262
$get : ThemingService ,
186
263
_LIGHT_DEFAULT_HUES : LIGHT_DEFAULT_HUES ,
187
264
_DARK_DEFAULT_HUES : DARK_DEFAULT_HUES ,
@@ -530,6 +607,8 @@ function generateAllThemes($injector, $mdTheming) {
530
607
var head = document . head ;
531
608
var firstChild = head ? head . firstElementChild : null ;
532
609
var themeCss = ! disableTheming && $injector . has ( '$MD_THEME_CSS' ) ? $injector . get ( '$MD_THEME_CSS' ) : '' ;
610
+ // Append our custom registered styles to the theme stylesheet.
611
+ themeCss += registeredStyles . join ( '' ) ;
533
612
534
613
if ( ! firstChild ) return ;
535
614
if ( themeCss . length === 0 ) return ; // no rules, so no point in running this expensive task
0 commit comments