Skip to content

Commit

Permalink
refactor(tooltip): remove animejs
Browse files Browse the repository at this point in the history
  • Loading branch information
wuda-io committed Dec 15, 2023
1 parent 9534e8a commit 2220700
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
24 changes: 16 additions & 8 deletions sass/components/_tooltip.scss
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
.material-tooltip {
padding: 10px 8px;
font-size: 1rem;
z-index: 2000;
border-radius: 2px;
// font-family: var(--md-sys-typescale-body-small-font-family-name);
padding: 0 8px;
border-radius: 4px;

background-color: $tooltip-bg-color;
color: $tooltip-font-color;
min-height: 36px;
line-height: 120%;

font-size: var(--md-sys-typescale-body-small-font-size);
line-height: vat(--md-sys-typescale-body-small-line-height);
min-height: 24px;
opacity: 0;
position: absolute;
text-align: center;

position: absolute;
max-width: calc(100% - 4px);
overflow: hidden;
left: 0;
top: 0;
pointer-events: none;

display: flex;
align-items: center;

visibility: hidden;
background-color: $tooltip-bg-color;
z-index: 2000;
}

.backdrop {
Expand Down
4 changes: 2 additions & 2 deletions sass/components/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ $toast-action-color: #eeff41;
// 20. Tooltips
// ==========================================================================

$tooltip-bg-color: var(--tooltip-background-color) !default;
$tooltip-font-color: var(--tooltip-font-color) !default;
$tooltip-bg-color: var(--md-sys-color-inverse-surface) !default;
$tooltip-font-color: var(--md-sys-color-inverse-on-surface) !default;


// 21. Typography
Expand Down
31 changes: 20 additions & 11 deletions src/tooltip.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import anim from "animejs";

import { Utils } from "./utils";
import { Bounding } from "./bounding";
import { Component, BaseOptions, InitElements, MElement } from "./component";
Expand Down Expand Up @@ -299,18 +297,28 @@ export class Tooltip extends Component<TooltipOptions> {
_animateIn() {
this._positionTooltip();
this.tooltipEl.style.visibility = 'visible';
anim.remove(this.tooltipEl);
anim({
targets: this.tooltipEl,
opacity: this.options.opacity || 1,
translateX: this.xMovement,
translateY: this.yMovement,
duration: this.options.inDuration,
easing: 'easeOutCubic'
});
const duration = this.options.inDuration;
// easeOutCubic
this.tooltipEl.style.transition = `
transform ${duration}ms ease-out,
opacity ${duration}ms ease-out`;
setTimeout(() => {
this.tooltipEl.style.transform = `translateX(${this.xMovement}px) translateY(${this.yMovement}px)`;
this.tooltipEl.style.opacity = (this.options.opacity || 1).toString();
}, 1);
}

_animateOut() {
const duration = this.options.outDuration;
// easeOutCubic
this.tooltipEl.style.transition = `
transform ${duration}ms ease-out,
opacity ${duration}ms ease-out`;
setTimeout(() => {
this.tooltipEl.style.transform = `translateX(0px) translateY(0px)`;
this.tooltipEl.style.opacity = '0';
}, 1);
/*
anim.remove(this.tooltipEl);
anim({
targets: this.tooltipEl,
Expand All @@ -320,6 +328,7 @@ export class Tooltip extends Component<TooltipOptions> {
duration: this.options.outDuration,
easing: 'easeOutCubic'
});
*/
}

_handleMouseEnter = () => {
Expand Down

0 comments on commit 2220700

Please sign in to comment.