UNPKG

material-ui

Version:

Material Design UI components built with React

76 lines (61 loc) 1.71 kB
const React = require('react'); const Styles = require('../styles'); const StylePropable = require('../mixins/style-propable'); const ThemeManager = require('../styles/theme-manager'); const DefaultRawTheme = require('../styles/raw-themes/light-raw-theme'); const CardText = 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}); }, propTypes: { color: React.PropTypes.string, style: React.PropTypes.object, expandable: React.PropTypes.bool, actAsExpander: React.PropTypes.bool, }, getDefaultProps() { return { color: Styles.Colors.ck, }; }, getStyles() { return { root: { padding: 16, fontSize: '14px', color: this.props.color, }, }; }, render() { let styles = this.getStyles(); let rootStyle = this.prepareStyles(styles.root, this.props.style); return ( <div {...this.props} style={rootStyle}> {this.props.children} </div> ); }, }); module.exports = CardText;