UNPKG

material-ui

Version:

Material Design UI components built with React

104 lines (85 loc) 3.17 kB
'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; }; function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } var React = require('react'); var StylePropable = require('../mixins/style-propable'); var DefaultRawTheme = require('../styles/raw-themes/light-raw-theme'); var ThemeManager = require('../styles/theme-manager'); var Tab = React.createClass({ displayName: 'Tab', mixins: [StylePropable], contextTypes: { muiTheme: React.PropTypes.object }, propTypes: { onTouchTap: React.PropTypes.func, label: React.PropTypes.node, onActive: React.PropTypes.func, selected: React.PropTypes.bool, width: React.PropTypes.string, value: React.PropTypes.string }, //for passing default theme context to children childContextTypes: { muiTheme: React.PropTypes.object }, getChildContext: function getChildContext() { return { muiTheme: this.state.muiTheme }; }, getDefaultProps: function getDefaultProps() { return { onActive: function onActive() {}, onTouchTap: function onTouchTap() {} }; }, getInitialState: function 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: function componentWillReceiveProps(nextProps, nextContext) { var newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme; this.setState({ muiTheme: newMuiTheme }); }, render: function render() { var _props = this.props; var label = _props.label; var onActive = _props.onActive; var onTouchTap = _props.onTouchTap; var selected = _props.selected; var style = _props.style; var value = _props.value; var width = _props.width; var other = _objectWithoutProperties(_props, ['label', 'onActive', 'onTouchTap', 'selected', 'style', 'value', 'width']); var styles = this.prepareStyles({ display: 'table-cell', cursor: 'pointer', textAlign: 'center', verticalAlign: 'middle', height: 48, color: selected ? 'rgba(255,255,255,1)' : 'rgba(255,255,255,0.6)', outline: 'none', fontSize: 14, fontWeight: 500, whiteSpace: 'initial', fontFamily: this.state.muiTheme.rawTheme.fontFamily, boxSizing: 'border-box', width: width }, style); return React.createElement( 'div', _extends({}, other, { style: styles, onTouchTap: this._handleTouchTap }), label ); }, _handleTouchTap: function _handleTouchTap(e) { this.props.onTouchTap(this.props.value, e, this); } }); module.exports = Tab;