UNPKG

material-ui

Version:

Material Design UI components built with React

151 lines (121 loc) 4.76 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; }; Object.defineProperty(exports, "__esModule", { value: true }); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _stylePropable = require('../mixins/style-propable'); var _stylePropable2 = _interopRequireDefault(_stylePropable); var _lightRawTheme = require('../styles/raw-themes/light-raw-theme'); var _lightRawTheme2 = _interopRequireDefault(_lightRawTheme); var _themeManager = require('../styles/theme-manager'); var _themeManager2 = _interopRequireDefault(_themeManager); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 Tab = _react2.default.createClass({ displayName: 'Tab', propTypes: { /** * The css class name of the root element. */ className: _react2.default.PropTypes.string, /** * Sets the text value of the tab item to the string specified. */ label: _react2.default.PropTypes.node, /** * Fired when the active tab changes by touch or tap. * Use this event to specify any functionality when an active tab changes. * For example - we are using this to route to home when the third tab becomes active. * This function will always recieve the active tab as it\'s first argument. */ onActive: _react2.default.PropTypes.func, /** * This property is overriden by the Tabs component. */ onTouchTap: _react2.default.PropTypes.func, /** * Defines if the current tab is selected or not. * The Tabs component is responsible for setting this property. */ selected: _react2.default.PropTypes.bool, /** * Override the inline-styles of the root element. */ style: _react2.default.PropTypes.object, /** * If value prop passed to Tabs component, this value prop is also required. * It assigns a value to the tab so that it can be selected by the Tabs. */ value: _react2.default.PropTypes.any, /** * This property is overriden by the Tabs component. */ width: _react2.default.PropTypes.string }, contextTypes: { muiTheme: _react2.default.PropTypes.object }, //for passing default theme context to children childContextTypes: { muiTheme: _react2.default.PropTypes.object }, mixins: [_stylePropable2.default], getInitialState: function getInitialState() { return { muiTheme: this.context.muiTheme ? this.context.muiTheme : _themeManager2.default.getMuiTheme(_lightRawTheme2.default) }; }, getChildContext: function getChildContext() { return { muiTheme: this.state.muiTheme }; }, //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 }); }, _handleTouchTap: function _handleTouchTap(event) { if (this.props.onTouchTap) { this.props.onTouchTap(this.props.value, event, this); } }, 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 ? this.state.muiTheme.tabs.selectedTextColor : this.state.muiTheme.tabs.textColor, outline: 'none', fontSize: 14, fontWeight: 500, whiteSpace: 'initial', fontFamily: this.state.muiTheme.rawTheme.fontFamily, boxSizing: 'border-box', width: width }, style); return _react2.default.createElement( 'div', _extends({}, other, { style: styles, onTouchTap: this._handleTouchTap }), label ); } }); exports.default = Tab; module.exports = exports['default'];