zarm-web
Version:
基于 React 的桌面端UI库
189 lines (156 loc) • 9.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames3 = _interopRequireDefault(require("classnames"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var FixedColumn =
/*#__PURE__*/
function (_Component) {
_inherits(FixedColumn, _Component);
function FixedColumn() {
_classCallCheck(this, FixedColumn);
return _possibleConstructorReturn(this, _getPrototypeOf(FixedColumn).apply(this, arguments));
}
_createClass(FixedColumn, [{
key: "renderRows",
value: function renderRows(column, height) {
var _this$props = this.props,
dataSource = _this$props.dataSource,
onEnterRow = _this$props.onEnterRow,
onLeaveRow = _this$props.onLeaveRow,
rowClassName = _this$props.rowClassName;
var render = column.render,
dataIndex = column.dataIndex;
var size = dataSource.length;
var iHeight = parseInt(height, 10); // eslint-disable-next-line no-restricted-globals
if (isNaN(iHeight)) {
iHeight = 41;
}
return dataSource.map(function (data, index) {
var tdHeight = index === size - 1 ? iHeight - 1 : height;
var rowClass = (0, _classnames3.default)(_defineProperty({}, "".concat(rowClassName && rowClassName(data)), !!(rowClassName && rowClassName(data))));
return _react.default.createElement("tr", {
key: index.toString(),
onMouseEnter: function onMouseEnter() {
return onEnterRow(index);
},
onMouseLeave: function onMouseLeave() {
return onLeaveRow();
},
className: rowClass
}, _react.default.createElement("td", {
style: {
height: tdHeight
}
}, typeof render === 'function' ? render(data[dataIndex], data, index) : data[dataIndex]));
});
}
}, {
key: "renderSelection",
value: function renderSelection(thHeight, tdHeight) {
var _this = this;
var _this$props2 = this.props,
prefixCls = _this$props2.prefixCls,
direction = _this$props2.direction,
rowSelection = _this$props2.rowSelection,
renderSelect = _this$props2.renderSelect,
renderSelectAll = _this$props2.renderSelectAll,
onEnterRow = _this$props2.onEnterRow,
onLeaveRow = _this$props2.onLeaveRow,
dataSource = _this$props2.dataSource,
rowClassName = _this$props2.rowClassName;
var size = dataSource.length;
var iHeight = parseInt(tdHeight, 10); // eslint-disable-next-line no-restricted-globals
if (isNaN(iHeight)) {
iHeight = 41;
}
var cls = "".concat(prefixCls, "-fixed-").concat(direction);
return _react.default.createElement("table", {
ref: function ref(fixedCol) {
_this["fixed".concat(direction, "Col")] = fixedCol;
},
className: cls
}, _react.default.createElement("thead", null, _react.default.createElement("tr", null, rowSelection ? renderSelectAll(rowSelection, dataSource, 1, thHeight) : null)), _react.default.createElement("tbody", {
ref: function ref(fixedTbody) {
_this["fixed".concat(direction, "Tbody")] = fixedTbody;
}
}, dataSource.map(function (data, index) {
var height = index === size - 1 ? iHeight - 1 : tdHeight;
var rowClass = (0, _classnames3.default)(_defineProperty({}, "".concat(rowClassName && rowClassName(data)), !!(rowClassName && rowClassName(data))));
return _react.default.createElement("tr", {
key: index.toString(),
onMouseEnter: function onMouseEnter() {
return onEnterRow(index);
},
onMouseLeave: function onMouseLeave() {
return onLeaveRow();
},
className: rowClass
}, rowSelection ? renderSelect(rowSelection, data, height) : null);
})));
}
}, {
key: "render",
value: function render() {
var _this2 = this;
var _this$props3 = this.props,
direction = _this$props3.direction,
_this$props3$columns = _this$props3.columns,
columns = _this$props3$columns === void 0 ? [] : _this$props3$columns,
prefixCls = _this$props3.prefixCls,
colAttrs = _this$props3.colAttrs,
rowSelection = _this$props3.rowSelection;
var fixedColThHeight = colAttrs.fixedColThHeight,
fixedColTdHeight = colAttrs.fixedColTdHeight,
fixedleftColWidth = colAttrs.fixedleftColWidth,
fixedrightColWidth = colAttrs.fixedrightColWidth;
var column = direction === 'left' ? columns[0] : columns[columns.length - 1];
var columnWidth = direction === 'left' ? fixedleftColWidth : fixedrightColWidth;
if (!column) {
return null;
}
var fixed = column.fixed,
title = column.title;
var cls = "".concat(prefixCls, "-fixed-").concat(direction);
if (direction === 'left' && rowSelection && rowSelection.fixed) {
return this.renderSelection(fixedColThHeight, fixedColTdHeight);
}
if (fixed && fixed === direction) {
return _react.default.createElement("table", {
ref: function ref(fixedCol) {
_this2["fixed".concat(direction, "Col")] = fixedCol;
},
className: cls
}, _react.default.createElement("thead", null, _react.default.createElement("tr", null, _react.default.createElement("th", {
style: {
width: columnWidth,
height: fixedColThHeight
}
}, title))), _react.default.createElement("tbody", {
ref: function ref(fixedTbody) {
_this2["fixed".concat(direction, "Tbody")] = fixedTbody;
}
}, this.renderRows(column, fixedColTdHeight)));
}
return null;
}
}]);
return FixedColumn;
}(_react.Component);
var _default = FixedColumn;
exports.default = _default;