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,6 +33,7 @@ export function ScrollToTop() {
return ( return (
<AnimatePresence> <AnimatePresence>
{isVisible && ( {isVisible && (
<Tooltip content="Scroll to top" hideDelay={0} showDelay={0}>
<motion.button <motion.button
animate="show" animate="show"
aria-label="Scroll to top" aria-label="Scroll to top"
@ -43,6 +45,7 @@ export function ScrollToTop() {
> >
<BiUpArrowAlt /> <BiUpArrowAlt />
</motion.button> </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,