Skip to content

Commit

Permalink
chore: add highlighting of subtitles on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
ratmirslv committed Jan 27, 2024
1 parent 7c46619 commit c0d4f59
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions components/Word.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Popover, Text } from '@mantine/core'
import { useDisclosure } from '@mantine/hooks'
import { useRef } from 'react'

import TranslateWordPopup from './TranslateWordPopup'

Expand All @@ -12,8 +13,23 @@ interface WordProps {

function Word(props: WordProps) {
const [opened, { close, open }] = useDisclosure(false)

const wordRef = useRef<HTMLDivElement>(null)
const debouncedOpen = useDebounce(opened, 400)

const handleMouseEnter = () => {
if (wordRef.current) {
wordRef.current.style.color = '#359dff'
}
open()
}

const handleMouseLeave = () => {
if (wordRef.current) {
wordRef.current.style.color = '#ffffff'
}
close()
}

return (
<Popover
width={200}
Expand All @@ -22,7 +38,13 @@ function Word(props: WordProps) {
offset={{ mainAxis: 0, crossAxis: 5 }}
>
<Popover.Target>
<Text span size="xl" onMouseEnter={open} onMouseLeave={close}>
<Text
span
size="xl"
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
ref={wordRef}
>
{`${props.word} `}
<Popover.Dropdown>
<TranslateWordPopup word={clearWord(props.word)} />
Expand Down

0 comments on commit c0d4f59

Please sign in to comment.