choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
150 lines (125 loc) • 4.76 kB
JavaScript
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 _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import React, { Children, cloneElement, PureComponent } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
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, ["type", "justify", "align", "className", "style", "children", "prefixCls"]);
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 cloneElement(col, {
style: _objectSpread({
paddingLeft: gutter / 2,
paddingRight: gutter / 2
}, col.props.style)
});
}
return col;
});
var otherProps = _objectSpread({}, others);
delete otherProps.gutter;
return 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 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
};
Row.propTypes = {
type: PropTypes.string,
align: PropTypes.string,
justify: PropTypes.string,
className: PropTypes.string,
children: PropTypes.node,
gutter: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
prefixCls: PropTypes.string
};
//# sourceMappingURL=row.js.map