Skip to content

Commit

Permalink
style: add text animation
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Oct 30, 2023
1 parent 5fecd38 commit 7810d21
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import {
} from '@floating-ui/react';
import { motion, AnimatePresence } from 'framer-motion';

import { slideX, slideY, mix, fade } from '@/lib/motion';

import styles from './tooltip.module.css';

interface TooltipProps {
children: JSX.Element;
content: React.ReactNode;
content: string;
hideDelay?: number;
placement?: Placement;
showDelay?: number;
Expand Down Expand Up @@ -62,21 +64,19 @@ export function Tooltip({
role,
]);

const translate = {
bottom: { translateY: -5 },
left: { translateX: 5 },
right: { translateX: -5 },
top: { translateY: 5 },
const slide = {
bottom: slideY(-5),
left: slideX(5),
right: slideX(-5),
top: slideY(5),
}[
computedPlacement.includes('-')
? computedPlacement.split('-')[0]
: computedPlacement
];

const variants = {
hidden: { opacity: 0, ...translate },
show: { opacity: 1, translateX: 0, translateY: 0 },
};
const variants = mix(fade(), slide!);
const textVariants = fade();

return (
<>
Expand All @@ -98,7 +98,18 @@ export function Tooltip({
initial="hidden"
variants={variants}
>
{content}
<AnimatePresence initial={false} mode="wait">
<motion.span
animate="show"
exit="hidden"
initial="hidden"
key={content}
transition={{ duration: 0.15 }}
variants={textVariants}
>
{content}
</motion.span>
</AnimatePresence>
</motion.div>
</div>
)}
Expand Down

0 comments on commit 7810d21

Please sign in to comment.