UNPKG

@atlaskit/dynamic-table

Version:

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

74 lines 3.16 kB
import _extends from "@babel/runtime/helpers/extends"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(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; })(); } import React from 'react'; // Compute height and width of wrapped component before ranking export default function withDimensions(WrappedComponent) { return /*#__PURE__*/function (_React$Component) { function WithDimensions() { var _this; _classCallCheck(this, WithDimensions); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _callSuper(this, WithDimensions, [].concat(args)); _defineProperty(_this, "state", { refWidth: 0, refHeight: 0 }); _defineProperty(_this, "innerRef", function (ref) { if (ref && !_this.props.isRanking) { _this.ref = ref; } }); _defineProperty(_this, "updateDimensions", function () { if (!_this.ref) { return; } var clientRect = _this.ref.getBoundingClientRect(); var width = clientRect.width; var height = clientRect.height; if (width !== _this.state.refWidth || height !== _this.state.refHeight) { _this.setState({ refWidth: width, refHeight: height }); } }); return _this; } _inherits(WithDimensions, _React$Component); return _createClass(WithDimensions, [{ key: "UNSAFE_componentWillReceiveProps", value: function UNSAFE_componentWillReceiveProps(nextProps) { var wasRanking = this.props.isRanking; var willRanking = nextProps.isRanking; if (willRanking && !wasRanking) { this.updateDimensions(); } } }, { key: "render", value: function render() { var _this$state = this.state, refWidth = _this$state.refWidth, refHeight = _this$state.refHeight; return /*#__PURE__*/React.createElement(WrappedComponent //@ts-expect-error TODO Fix legit TypeScript 3.9.6 improved inference error , _extends({ refWidth: refWidth //@ts-expect-error TODO Fix legit TypeScript 3.9.6 improved inference error , refHeight: refHeight, innerRef: this.innerRef }, this.props)); } }]); }(React.Component); }