import React, { useEffect, useRef, useState } from 'react' import Image from 'next/image' import Typed from 'typed.js' import type { TypedOptions } from 'typed.js' import { useBreakpoint } from 'common' import { cn } from 'ui' interface Props { className?: string } const FunctionsVisual: React.FC = ({ className }) => { const typerRef = useRef(null) const isMobile = useBreakpoint('md') const [typed, setTyped] = useState(null) const [isPlaying, setIsPlaying] = useState(false) const firstString = 'deploy' const strings = [firstString, 'serve'] const disableAnimation = isPlaying || isMobile let hoverTimeoutRef: any const handleMouseEnter = () => { // Delay the animation to trigger animation only if hover is intentional hoverTimeoutRef = setTimeout(() => { triggerAnimation() }, 200) } const handleMouseLeave = () => { clearTimeout(hoverTimeoutRef) } const onComplete = () => { setIsPlaying(false) } const onBegin = () => { setIsPlaying(true) } const options: TypedOptions = { strings, typeSpeed: 40, backSpeed: 30, backDelay: 100, showCursor: false, loop: false, fadeOutDelay: 100, onBegin, onComplete, } const triggerAnimation = () => { // Disable triggering the animation on mobile and if it's already playing if (disableAnimation) return typed?.destroy() setTyped(new Typed(typerRef.current, options)) typed?.reset() typed?.start() } useEffect(() => { return () => { typed?.destroy() hoverTimeoutRef && clearTimeout(hoverTimeoutRef) } }, []) return (
Supabase Edge Functions globe Supabase Edge Functions globe
$ supabase functions {firstString}
) } export default FunctionsVisual