beyond-components
Version:
react prototype components
63 lines (61 loc) • 2.33 kB
JavaScript
;
exports.__esModule = true;
var tslib_1 = require("tslib");
/*
12 grid, Col.xs 表示百分比
<Row width={1200} gutter={30} verticalGutter={20}>
<Col xs={6} width={600} offset={100}></Col>
<Col xs={6} width={600}></Col>
</Row>
<Row gutter={30}>
<Col xs={6} xsOffset={}></Col>
<Col xs={6}></Col>
</Row>
*/
var React = require("react");
var classnames = require("classnames");
var assign = require("beyond-lib/lib/assign");
// import Col from './Col'
var consts_1 = require("../consts");
;
;
var Row = /** @class */ (function (_super) {
tslib_1.__extends(Row, _super);
function Row() {
return _super !== null && _super.apply(this, arguments) || this;
}
Row.prototype.render = function () {
var style = {};
var _a = this.props, width = _a.width, extraClassName = _a.extraClassName, _style = _a.style, prefix = _a.prefix;
var className = prefix + "row";
if (width != null) {
style.width = width;
}
return (React.createElement("div", { style: assign(style, _style), className: classnames(className, extraClassName) }, this.renderCols()));
};
Row.prototype.renderCols = function () {
var _a = this.props, gutter = _a.gutter, verticalGutter = _a.verticalGutter, grids = _a.grids, prefix = _a.prefix;
var children = (Array.isArray(this.props.children) ? this.props.children : [this.props.children]).filter(function (child) { return child != null; });
var style = {};
if (gutter > 0) {
style.paddingLeft = gutter / 2;
style.paddingRight = gutter / 2;
}
if (verticalGutter > 0) {
style.paddingTop = verticalGutter / 2;
style.paddingBottom = verticalGutter / 2;
}
return children.map(function (child, i) {
var key = child.key || (i + '');
return React.cloneElement(child, { key: key, style: assign({}, style, child.props.style), grids: grids, prefix: prefix });
});
};
Row.defaultProps = {
grids: 12,
prefix: consts_1.prefix,
gutter: 0,
verticalGutter: 0
};
return Row;
}(React.Component));
exports["default"] = Row;