Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

add animation for tooltip

Blue Mousef46c1e2d892e
diff --git a/web/app/styles/tailwind.css b/web/app/styles/tailwind.css
index 404e88350..063572cc5 100644
--- a/web/app/styles/tailwind.css
+++ b/web/app/styles/tailwind.css
@@ -78,6 +78,142 @@
}
}
+/* Tooltip animations */
+@keyframes tooltipSlideDownAndFadeIn {
+ 0% {
+ opacity: 0;
+ transform: translateY(-4px);
+ }
+ 100% {
+ opacity: 1;
+ transform: translateY(0);
+ }
+}
+
+@keyframes tooltipSlideUpAndFadeIn {
+ 0% {
+ opacity: 0;
+ transform: translateY(4px);
+ }
+ 100% {
+ opacity: 1;
+ transform: translateY(0);
+ }
+}
+
+@keyframes tooltipSlideLeftAndFadeIn {
+ 0% {
+ opacity: 0;
+ transform: translateX(4px);
+ }
+ 100% {
+ opacity: 1;
+ transform: translateX(0);
+ }
+}
+
+@keyframes tooltipSlideRightAndFadeIn {
+ 0% {
+ opacity: 0;
+ transform: translateX(-4px);
+ }
+ 100% {
+ opacity: 1;
+ transform: translateX(0);
+ }
+}
+
+@keyframes tooltipSlideDownAndFadeOut {
+ 0% {
+ opacity: 1;
+ transform: translateY(0);
+ }
+ 100% {
+ opacity: 0;
+ transform: translateY(-4px);
+ }
+}
+
+@keyframes tooltipSlideUpAndFadeOut {
+ 0% {
+ opacity: 1;
+ transform: translateY(0);
+ }
+ 100% {
+ opacity: 0;
+ transform: translateY(4px);
+ }
+}
+
+@keyframes tooltipSlideLeftAndFadeOut {
+ 0% {
+ opacity: 1;
+ transform: translateX(0);
+ }
+ 100% {
+ opacity: 0;
+ transform: translateX(4px);
+ }
+}
+
+@keyframes tooltipSlideRightAndFadeOut {
+ 0% {
+ opacity: 1;
+ transform: translateX(0);
+ }
+ 100% {
+ opacity: 0;
+ transform: translateX(-4px);
+ }
+}
+
+@layer utilities {
+ /* Base class to enable smooth transform/opacity animations */
+ .tooltip-content {
+ will-change: transform, opacity;
+ }
+
+ /* Open animations (handle both delayed and instant) */
+ .tooltip-content[data-state='delayed-open'][data-side='top'],
+ .tooltip-content[data-state='instant-open'][data-side='top'] {
+ animation: tooltipSlideUpAndFadeIn var(--default-transition-duration, 250ms)
+ cubic-bezier(0.16, 1, 0.3, 1);
+ }
+ .tooltip-content[data-state='delayed-open'][data-side='bottom'],
+ .tooltip-content[data-state='instant-open'][data-side='bottom'] {
+ animation: tooltipSlideDownAndFadeIn var(--default-transition-duration, 250ms)
+ cubic-bezier(0.16, 1, 0.3, 1);
+ }
+ .tooltip-content[data-state='delayed-open'][data-side='left'],
+ .tooltip-content[data-state='instant-open'][data-side='left'] {
+ animation: tooltipSlideLeftAndFadeIn var(--default-transition-duration, 250ms)
+ cubic-bezier(0.16, 1, 0.3, 1);
+ }
+ .tooltip-content[data-state='delayed-open'][data-side='right'],
+ .tooltip-content[data-state='instant-open'][data-side='right'] {
+ animation: tooltipSlideRightAndFadeIn var(--default-transition-duration, 250ms)
+ cubic-bezier(0.16, 1, 0.3, 1);
+ }
+
+ /* Close animations */
+ .tooltip-content[data-state='closed'][data-side='top'] {
+ animation: tooltipSlideUpAndFadeOut var(--default-transition-duration, 250ms)
+ cubic-bezier(0.16, 1, 0.3, 1);
+ }
+ .tooltip-content[data-state='closed'][data-side='bottom'] {
+ animation: tooltipSlideDownAndFadeOut var(--default-transition-duration, 250ms)
+ cubic-bezier(0.16, 1, 0.3, 1);
+ }
+ .tooltip-content[data-state='closed'][data-side='left'] {
+ animation: tooltipSlideLeftAndFadeOut var(--default-transition-duration, 250ms)
+ cubic-bezier(0.16, 1, 0.3, 1);
+ }
+ .tooltip-content[data-state='closed'][data-side='right'] {
+ animation: tooltipSlideRightAndFadeOut var(--default-transition-duration, 250ms)
+ cubic-bezier(0.16, 1, 0.3, 1);
+ }
+}
+
@layer base {
*,
::after,
diff --git a/web/app/ui/Tooltip.tsx b/web/app/ui/Tooltip.tsx
index 0aa295a71..e8c75a807 100644
--- a/web/app/ui/Tooltip.tsx
+++ b/web/app/ui/Tooltip.tsx
@@ -1,8 +1,9 @@
import * as TooltipPrimitive from '@radix-ui/react-tooltip'
-import cx from 'clsx'
import { CircleHelpIcon } from 'lucide-react'
import React, { forwardRef, memo } from 'react'
+import { cn } from '~/utils/generic'
+
const TooltipProvider = TooltipPrimitive.Provider
const TooltipRoot = TooltipPrimitive.Root
@@ -16,13 +17,10 @@ const TooltipContent = forwardRef<
<TooltipPrimitive.Portal>
<TooltipPrimitive.Content
ref={ref}
+ forceMount
sideOffset={sideOffset}
- className={cx(
- // Animation does not work
- // 'transform-gpu transition-all ease-in-out',
- // 'data-[state=closed]:scale-90 data-[state=delayed-open]:scale-100',
- // 'data-[state=closed]:opacity-0 data-[state=delayed-open]:opacity-100',
- 'z-50 max-w-80 overflow-hidden rounded-md bg-slate-800 px-3 py-1.5 text-xs text-white ring-1 ring-slate-900/80',
+ className={cn(
+ 'tooltip-content z-50 max-w-80 overflow-hidden rounded-md bg-slate-800 px-3 py-1.5 text-xs text-white ring-1 ring-slate-900/80',
className,
)}
{...props}