Skip to content

Instantly share code, notes, and snippets.

@fResult
Created March 16, 2023 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fResult/24edb41b2858044ed6ef49bed887b182 to your computer and use it in GitHub Desktop.
Save fResult/24edb41b2858044ed6ef49bed887b182 to your computer and use it in GitHub Desktop.
import IconFacebook from '../components/icons/IconFacebook'
import IconTwitter from '../components/icons/IconTwitter'
function YourPage() {
const [hoveredIcons, setHoveredIcons] = useState({
fb: false,
tw: false,
ig: false,
pt: false,
})
/**
* @param { 'fb' | 'tw' | 'ig' | 'pt' } icon
* @returns { void }
*/
function handleHoverIcons(icon) {
setHoveredIcons({
...hoveredIcons,
[icon]: !hoveredIcons[icon],
})
}
return (
<>
<header>
HEADER
</header>
<main>
CONTENT
</main>
<footer>
<button
aria-label="Facebook"
// อันนี้ท่ากึ่งๆ hard code
onMouseEnter={() => setHoveredIcons({ ...hoveredIcons, fb: true })}
onMouseLeave={() => setHoveredIcons({ ...hoveredIcons, fb: false })}
>
<IconFacebook fill={hoveredIcons.fb ? '#2E89FF' : 'white'} />
</button>
<button
aria-label="Twitter"
// อันนี้ powerful กว่า
onMouseEnter={() => handleHoverIcons('tw')}
onMouseLeave={() => handleHoverIcons('tw')}
>
<IconTwitter fill={hoveredIcons.tw ? '#1D9BF0' : 'white'} />
</button>
<button
aria-label="Pinterest"
onMouseEnter={() => handleHoverIcons('ig')}
onMouseLeave={() => handleHoverIcons('ig')}
>
<IconPinterest fill={hoveredIcons.ig ? 'orangered' : 'white'} />
</button>
<button
aria-label="Pinterest"
onMouseEnter={() => handleHoverIcons('pt')}
onMouseLeave={() => handleHoverIcons('pt')}
>
<IconPinterest fill={hoveredIcons.pt ? 'pink' : 'white'} />
</button>
</footer>
</>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment