|
| 1 | +var React = require('react'); |
| 2 | +var StylePropable = require('../mixins/style-propable'); |
| 3 | +var CustomVariables = require('../styles/variables/custom-variables'); |
| 4 | + |
| 5 | +var ToolbarGroup = React.createClass({ |
| 6 | + |
| 7 | + mixins: [StylePropable], |
| 8 | + |
| 9 | + propTypes: { |
| 10 | + className: React.PropTypes.string, |
| 11 | + float: React.PropTypes.string, |
| 12 | + firstChild: React.PropTypes.bool, |
| 13 | + lastChild: React.PropTypes.bool, |
| 14 | + }, |
| 15 | + |
| 16 | + getDefaultProps: function() { |
| 17 | + return { |
| 18 | + float: 'left', |
| 19 | + }; |
| 20 | + }, |
| 21 | + |
| 22 | + /** Styles for certain mui components */ |
| 23 | + _dropDownMenu: function() { |
| 24 | + var style = { |
| 25 | + main: { |
| 26 | + float: 'left', |
| 27 | + color: CustomVariables.colors.lightBlack,// removes hover color change, we want to keep it |
| 28 | + display: 'inline-block', |
| 29 | + marginRight: CustomVariables.spacing.desktopGutter, |
| 30 | + }, |
| 31 | + controlBg: { |
| 32 | + backgroundColor: CustomVariables.toolbarMenuHoverColor, |
| 33 | + borderRadius: 0, |
| 34 | + }, |
| 35 | + underline: { |
| 36 | + display: 'none', |
| 37 | + } |
| 38 | + }; |
| 39 | + |
| 40 | + return style; |
| 41 | + }, |
| 42 | + |
| 43 | + _button: function (){ |
| 44 | + var marginVertical = (CustomVariables.toolbarHeight - CustomVariables.buttonHeight) / 2; |
| 45 | + var marginHorizontal = CustomVariables.spacing.desktopGutter; |
| 46 | + return { |
| 47 | + float: 'left', |
| 48 | + margin: marginVertical + 'px ' + marginHorizontal + 'px', |
| 49 | + position: 'relative', |
| 50 | + }; |
| 51 | + }, |
| 52 | + |
| 53 | + _icon: function() { |
| 54 | + return { |
| 55 | + main: { |
| 56 | + float: 'left', |
| 57 | + cursor: 'pointer', |
| 58 | + color: CustomVariables.toolbarIconColor, |
| 59 | + lineHeight: CustomVariables.toolbarHeight + 'px', |
| 60 | + paddingLeft: CustomVariables.spacing.desktopGutter, |
| 61 | + }, |
| 62 | + hover: { |
| 63 | + zIndex: 1, |
| 64 | + color: CustomVariables.colors.darkBlack, |
| 65 | + } |
| 66 | + }; |
| 67 | + }, |
| 68 | + |
| 69 | + _span: function() { |
| 70 | + return { |
| 71 | + float: 'left', |
| 72 | + color: CustomVariables.toolbarIconColor, |
| 73 | + lineHeight: CustomVariables.toolbarHeight + 'px', |
| 74 | + }; |
| 75 | + }, |
| 76 | + |
| 77 | + |
| 78 | + render: function() { |
| 79 | + |
| 80 | + var styles = this.mergeAndPrefix({ |
| 81 | + position: 'relative', |
| 82 | + float: this.props.float, |
| 83 | + }); |
| 84 | + |
| 85 | + if (this.props.firstChild) styles.marginLeft = -24; |
| 86 | + if (this.props.lastChild) styles.marginRight = -24; |
| 87 | + |
| 88 | + React.Children.forEach(this.props.children, function(currentChild) { |
| 89 | + switch (currentChild.type.displayName) { |
| 90 | + case 'DropDownMenu' : |
| 91 | + currentChild.props.style = this._dropDownMenu().main; |
| 92 | + currentChild.props.styleControlBg = this._dropDownMenu().controlBg; |
| 93 | + currentChild.props.styleUnderline = this._dropDownMenu().underline; |
| 94 | + break; |
| 95 | + case 'DropDownIcon' : |
| 96 | + currentChild.props.style = {float: 'left'}; |
| 97 | + currentChild.props.iconStyle = this._icon().main; |
| 98 | + currentChild.props.hoverStyle = this._icon().hover; |
| 99 | + break; |
| 100 | + case 'RaisedButton' : case 'FlatButton' : |
| 101 | + currentChild.props.style = this._button(); |
| 102 | + break; |
| 103 | + case 'FontIcon' : |
| 104 | + currentChild.props.style = this._icon().main; |
| 105 | + currentChild.props.hoverStyle = this._icon().hover; |
| 106 | + break; |
| 107 | + case 'ToolbarSeparator' : case 'ToolbarTitle' : |
| 108 | + currentChild.props.style = this._span(); |
| 109 | + break; |
| 110 | + } |
| 111 | + }, this); |
| 112 | + |
| 113 | + return ( |
| 114 | + <div className={this.props.className} style={styles}> |
| 115 | + {this.props.children} |
| 116 | + </div> |
| 117 | + ); |
| 118 | + } |
| 119 | + |
| 120 | +}); |
| 121 | + |
| 122 | +module.exports = ToolbarGroup; |
0 commit comments