@txdfe/at
Version:
一个设计体系组件库
182 lines (181 loc) • 10.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames2 = _interopRequireDefault(require("classnames"));
var _row = _interopRequireDefault(require("./row"));
var _cell = _interopRequireDefault(require("./cell"));
var _excluded = ["prefix", "className", "children", "component", "colGroup", "loading", "emptyContent", "components", "getCellProps", "primaryKey", "getRowProps", "dataSource", "cellRef", "columns", "rowRef", "onRowClick", "onRowMouseEnter", "onRowMouseLeave", "locale", "pure", "expandedIndexSimulate", "rtl", "table"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var noop = function noop() {};
var Body = exports["default"] = /*#__PURE__*/function (_React$Component) {
function Body() {
var _this;
_classCallCheck(this, Body);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, Body, [].concat(args));
_defineProperty(_this, "getRowRef", function (i, row) {
_this.props.rowRef(i, row);
});
_defineProperty(_this, "onRowClick", function (record, index, e) {
_this.props.onRowClick(record, index, e);
});
_defineProperty(_this, "onRowMouseEnter", function (record, index, e) {
_this.props.onRowMouseEnter(record, index, e);
});
_defineProperty(_this, "onRowMouseLeave", function (record, index, e) {
_this.props.onRowMouseLeave(record, index, e);
});
return _this;
}
_inherits(Body, _React$Component);
return _createClass(Body, [{
key: "render",
value: function render() {
var _this2 = this;
/* eslint-disable no-unused-vars */
var _this$props = this.props,
prefix = _this$props.prefix,
className = _this$props.className,
children = _this$props.children,
Tag = _this$props.component,
colGroup = _this$props.colGroup,
loading = _this$props.loading,
emptyContent = _this$props.emptyContent,
components = _this$props.components,
getCellProps = _this$props.getCellProps,
primaryKey = _this$props.primaryKey,
getRowProps = _this$props.getRowProps,
dataSource = _this$props.dataSource,
cellRef = _this$props.cellRef,
columns = _this$props.columns,
rowRef = _this$props.rowRef,
onRowClick = _this$props.onRowClick,
onRowMouseEnter = _this$props.onRowMouseEnter,
onRowMouseLeave = _this$props.onRowMouseLeave,
locale = _this$props.locale,
pure = _this$props.pure,
expandedIndexSimulate = _this$props.expandedIndexSimulate,
rtl = _this$props.rtl,
table = _this$props.table,
others = _objectWithoutProperties(_this$props, _excluded);
delete others.table;
var _components$Row = components.Row,
Row = _components$Row === void 0 ? _row["default"] : _components$Row,
_components$Cell = components.Cell,
Cell = _components$Cell === void 0 ? _cell["default"] : _components$Cell;
var empty = loading ? /*#__PURE__*/_react["default"].createElement("span", null, "\xA0") : emptyContent || locale.empty;
var rows = /*#__PURE__*/_react["default"].createElement("tr", null, /*#__PURE__*/_react["default"].createElement("td", {
colSpan: columns.length
}, /*#__PURE__*/_react["default"].createElement("div", {
className: "".concat(prefix, "table-empty")
}, empty)));
if (Tag === 'div') {
rows = /*#__PURE__*/_react["default"].createElement("table", {
role: "table"
}, /*#__PURE__*/_react["default"].createElement("tbody", null, rows));
}
if (dataSource.length) {
rows = dataSource.map(function (record, index) {
var rowProps = {};
if (expandedIndexSimulate) {
rowProps = record.__expanded ? {} : getRowProps(record, index / 2);
} else {
rowProps = getRowProps(record, index);
}
rowProps = rowProps || {};
var rowClass = rowProps.className;
var rowClassName = (0, _classnames2["default"])(_defineProperty({
first: index === 0,
last: index === dataSource.length - 1
}, rowClass, rowClass));
var expanded = record.__expanded ? 'expanded' : '';
return /*#__PURE__*/_react["default"].createElement(Row, _extends({
key: "".concat(record[primaryKey] || index).concat(expanded)
}, rowProps, {
ref: _this2.getRowRef.bind(_this2, index),
colGroup: colGroup,
rtl: rtl,
columns: columns,
primaryKey: primaryKey,
record: record,
rowIndex: index,
prefix: prefix,
pure: pure,
cellRef: cellRef,
getCellProps: getCellProps,
className: rowClassName,
Cell: Cell,
onClick: _this2.onRowClick,
locale: locale,
onMouseEnter: _this2.onRowMouseEnter,
onMouseLeave: _this2.onRowMouseLeave,
table: table
}));
});
}
return /*#__PURE__*/_react["default"].createElement(Tag, _extends({
className: className
}, others), rows, children);
}
}]);
}(_react["default"].Component);
_defineProperty(Body, "propTypes", {
loading: _propTypes["default"].bool,
emptyContent: _propTypes["default"].any,
prefix: _propTypes["default"].string,
pure: _propTypes["default"].bool,
components: _propTypes["default"].object,
getCellProps: _propTypes["default"].func,
cellRef: _propTypes["default"].func,
primaryKey: _propTypes["default"].string,
getRowProps: _propTypes["default"].func,
rowRef: _propTypes["default"].func,
dataSource: _propTypes["default"].array,
children: _propTypes["default"].any,
className: _propTypes["default"].string,
component: _propTypes["default"].string,
colGroup: _propTypes["default"].object,
columns: _propTypes["default"].array,
onRowClick: _propTypes["default"].func,
onRowMouseEnter: _propTypes["default"].func,
onRowMouseLeave: _propTypes["default"].func,
locale: _propTypes["default"].object,
table: _propTypes["default"].object
});
_defineProperty(Body, "defaultProps", {
loading: false,
prefix: 'next-',
components: {},
getCellProps: noop,
cellRef: noop,
primaryKey: 'id',
getRowProps: noop,
rowRef: noop,
dataSource: [],
component: 'tbody',
columns: [],
table: null
});