UNPKG

@atlaskit/dynamic-table

Version:

A dynamic table displays rows of data with built-in pagination, sorting, and re-ordering functionality.

63 lines (62 loc) 3.55 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireDefault(require("react")); var _pagination = _interopRequireDefault(require("@atlaskit/pagination")); function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } // eslint-disable-next-line @repo/internal/react/no-class-components var ManagedPagination = exports.default = /*#__PURE__*/function (_React$Component) { function ManagedPagination() { var _this; (0, _classCallCheck2.default)(this, ManagedPagination); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _callSuper(this, ManagedPagination, [].concat(args)); (0, _defineProperty2.default)(_this, "onChange", function (_event, newValue, analyticsEvent) { _this.props.onChange(newValue, analyticsEvent); }); return _this; } (0, _inherits2.default)(ManagedPagination, _React$Component); return (0, _createClass2.default)(ManagedPagination, [{ key: "render", value: function render() { var _this$props = this.props, total = _this$props.total, _this$props$value = _this$props.value, value = _this$props$value === void 0 ? 1 : _this$props$value, i18n = _this$props.i18n, testId = _this$props.testId, isDisabled = _this$props.isDisabled; var pages = (0, _toConsumableArray2.default)(Array(total)).map(function (_, index) { return index + 1; }); // Pagination accepts array now thus selectedIndex starts with 0 // So, we are substracting value by one thus not breaking dynamic table var selectedIndex = value - 1; return /*#__PURE__*/_react.default.createElement(_pagination.default, { selectedIndex: selectedIndex, isDisabled: isDisabled, label: i18n === null || i18n === void 0 ? void 0 : i18n.label, nextLabel: i18n === null || i18n === void 0 ? void 0 : i18n.next, previousLabel: i18n === null || i18n === void 0 ? void 0 : i18n.prev, pageLabel: i18n === null || i18n === void 0 ? void 0 : i18n.pageLabel, onChange: this.onChange, pages: pages, testId: testId && "".concat(testId, "--pagination") }); } }]); }(_react.default.Component);