@up-group-ui/react-controls
Version:
Up shared react controls
52 lines • 3.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var React = (0, tslib_1.__importStar)(require("react"));
var classnames_1 = (0, tslib_1.__importDefault)(require("classnames"));
var object_assign_1 = (0, tslib_1.__importDefault)(require("object-assign"));
var UpGridContext_1 = require("./UpGridContext");
var UpCol_1 = (0, tslib_1.__importDefault)(require("./UpCol"));
var RowRenderer = function (props) {
var prefixCls = props.prefixCls, justify = props.justify, align = props.align, className = props.className, style = props.style, children = props.children, type = props.type, gutter = props.gutter, rowSpacing = props.rowSpacing, fullRowLayout = props.fullRowLayout, others = (0, tslib_1.__rest)(props, ["prefixCls", "justify", "align", "className", "style", "children", "type", "gutter", "rowSpacing", "fullRowLayout"]);
var getRowStyle = function () {
return gutter > 0
? (0, object_assign_1.default)({}, {
marginLeft: gutter / -2,
marginRight: gutter / -2,
}, style)
: style;
};
var getClasses = function () {
var _a;
return (0, classnames_1.default)((_a = {},
_a[prefixCls] = type == 'float',
_a[prefixCls + "-flex"] = type == 'flex',
_a[prefixCls + "-flex-" + justify] = type == 'flex' && justify,
_a[prefixCls + "-flex-" + align] = type == 'flex' && align,
_a[prefixCls + "-flex-full"] = fullRowLayout,
_a), className);
};
var cols = children;
if (rowSpacing > 0 || type != 'float') {
cols = React.Children.map(children, function (row, index) {
if (!row) {
return null;
}
if (row.props && row.type == UpCol_1.default) {
return ((0, jsx_runtime_1.jsx)(React.Fragment, { children: React.cloneElement(row, {
rowSpacing: row.props.rowSpacing == 0 ? rowSpacing : row.props.gutter,
type: row.props.type ? row.props.type : row.props.type,
}) }, index));
}
return row;
});
}
return ((0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({}, others, { className: getClasses(), style: getRowStyle() }, { children: cols }), void 0));
};
var UpRow = function (_a) {
var _b = _a.gutter, gutter = _b === void 0 ? 0 : _b, _c = _a.rowSpacing, rowSpacing = _c === void 0 ? 0 : _c, _d = _a.type, type = _d === void 0 ? 'flex' : _d, _e = _a.prefixCls, prefixCls = _e === void 0 ? 'up-row' : _e, rest = (0, tslib_1.__rest)(_a, ["gutter", "rowSpacing", "type", "prefixCls"]);
return ((0, jsx_runtime_1.jsx)(UpGridContext_1.UpGridConsumer, { children: function (value) { return ((0, jsx_runtime_1.jsx)(RowRenderer, (0, tslib_1.__assign)({ fullRowLayout: value.fullRowLayout, gutter: gutter || value.gutter, rowSpacing: rowSpacing || value.rowSpacing, type: type || value.type, prefixCls: prefixCls }, rest), void 0)); } }, void 0));
};
exports.default = UpRow;
//# sourceMappingURL=UpRow.js.map