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