material-ui
Version:
React Components that Implement Google's Material Design.
97 lines (73 loc) • 2.56 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _simpleAssign = require('simple-assign');
var _simpleAssign2 = _interopRequireDefault(_simpleAssign);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getStyles(props, context) {
var bottomNavigation = context.muiTheme.bottomNavigation;
var styles = {
root: {
position: 'relative',
width: '100%',
display: 'flex',
justifyContent: 'center',
backgroundColor: bottomNavigation.backgroundColor,
height: bottomNavigation.height
},
item: {
flex: '1'
}
};
return styles;
}
var BottomNavigation = function BottomNavigation(props, context) {
var children = props.children,
style = props.style,
selectedIndex = props.selectedIndex,
other = (0, _objectWithoutProperties3.default)(props, ['children', 'style', 'selectedIndex']);
var prepareStyles = context.muiTheme.prepareStyles;
var styles = getStyles(props, context);
var preparedChildren = _react.Children.map(children, function (child, index) {
if (!child) {
return null;
}
return (0, _react.cloneElement)(child, {
style: (0, _simpleAssign2.default)({}, styles.item, child.props.style),
selected: index === selectedIndex
});
});
return _react2.default.createElement(
'div',
(0, _extends3.default)({}, other, { style: prepareStyles((0, _simpleAssign2.default)({}, styles.root, style)) }),
preparedChildren
);
};
BottomNavigation.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The `BottomNavigationItem`s to populate the element with.
*/
children: _propTypes2.default.node,
/**
* The index of the currently selected navigation item.
*/
selectedIndex: _propTypes2.default.number,
/**
* @ignore
* Override the inline-styles of the root element.
*/
style: _propTypes2.default.object
} : {};
BottomNavigation.contextTypes = {
muiTheme: _propTypes2.default.object.isRequired
};
exports.default = BottomNavigation;
;