|
1 | | -import React from 'react' |
| 1 | +'use client' |
| 2 | +import React, { useEffect, useRef, useState } from 'react' |
2 | 3 | import clsx from 'clsx' |
3 | 4 |
|
4 | 5 | interface Props { |
5 | 6 | className?: string |
6 | | - loading?: 'lazy' | 'eager' |
7 | | - priority?: 'auto' | 'high' | 'low' |
| 7 | + emojis: string[] |
8 | 8 | } |
9 | 9 |
|
10 | | -export const Logo = (props: Props) => { |
11 | | - return <span className={clsx('text-2xl font-bold font-logo')}>XC@F</span> |
| 10 | +export const Logo = ({ emojis = [] }: Props) => { |
| 11 | + const [hovered, setHovered] = useState(false) |
| 12 | + const [emoji, setEmoji] = useState(emojis[0]) |
| 13 | + const indexRef = useRef(0) |
| 14 | + const timerRef = useRef<NodeJS.Timeout | null>(null) |
| 15 | + |
| 16 | + useEffect(() => { |
| 17 | + if (!hovered || !emoji) { |
| 18 | + if (timerRef.current) { |
| 19 | + clearInterval(timerRef.current) |
| 20 | + timerRef.current = null |
| 21 | + } |
| 22 | + return |
| 23 | + } |
| 24 | + |
| 25 | + timerRef.current = setInterval(() => { |
| 26 | + indexRef.current = (indexRef.current + 1) % emojis.length |
| 27 | + setEmoji(emojis[indexRef.current]) |
| 28 | + }, 250) |
| 29 | + |
| 30 | + return () => { |
| 31 | + if (timerRef.current) clearInterval(timerRef.current) |
| 32 | + } |
| 33 | + }, [hovered]) |
| 34 | + |
| 35 | + return ( |
| 36 | + <span |
| 37 | + className="text-2xl font-bold font-logo cursor-pointer select-none" |
| 38 | + onMouseEnter={() => setHovered(!!emoji)} |
| 39 | + onMouseLeave={() => setHovered(false)} |
| 40 | + > |
| 41 | + XC |
| 42 | + <span |
| 43 | + className={clsx( |
| 44 | + 'inline-flex w-[1em] justify-center leading-none', |
| 45 | + hovered && 'scale-[0.9] relative bottom-[3px] right-px', |
| 46 | + )} |
| 47 | + > |
| 48 | + {!hovered && '@'} |
| 49 | + {hovered && emoji} |
| 50 | + </span> |
| 51 | + F |
| 52 | + </span> |
| 53 | + ) |
12 | 54 | } |
0 commit comments