UNPKG

kitchensink

Version:

Dispatch's awesome components and style guide

132 lines (103 loc) 5.25 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _radium = require('radium'); var _radium2 = _interopRequireDefault(_radium); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _View = require('./View'); var _View2 = _interopRequireDefault(_View); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var SplitView = function (_React$Component) { _inherits(SplitView, _React$Component); function SplitView(props) { _classCallCheck(this, SplitView); var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(SplitView).call(this, props)); var orientation = _this.props.orientation || 'horizontal'; if (orientation === 'horizontal') { var leftWidth = _this.props.leftWidth; var rightWidth = _this.props.rightWidth; if (leftWidth && leftWidth.indexOf('px') > -1) { rightWidth = 'calc(100% - ' + leftWidth + ')'; } else if (rightWidth && rightWidth.indexOf('px') > -1) { leftWidth = 'calc(100% - ' + rightWidth + ')'; } _this.overridesLeft = leftWidth ? { width: leftWidth } : false; _this.overridesRight = rightWidth ? { width: rightWidth } : false; } else if (orientation === 'vertical') { var topHeight = _this.props.topHeight; var bottomHeight = _this.props.bottomHeight; if (topHeight && topHeight.indexOf('px') > -1) { bottomHeight = 'calc(100% - ' + topHeight + ')'; } else if (bottomHeight && bottomHeight.indexOf('px') > -1) { topHeight = 'calc(100% - ' + bottomHeight + ')'; } _this.overridesTop = topHeight ? { height: topHeight } : false; _this.overridesBottom = bottomHeight ? { height: bottomHeight } : false; } return _this; } _createClass(SplitView, [{ key: 'render', value: function render() { var viewOneStyles = {}; var viewTwoStyles = {}; var orientation = this.props.orientation || 'horizontal'; if (orientation === 'horizontal') { viewOneStyles = Object.assign({}, SplitView.horizontalStyles, SplitView.leftStyles, this.overridesLeft); viewTwoStyles = Object.assign({}, SplitView.horizontalStyles, SplitView.rightStyles, this.overridesRight); } else if (orientation === 'vertical') { viewOneStyles = Object.assign({}, SplitView.topStyles, this.overridesTop); viewTwoStyles = Object.assign({}, SplitView.bottomStyles, this.overridesBottom); } return _react2.default.createElement( _View2.default, { style: Object.assign({}, { overflow: 'hidden', height: '100%' }, this.props.style) }, _react2.default.createElement( _View2.default, { style: viewOneStyles }, this.props.viewOne ), _react2.default.createElement( _View2.default, { style: viewTwoStyles }, this.props.viewTwo ) ); } }]); return SplitView; }(_react2.default.Component); SplitView.propTypes = { orientation: _react2.default.PropTypes.string, leftWidth: _react2.default.PropTypes.string, rightWidth: _react2.default.PropTypes.string, topHeight: _react2.default.PropTypes.string, bottomHeight: _react2.default.PropTypes.string, style: _react2.default.PropTypes.object, viewOne: _react2.default.PropTypes.any, viewTwo: _react2.default.PropTypes.any }; SplitView.horizontalStyles = { height: '100%', float: 'left' }; SplitView.topStyles = { height: '50%' }; SplitView.bottomStyles = { height: '50%' }; SplitView.leftStyles = { width: '50%' }; SplitView.rightStyles = { width: '50%' }; exports.default = SplitView; SplitView = (0, _radium2.default)(SplitView); // eslint-disable-line new-cap