feat: add tooltip to scroll button

This commit is contained in:
MAZE 2023-11-01 17:42:23 +03:30
parent 262bb1a9c6
commit d4401faaff
2 changed files with 15 additions and 12 deletions

View File

@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
import { BiUpArrowAlt } from 'react-icons/bi/index'; import { BiUpArrowAlt } from 'react-icons/bi/index';
import { motion, AnimatePresence } from 'framer-motion'; import { motion, AnimatePresence } from 'framer-motion';
import { Tooltip } from '@/components/tooltip';
import { mix, fade, slideY } from '@/lib/motion'; import { mix, fade, slideY } from '@/lib/motion';
import styles from './scroll-to-top.module.css'; import styles from './scroll-to-top.module.css';
@ -32,17 +33,19 @@ export function ScrollToTop() {
return ( return (
<AnimatePresence> <AnimatePresence>
{isVisible && ( {isVisible && (
<motion.button <Tooltip content="Scroll to top" hideDelay={0} showDelay={0}>
animate="show" <motion.button
aria-label="Scroll to top" animate="show"
className={styles.button} aria-label="Scroll to top"
exit="hidden" className={styles.button}
initial="hidden" exit="hidden"
variants={variants} initial="hidden"
onClick={scrollToTop} variants={variants}
> onClick={scrollToTop}
<BiUpArrowAlt /> >
</motion.button> <BiUpArrowAlt />
</motion.button>
</Tooltip>
)} )}
</AnimatePresence> </AnimatePresence>
); );

View File

@ -41,7 +41,7 @@ export function Tooltip({
placement: computedPlacement, placement: computedPlacement,
refs, refs,
} = useFloating({ } = useFloating({
middleware: [offset(12), flip(), shift()], middleware: [offset(12), flip(), shift({ padding: 8 })],
onOpenChange: setIsTooltipOpen, onOpenChange: setIsTooltipOpen,
open: isTooltipOpen, open: isTooltipOpen,
placement: placement, placement: placement,