Download react-spring/docs/app/components/Code/H.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/components/Code/H.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/components/Code/H.tsx
-
curl -L -o H.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/components/Code/H.tsx
1.12 kB
| interface HProps { | |
| index: number | |
| id: string | |
| } | |
| export const H = ({ index, id, ...props }: HProps) => { | |
| const getHighlightedWords = (): [ | |
| targetIndex: number[], | |
| allHighlightWords: Element[], | |
| ] => { | |
| const codeBlock = document.getElementById(id) | |
| if (!codeBlock) return [[], []] | |
| const allHighlightWords = codeBlock.querySelectorAll( | |
| '.highlight-word' | |
| ) as unknown as Element[] | |
| const targetIndex = [index - 1] | |
| if (Math.max(...targetIndex) >= allHighlightWords.length) return [[], []] | |
| else return [targetIndex, allHighlightWords] | |
| } | |
| const handleMouseEnter = () => { | |
| const [targetIndex, allHighlightWords] = getHighlightedWords() | |
| targetIndex.forEach(i => allHighlightWords[i].classList.add('on')) | |
| } | |
| const handleMouseLeave = () => { | |
| const [targetIndex, allHighlightWords] = getHighlightedWords() | |
| targetIndex.forEach(i => allHighlightWords[i].classList.remove('on')) | |
| } | |
| return ( | |
| <code | |
| onMouseLeave={handleMouseLeave} | |
| onMouseEnter={handleMouseEnter} | |
| style={{ | |
| cursor: 'pointer', | |
| }} | |
| {...props} | |
| /> | |
| ) | |
| } | |