|
- 'use strict';
-
- 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 _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
-
- var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
-
- var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
-
- var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
-
- var _createClass2 = require('babel-runtime/helpers/createClass');
-
- var _createClass3 = _interopRequireDefault(_createClass2);
-
- var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
-
- var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
-
- var _inherits2 = require('babel-runtime/helpers/inherits');
-
- var _inherits3 = _interopRequireDefault(_inherits2);
-
- 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 firstChild = props.firstChild,
- lastChild = props.lastChild;
- var _context$muiTheme = context.muiTheme,
- baseTheme = _context$muiTheme.baseTheme,
- button = _context$muiTheme.button,
- toolbar = _context$muiTheme.toolbar;
-
-
- var marginHorizontal = baseTheme.spacing.desktopGutter;
- var marginVertical = (toolbar.height - button.height) / 2;
-
- var styles = {
- root: {
- position: 'relative',
- marginLeft: firstChild ? -marginHorizontal : undefined,
- marginRight: lastChild ? -marginHorizontal : undefined,
- display: 'flex',
- justifyContent: 'space-between',
- alignItems: 'center'
- },
- dropDownMenu: {
- root: {
- color: toolbar.color, // removes hover color change, we want to keep it
- marginRight: baseTheme.spacing.desktopGutter,
- flex: 1,
- whiteSpace: 'nowrap'
- },
- controlBg: {
- backgroundColor: toolbar.menuHoverColor,
- borderRadius: 0
- },
- underline: {
- display: 'none'
- }
- },
- button: {
- margin: marginVertical + 'px ' + marginHorizontal + 'px',
- position: 'relative'
- },
- icon: {
- root: {
- cursor: 'pointer',
- lineHeight: toolbar.height + 'px',
- paddingLeft: baseTheme.spacing.desktopGutter
- }
- },
- span: {
- color: toolbar.iconColor,
- lineHeight: toolbar.height + 'px'
- }
- };
-
- return styles;
- }
-
- var ToolbarGroup = function (_Component) {
- (0, _inherits3.default)(ToolbarGroup, _Component);
-
- function ToolbarGroup() {
- (0, _classCallCheck3.default)(this, ToolbarGroup);
- return (0, _possibleConstructorReturn3.default)(this, (ToolbarGroup.__proto__ || (0, _getPrototypeOf2.default)(ToolbarGroup)).apply(this, arguments));
- }
-
- (0, _createClass3.default)(ToolbarGroup, [{
- key: 'handleMouseLeaveFontIcon',
- value: function handleMouseLeaveFontIcon(style) {
- return function (event) {
- event.target.style.zIndex = 'auto';
- event.target.style.color = style.root.color;
- };
- }
- }, {
- key: 'render',
- value: function render() {
- var _this2 = this;
-
- var _props = this.props,
- children = _props.children,
- className = _props.className,
- firstChild = _props.firstChild,
- lastChild = _props.lastChild,
- style = _props.style,
- other = (0, _objectWithoutProperties3.default)(_props, ['children', 'className', 'firstChild', 'lastChild', 'style']);
- var prepareStyles = this.context.muiTheme.prepareStyles;
-
- var styles = getStyles(this.props, this.context);
-
- var newChildren = _react2.default.Children.map(children, function (currentChild) {
- if (!currentChild) {
- return null;
- }
- if (!currentChild.type) {
- return currentChild;
- }
- switch (currentChild.type.muiName) {
- case 'DropDownMenu':
- return _react2.default.cloneElement(currentChild, {
- style: (0, _simpleAssign2.default)({}, styles.dropDownMenu.root, currentChild.props.style),
- underlineStyle: styles.dropDownMenu.underline
- });
- case 'RaisedButton':
- case 'FlatButton':
- return _react2.default.cloneElement(currentChild, {
- style: (0, _simpleAssign2.default)({}, styles.button, currentChild.props.style)
- });
- case 'FontIcon':
- return _react2.default.cloneElement(currentChild, {
- style: (0, _simpleAssign2.default)({}, styles.icon.root, currentChild.props.style),
- color: currentChild.props.color || _this2.context.muiTheme.toolbar.iconColor,
- hoverColor: currentChild.props.hoverColor || _this2.context.muiTheme.toolbar.hoverColor
- });
- case 'ToolbarSeparator':
- case 'ToolbarTitle':
- return _react2.default.cloneElement(currentChild, {
- style: (0, _simpleAssign2.default)({}, styles.span, currentChild.props.style)
- });
- default:
- return currentChild;
- }
- }, this);
-
- return _react2.default.createElement(
- 'div',
- (0, _extends3.default)({}, other, { className: className, style: prepareStyles((0, _simpleAssign2.default)({}, styles.root, style)) }),
- newChildren
- );
- }
- }]);
- return ToolbarGroup;
- }(_react.Component);
-
- ToolbarGroup.defaultProps = {
- firstChild: false,
- lastChild: false
- };
- ToolbarGroup.contextTypes = {
- muiTheme: _propTypes2.default.object.isRequired
- };
- ToolbarGroup.propTypes = process.env.NODE_ENV !== "production" ? {
- /**
- * Can be any node or number of nodes.
- */
- children: _propTypes2.default.node,
- /**
- * The css class name of the root element.
- */
- className: _propTypes2.default.string,
- /**
- * Set this to true for if the `ToolbarGroup` is the first child of `Toolbar`
- * to prevent setting the left gap.
- */
- firstChild: _propTypes2.default.bool,
- /**
- * Set this to true for if the `ToolbarGroup` is the last child of `Toolbar`
- * to prevent setting the right gap.
- */
- lastChild: _propTypes2.default.bool,
- /**
- * Override the inline-styles of the root element.
- */
- style: _propTypes2.default.object
- } : {};
- exports.default = ToolbarGroup;
|