UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

107 lines (89 loc) 3.65 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _createSuper from "@babel/runtime/helpers/createSuper"; var _excluded = ["type", "justify", "align", "className", "style", "children", "prefixCls"]; import React, { Children, cloneElement, PureComponent } from 'react'; import classNames from 'classnames'; import omit from 'lodash/omit'; import Responsive from '../responsive/Responsive'; import ConfigContext from '../config-provider/ConfigContext'; var defaultGutter = 0; var Row = /*#__PURE__*/function (_PureComponent) { _inherits(Row, _PureComponent); var _super = _createSuper(Row); function Row() { var _this; _classCallCheck(this, Row); _this = _super.apply(this, arguments); _this.renderRow = function (_ref) { var _classNames; var _ref2 = _slicedToArray(_ref, 1), _ref2$ = _ref2[0], gutter = _ref2$ === void 0 ? defaultGutter : _ref2$; var _this$props = _this.props, type = _this$props.type, justify = _this$props.justify, align = _this$props.align, className = _this$props.className, style = _this$props.style, children = _this$props.children, customizePrefixCls = _this$props.prefixCls, others = _objectWithoutProperties(_this$props, _excluded); var getPrefixCls = _this.context.getPrefixCls; var prefixCls = getPrefixCls('row', customizePrefixCls); var classes = classNames((_classNames = {}, _defineProperty(_classNames, prefixCls, !type), _defineProperty(_classNames, "".concat(prefixCls, "-").concat(type), type), _defineProperty(_classNames, "".concat(prefixCls, "-").concat(type, "-").concat(justify), type && justify), _defineProperty(_classNames, "".concat(prefixCls, "-").concat(type, "-").concat(align), type && align), _classNames), className); var rowStyle = gutter > 0 ? _objectSpread({ marginLeft: gutter / -2, marginRight: gutter / -2 }, style) : style; var cols = Children.map(children, function (col) { if (!col) { return null; } if (col.props && gutter > 0) { return /*#__PURE__*/cloneElement(col, { style: _objectSpread({ paddingLeft: gutter / 2, paddingRight: gutter / 2 }, col.props.style) }); } return col; }); var otherProps = _objectSpread({}, others); delete otherProps.gutter; return /*#__PURE__*/React.createElement("div", _extends({}, omit(otherProps, ['rowIndex', 'colIndex']), { className: classes, style: rowStyle }), cols); }; return _this; } _createClass(Row, [{ key: "render", value: function render() { var gutter = this.props.gutter; return /*#__PURE__*/React.createElement(Responsive, { items: [gutter] }, this.renderRow); } }], [{ key: "contextType", get: function get() { return ConfigContext; } }]); return Row; }(PureComponent); export { Row as default }; Row.displayName = 'Row'; Row.defaultProps = { gutter: defaultGutter }; //# sourceMappingURL=row.js.map