forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathink-bar.jsx
76 lines (63 loc) · 1.8 KB
/
ink-bar.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
67
68
69
70
71
72
73
74
75
76
const React = require('react');
const Transitions = require('./styles/transitions');
const StylePropable = require('./mixins/style-propable');
const DefaultRawTheme = require('./styles/raw-themes/light-raw-theme');
const ThemeManager = require('./styles/theme-manager');
const InkBar = React.createClass({
contextTypes: {
muiTheme: React.PropTypes.object,
},
//for passing default theme context to children
childContextTypes: {
muiTheme: React.PropTypes.object,
},
getChildContext () {
return {
muiTheme: this.state.muiTheme,
};
},
propTypes: {
color: React.PropTypes.string,
left: React.PropTypes.string.isRequired,
width: React.PropTypes.string.isRequired,
},
getInitialState () {
return {
muiTheme: this.context.muiTheme ? this.context.muiTheme : ThemeManager.getMuiTheme(DefaultRawTheme),
};
},
//to update theme inside state whenever a new theme is passed down
//from the parent / owner using context
componentWillReceiveProps (nextProps, nextContext) {
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({muiTheme: newMuiTheme});
},
mixins: [StylePropable],
render() {
let {
color,
left,
width,
style,
...other,
} = this.props;
let colorStyle = color ? {backgroundColor: color} : undefined;
let styles = this.mergeAndPrefix({
left: left,
width: width,
bottom: 0,
display: 'block',
backgroundColor: this.state.muiTheme.inkBar.backgroundColor,
height: 2,
marginTop: -2,
position: 'relative',
transition: Transitions.easeOut('1s', 'left'),
}, this.props.style, colorStyle);
return (
<div style={styles}>
</div>
);
},
});
module.exports = InkBar;