1 | import { __assign, __extends } from "tslib";
|
2 | import * as React from 'react';
|
3 | import { classNamesFunction, KeyCodes, Async, initializeComponentRef } from '../../Utilities';
|
4 | import { ExpandingCardMode, } from './ExpandingCard.types';
|
5 | import { CardCallout } from './CardCallout/CardCallout';
|
6 | var getClassNames = classNamesFunction();
|
7 | var ExpandingCardBase = (function (_super) {
|
8 | __extends(ExpandingCardBase, _super);
|
9 | function ExpandingCardBase(props) {
|
10 | var _this = _super.call(this, props) || this;
|
11 | _this._expandedElem = React.createRef();
|
12 | _this._onKeyDown = function (ev) {
|
13 | if (ev.which === KeyCodes.escape) {
|
14 | _this.props.onLeave && _this.props.onLeave(ev);
|
15 | }
|
16 | };
|
17 | _this._onRenderCompactCard = function () {
|
18 | return React.createElement("div", { className: _this._classNames.compactCard }, _this.props.onRenderCompactCard(_this.props.renderData));
|
19 | };
|
20 | _this._onRenderExpandedCard = function () {
|
21 |
|
22 |
|
23 | !_this.state.firstFrameRendered &&
|
24 | _this._async.requestAnimationFrame(function () {
|
25 | _this.setState({
|
26 | firstFrameRendered: true,
|
27 | });
|
28 | });
|
29 | return (React.createElement("div", { className: _this._classNames.expandedCard, ref: _this._expandedElem },
|
30 | React.createElement("div", { className: _this._classNames.expandedCardScroll }, _this.props.onRenderExpandedCard && _this.props.onRenderExpandedCard(_this.props.renderData))));
|
31 | };
|
32 | _this._checkNeedsScroll = function () {
|
33 | var expandedCardHeight = _this.props.expandedCardHeight;
|
34 | _this._async.requestAnimationFrame(function () {
|
35 | if (_this._expandedElem.current && _this._expandedElem.current.scrollHeight >= expandedCardHeight) {
|
36 | _this.setState({
|
37 | needsScroll: true,
|
38 | });
|
39 | }
|
40 | });
|
41 | };
|
42 | _this._async = new Async(_this);
|
43 | initializeComponentRef(_this);
|
44 | _this.state = {
|
45 | firstFrameRendered: false,
|
46 | needsScroll: false,
|
47 | };
|
48 | return _this;
|
49 | }
|
50 | ExpandingCardBase.prototype.componentDidMount = function () {
|
51 | this._checkNeedsScroll();
|
52 | };
|
53 | ExpandingCardBase.prototype.componentWillUnmount = function () {
|
54 | this._async.dispose();
|
55 | };
|
56 | ExpandingCardBase.prototype.render = function () {
|
57 | var _a = this.props, styles = _a.styles, compactCardHeight = _a.compactCardHeight, expandedCardHeight = _a.expandedCardHeight, theme = _a.theme, mode = _a.mode, className = _a.className;
|
58 | var _b = this.state, needsScroll = _b.needsScroll, firstFrameRendered = _b.firstFrameRendered;
|
59 | var finalHeight = compactCardHeight + expandedCardHeight;
|
60 | this._classNames = getClassNames(styles, {
|
61 | theme: theme,
|
62 | compactCardHeight: compactCardHeight,
|
63 | className: className,
|
64 | expandedCardHeight: expandedCardHeight,
|
65 | needsScroll: needsScroll,
|
66 | expandedCardFirstFrameRendered: mode === ExpandingCardMode.expanded && firstFrameRendered,
|
67 | });
|
68 | var content = (React.createElement("div", { onMouseEnter: this.props.onEnter, onMouseLeave: this.props.onLeave, onKeyDown: this._onKeyDown },
|
69 | this._onRenderCompactCard(),
|
70 | this._onRenderExpandedCard()));
|
71 | return (React.createElement(CardCallout, __assign({}, this.props, { content: content, finalHeight: finalHeight, className: this._classNames.root })));
|
72 | };
|
73 | ExpandingCardBase.defaultProps = {
|
74 | compactCardHeight: 156,
|
75 | expandedCardHeight: 384,
|
76 | directionalHintFixed: true,
|
77 | };
|
78 | return ExpandingCardBase;
|
79 | }(React.Component));
|
80 | export { ExpandingCardBase };
|
81 |
|
\ | No newline at end of file |