import { AnimatePresence, motion } from 'framer-motion'; import { devices } from '../consts/devices'; import { IDevice } from '../types/IDevice'; import { Title } from './ui/Title'; import { useEffect, useRef, useState } from 'react'; import { useHover, useOnClickOutside } from 'usehooks-ts'; import { ChevronUpIcon } from './icons/ChevronUpIcon'; import { ChevronDownIcon } from './icons/ChevronDownIcon'; export function Devices() { return (
Работаем с <span className="text-gradient"> любыми типами оборудования</span> <br /> и предложим лучшее мультимедийное оснащение
{devices.map((device, index) => ( ))}
{devices.map(device => ( ))}
); } function DesktopDevice({ title, description, img, number, }: IDevice & { number: number; }) { const root = useRef(null); const descriptionRef = useRef(null); const [descriptionHeight, setDescriptionHeight] = useState(0); const hovered = useHover(root); useEffect(() => { setDescriptionHeight(descriptionRef.current?.clientHeight ?? 0); }, [descriptionRef, hovered]); return (

{title}

{hovered && ( {description.map(paragraph => (

{paragraph}

))}
)}
{hovered && ( )}

[0{number}]

); } function Device({ title, description, img }: IDevice) { const [expanded, setExpanded] = useState(false); const [descriptionHeight, setDescriptionHeight] = useState(0); const [imgHeight, setImgHeight] = useState(0); const root = useRef(null); const descriptionRef = useRef(null); const imgRef = useRef(null); useEffect(() => { if (!imgRef.current) return; imgRef.current!.onload = () => setImgHeight(imgRef.current?.clientHeight ?? 0); }, [imgRef, expanded]); useEffect(() => { setDescriptionHeight(descriptionRef.current?.clientHeight ?? 0); }, [descriptionRef, expanded]); useOnClickOutside(root, () => setExpanded(false), 'mouseup'); return ( setExpanded(prev => !prev)} className="py-4 space-y-6 border-t last:border-b border-[#3D425C] relative select-none" >

{title}

{expanded ? : }
{expanded && ( {description.map(paragraph => (

{paragraph}

))}
)}
{expanded && ( )}
); }