1+ var React = require ( 'react' ) ;
2+ var ThemeManager = require ( './styles/theme-manager' ) ;
3+
4+
5+ var Theme = React . createClass ( {
6+
7+ propTypes : {
8+ theme : React . PropTypes . object
9+ } ,
10+
11+ childContextTypes : {
12+ muiTheme : React . PropTypes . object . isRequired ,
13+ muiThemeManager : React . PropTypes . object . isRequired
14+ } ,
15+
16+ getChildContext : function ( ) {
17+ return {
18+ muiTheme : this . themeManager . getCurrentTheme ( ) ,
19+ muiThemeManager : this . themeManager
20+ } ;
21+ } ,
22+
23+ componentWillMount : function ( ) {
24+ this . themeManager = new ThemeManager ( ) ;
25+
26+ if ( this . props . theme ) {
27+ this . themeManager . setTheme ( this . props . theme ) ;
28+ }
29+ } ,
30+
31+ render : function ( ) {
32+ return this . props . children ( {
33+ muiTheme : this . themeManager . getCurrentTheme ( ) ,
34+ muiThemeManager : this . themeManager
35+ } ) ;
36+ }
37+ } ) ;
38+
39+
40+ function getDisplayName ( Component ) {
41+ return Component . displayName || Component . name || 'Component' ;
42+ }
43+
44+ function theme ( customTheme ) {
45+ return function ( Component ) {
46+ return React . createClass ( {
47+
48+ displayName : 'Theme(' + getDisplayName ( Component ) + ')' ,
49+
50+ render : function ( ) {
51+ return (
52+ < Theme theme = { customTheme } >
53+ {
54+ function ( props ) {
55+ return ( < Component { ...this . props } { ...props } /> ) ;
56+ } . bind ( this )
57+ }
58+ </ Theme >
59+ ) ;
60+ }
61+ } ) ;
62+ }
63+ }
64+
65+ module . exports = Theme ;
66+ module . exports . theme = theme ;
0 commit comments