office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
101 lines • 5.46 kB
JavaScript
import * as tslib_1 from "tslib";
/* tslint:disable:no-unused-variable */
import * as React from 'react';
/* tslint:enable:no-unused-variable */
import { BaseComponent, getNativeProps, divProperties, customizable, autobind } from '../../Utilities';
import { ExpandingCardMode } from './ExpandingCard.types';
import { Callout } from '../../Callout';
import { AnimationStyles, mergeStyles } from '../../Styling';
import { FocusTrapZone } from '../../FocusTrapZone';
import { getStyles } from './ExpandingCard.styles';
var ExpandingCard = /** @class */ (function (_super) {
tslib_1.__extends(ExpandingCard, _super);
function ExpandingCard(props) {
var _this = _super.call(this, props) || this;
_this.state = {
firstFrameRendered: false,
needsScroll: false
};
return _this;
}
ExpandingCard.prototype.componentDidMount = function () {
this._checkNeedsScroll();
};
ExpandingCard.prototype.componentWillUnmount = function () {
this._async.dispose();
};
ExpandingCard.prototype.render = function () {
var _a = this.props, targetElement = _a.targetElement, theme = _a.theme, customStyles = _a.styles, compactCardHeight = _a.compactCardHeight, directionalHintFixed = _a.directionalHintFixed, firstFocus = _a.firstFocus, expandedCardHeight = _a.expandedCardHeight;
this._styles = getStyles(theme, customStyles);
var content = (React.createElement("div", { onMouseEnter: this.props.onEnter, onMouseLeave: this.props.onLeave, onKeyDown: this._onKeyDown },
this._onRenderCompactCard(),
this._onRenderExpandedCard()));
return (React.createElement(Callout, tslib_1.__assign({}, getNativeProps(this.props, divProperties), { componentRef: this._resolveRef('_callout'), className: mergeStyles(AnimationStyles.scaleUpIn100, this._styles.root), target: targetElement, isBeakVisible: false, directionalHint: this.props.directionalHint, directionalHintFixed: directionalHintFixed, finalHeight: compactCardHeight + expandedCardHeight, minPagePadding: 24, onDismiss: this.props.onLeave, gapSpace: this.props.gapSpace }), this.props.trapFocus ?
React.createElement(FocusTrapZone, { forceFocusInsideTrap: false, isClickableOutsideFocusTrap: true, disableFirstFocus: !firstFocus }, content) :
content));
};
ExpandingCard.prototype._onKeyDown = function (ev) {
if (ev.which === 27 /* escape */) {
this.props.onLeave && this.props.onLeave(ev);
}
};
ExpandingCard.prototype._onDismiss = function (ev) {
this.props.onLeave && this.props.onLeave(ev);
};
ExpandingCard.prototype._onRenderCompactCard = function () {
return (React.createElement("div", { className: mergeStyles(this._styles.compactCard, { height: this.props.compactCardHeight + 'px' }) }, this.props.onRenderCompactCard(this.props.renderData)));
};
ExpandingCard.prototype._onRenderExpandedCard = function () {
var _this = this;
// firstFrameRendered helps in initially setting height of expanded card to 1px, even if
// mode prop is set to ExpandingCardMode.expanded on first render. This is to make sure transition animation takes place.
!this.state.firstFrameRendered && this._async.requestAnimationFrame(function () {
_this.setState({
firstFrameRendered: true
});
});
return (React.createElement("div", { className: mergeStyles(this._styles.expandedCard, this.props.mode === ExpandingCardMode.expanded && this.state.firstFrameRendered && { height: this.props.expandedCardHeight + 'px' }), ref: this._resolveRef('_expandedElem') },
React.createElement("div", { className: mergeStyles(this.state.needsScroll && this._styles.expandedCardScroll) }, this.props.onRenderExpandedCard && this.props.onRenderExpandedCard(this.props.renderData))));
};
ExpandingCard.prototype._checkNeedsScroll = function () {
var _this = this;
if (this._expandedElem) {
this._async.requestAnimationFrame(function () {
if (_this._expandedElem.scrollHeight >= _this.props.expandedCardHeight) {
_this.setState({
needsScroll: true
});
}
});
}
};
ExpandingCard.defaultProps = {
compactCardHeight: 156,
expandedCardHeight: 384,
directionalHint: 4 /* bottomLeftEdge */,
directionalHintFixed: true,
gapSpace: 0
};
tslib_1.__decorate([
autobind
], ExpandingCard.prototype, "_onKeyDown", null);
tslib_1.__decorate([
autobind
], ExpandingCard.prototype, "_onDismiss", null);
tslib_1.__decorate([
autobind
], ExpandingCard.prototype, "_onRenderCompactCard", null);
tslib_1.__decorate([
autobind
], ExpandingCard.prototype, "_onRenderExpandedCard", null);
tslib_1.__decorate([
autobind
// tslint:disable-next-line:no-unused-variable
], ExpandingCard.prototype, "_checkNeedsScroll", null);
ExpandingCard = tslib_1.__decorate([
customizable('ExpandingCard', ['theme'])
], ExpandingCard);
return ExpandingCard;
}(BaseComponent));
export { ExpandingCard };
//# sourceMappingURL=ExpandingCard.js.map