forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.js
67 lines (53 loc) · 1.71 KB
/
theme.js
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
67
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var React = require('react');
var ThemeManager = require('./styles/theme-manager');
var Theme = React.createClass({
displayName: 'Theme',
propTypes: {
theme: React.PropTypes.object
},
childContextTypes: {
muiTheme: React.PropTypes.object.isRequired,
muiThemeManager: React.PropTypes.object.isRequired
},
getChildContext: function getChildContext() {
return {
muiTheme: this.themeManager.getCurrentTheme(),
muiThemeManager: this.themeManager
};
},
componentWillMount: function componentWillMount() {
this.themeManager = new ThemeManager();
if (this.props.theme) {
this.themeManager.setTheme(this.props.theme);
}
},
render: function render() {
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 render() {
return React.createElement(
Theme,
{ theme: customTheme },
(function (props) {
return React.createElement(Component, _extends({}, this.props, props));
}).bind(this)
);
}
});
};
}
module.exports = Theme;
module.exports.theme = theme;