@atlaskit/tooltip
Version:
A tooltip is a floating, non-actionable label used to explain a user interface element or feature.
126 lines • 3.56 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.show = void 0;
var shared_schedule_1 = require("./shared-schedule");
var active = null;
function show(entry) {
var phase = 'waiting-to-show';
function isActive() {
return Boolean(active && active.entry === entry);
}
function cleanup() {
if (isActive()) {
shared_schedule_1.clearScheduled();
active = null;
}
}
function done() {
if (isActive()) {
entry.done();
}
phase = 'done';
cleanup();
}
function immediatelyHideAndDone() {
if (isActive()) {
entry.hide({ isImmediate: true });
}
done();
}
function keep() {
if (!isActive()) {
return;
}
// aborting a wait to hide
if (phase === 'waiting-to-hide') {
phase = 'shown';
shared_schedule_1.clearScheduled();
return;
}
// aborting hide animation
if (phase === 'hide-animating') {
phase = 'shown';
shared_schedule_1.clearScheduled();
entry.show({ isImmediate: false });
return;
}
}
function requestHide(_a) {
var isImmediate = _a.isImmediate;
if (!isActive()) {
return;
}
// If we were not showing yet anyway; finish straight away
if (phase === 'waiting-to-show') {
immediatelyHideAndDone();
return;
}
// already waiting to hide
if (phase === 'waiting-to-hide') {
return;
}
if (isImmediate) {
immediatelyHideAndDone();
return;
}
phase = 'waiting-to-hide';
shared_schedule_1.scheduleTimeout(function () {
phase = 'hide-animating';
entry.hide({ isImmediate: false });
}, entry.delay);
}
function finishHideAnimation() {
if (isActive() && phase === 'hide-animating') {
done();
}
}
function isVisible() {
return (phase === 'shown' ||
phase === 'waiting-to-hide' ||
phase === 'hide-animating');
}
function getInitialMouse() {
if (entry.source.type === 'mouse') {
return entry.source.mouse;
}
return null;
}
function start() {
var showImmediately = Boolean(active && active.isVisible());
// If there was an active tooltip; we tell it to remove itself at once!
if (active) {
shared_schedule_1.clearScheduled();
active.entry.hide({ isImmediate: true });
active.entry.done();
active = null;
}
// this tooltip is now the active tooltip
active = {
entry: entry,
isVisible: isVisible,
};
function show() {
phase = 'shown';
entry.show({ isImmediate: showImmediately });
}
if (showImmediately) {
show();
return;
}
phase = 'waiting-to-show';
shared_schedule_1.scheduleTimeout(show, entry.delay);
}
// let's get started!
start();
var result = {
keep: keep,
abort: cleanup,
isActive: isActive,
requestHide: requestHide,
finishHideAnimation: finishHideAnimation,
getInitialMouse: getInitialMouse,
};
return result;
}
exports.show = show;
//# sourceMappingURL=tooltip-manager.js.map
;