UNPKG

material-ui

Version:

Material Design UI components built with React

65 lines (51 loc) 1.68 kB
const React = require('react'); const StylePropable = require('../mixins/style-propable'); const DefaultRawTheme = require('../styles/raw-themes/light-raw-theme'); const ThemeManager = require('../styles/theme-manager'); const ToolbarSeparator = React.createClass({ mixins: [StylePropable], contextTypes: { muiTheme: React.PropTypes.object, }, //for passing default theme context to children childContextTypes: { muiTheme: React.PropTypes.object, }, getChildContext () { return { muiTheme: this.state.muiTheme, }; }, 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}); }, getTheme() { return this.state.muiTheme.toolbar; }, getSpacing() { return this.state.muiTheme.rawTheme.spacing; }, render() { let styles = this.prepareStyles({ backgroundColor: this.getTheme().separatorColor, display: 'inline-block', height: this.getSpacing().desktopGutterMore, marginLeft: this.getSpacing().desktopGutter, position: 'relative', top: ((this.getTheme().height - this.getSpacing().desktopGutterMore) / 2), width: 1, }, this.props.style); return ( <span className={this.props.className} style={styles}/> ); }, }); module.exports = ToolbarSeparator;