@atlaskit/mention
Version:
A React component used to display user profiles in a list for 'Mention' functionality
50 lines • 2.48 kB
JavaScript
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';
import { findDOMNode } from 'react-dom';
import { ScrollableStyle } from './styles';
var Scrollable = /*#__PURE__*/function (_React$PureComponent) {
function Scrollable() {
var _this;
_classCallCheck(this, Scrollable);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, Scrollable, [].concat(args));
// API
_defineProperty(_this, "reveal", function (child) {
if (child && _this.scrollableDiv) {
var childNode = findDOMNode(child);
// Not using Element.scrollIntoView as it scrolls even to top/bottom of view even if
// already visible
var scrollableRect = _this.scrollableDiv.getBoundingClientRect();
var elementRect = childNode.getBoundingClientRect();
if (elementRect.top < scrollableRect.top) {
_this.scrollableDiv.scrollTop += elementRect.top - scrollableRect.top;
} else if (elementRect.bottom > scrollableRect.bottom) {
_this.scrollableDiv.scrollTop += elementRect.bottom - scrollableRect.bottom;
}
}
});
_defineProperty(_this, "handleRef", function (ref) {
_this.scrollableDiv = ref;
});
return _this;
}
_inherits(Scrollable, _React$PureComponent);
return _createClass(Scrollable, [{
key: "render",
value: function render() {
return /*#__PURE__*/React.createElement(ScrollableStyle, {
ref: this.handleRef
}, this.props.children);
}
}]);
}(React.PureComponent);
export { Scrollable as default };