office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
83 lines • 4.36 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, autobind, css, divProperties, getNativeProps, getId, assign, hasOverflow } from '../../Utilities';
import { TooltipOverflowMode } from './TooltipHost.types';
import { Tooltip } from './Tooltip';
import { TooltipDelay } from './Tooltip.types';
import * as stylesImport from './TooltipHost.scss';
var styles = stylesImport;
var TooltipHost = /** @class */ (function (_super) {
tslib_1.__extends(TooltipHost, _super);
// Constructor
function TooltipHost(props) {
var _this = _super.call(this, props) || this;
_this.state = {
isTooltipVisible: false
};
return _this;
}
// Render
TooltipHost.prototype.render = function () {
var _a = this.props, calloutProps = _a.calloutProps, tooltipProps = _a.tooltipProps, content = _a.content, children = _a.children, directionalHint = _a.directionalHint, directionalHintForRTL = _a.directionalHintForRTL, delay = _a.delay, id = _a.id, _b = _a.setAriaDescribedBy, setAriaDescribedBy = _b === void 0 ? true : _b, hostClassName = _a.hostClassName;
var isTooltipVisible = this.state.isTooltipVisible;
var tooltipId = id || getId('tooltip');
return (React.createElement("div", tslib_1.__assign({ className: css('ms-TooltipHost', styles.host, hostClassName), ref: this._resolveRef('_tooltipHost') }, { onFocusCapture: this._onTooltipMouseEnter }, { onBlurCapture: this._onTooltipMouseLeave }, { onMouseEnter: this._onTooltipMouseEnter, onMouseLeave: this._onTooltipMouseLeave, "aria-describedby": setAriaDescribedBy && isTooltipVisible && content ? tooltipId : undefined }),
children,
isTooltipVisible && (React.createElement(Tooltip, tslib_1.__assign({ id: tooltipId, delay: delay, content: content, targetElement: this._getTargetElement(), directionalHint: directionalHint, directionalHintForRTL: directionalHintForRTL, calloutProps: assign(calloutProps, { onDismiss: this._onTooltipCallOutDismiss }) }, getNativeProps(this.props, divProperties), tooltipProps)))));
};
TooltipHost.prototype._getTargetElement = function () {
var overflowMode = this.props.overflowMode;
// Select target element based on overflow mode. For parent mode, you want to position the tooltip relative
// to the parent element, otherwise it might look off.
if (overflowMode !== undefined) {
switch (overflowMode) {
case TooltipOverflowMode.Parent:
return this._tooltipHost.parentElement;
case TooltipOverflowMode.Self:
return this._tooltipHost;
}
}
return this._tooltipHost;
};
// Show Tooltip
TooltipHost.prototype._onTooltipMouseEnter = function (ev) {
var overflowMode = this.props.overflowMode;
if (overflowMode !== undefined) {
var overflowElement = this._getTargetElement();
if (overflowElement && !hasOverflow(overflowElement)) {
return;
}
}
this._toggleTooltip(true);
};
// Hide Tooltip
TooltipHost.prototype._onTooltipMouseLeave = function (ev) {
this._toggleTooltip(false);
};
// Hide Tooltip
TooltipHost.prototype._onTooltipCallOutDismiss = function () {
this._toggleTooltip(false);
};
TooltipHost.prototype._toggleTooltip = function (isTooltipVisible) {
var _this = this;
this.setState({ isTooltipVisible: isTooltipVisible }, function () { return _this.props.onTooltipToggle &&
_this.props.onTooltipToggle(_this.state.isTooltipVisible); });
};
TooltipHost.defaultProps = {
delay: TooltipDelay.medium
};
tslib_1.__decorate([
autobind
], TooltipHost.prototype, "_onTooltipMouseEnter", null);
tslib_1.__decorate([
autobind
], TooltipHost.prototype, "_onTooltipMouseLeave", null);
tslib_1.__decorate([
autobind
], TooltipHost.prototype, "_onTooltipCallOutDismiss", null);
return TooltipHost;
}(BaseComponent));
export { TooltipHost };
//# sourceMappingURL=TooltipHost.js.map