Download wp-calypso/client/components/animated-icon/index.jsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 852 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/animated-icon/index.jsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/components/animated-icon/index.jsx
-
curl -L -o index.jsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/animated-icon/index.jsx
852 Bytes
| import clsx from 'clsx'; | |
| import lottie from 'lottie-web/build/player/lottie_light'; | |
| import { useEffect, useRef } from 'react'; | |
| const AnimatedIcon = ( { icon, className } ) => { | |
| const iconEl = useRef(); | |
| useEffect( () => { | |
| const reducedMotion = window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches; | |
| const animation = lottie.loadAnimation( { | |
| container: iconEl.current, | |
| renderer: 'svg', | |
| loop: false, | |
| autoplay: ! reducedMotion, | |
| path: icon, | |
| rendererSettings: { | |
| viewBoxOnly: true, | |
| }, | |
| } ); | |
| if ( reducedMotion ) { | |
| animation.addEventListener( 'config_ready', () => { | |
| animation.goToAndPlay( animation.totalFrames, true ); | |
| } ); | |
| } | |
| return () => animation.destroy(); | |
| }, [ icon ] ); | |
| return <div ref={ iconEl } className={ clsx( 'animated-icon', className ) }></div>; | |
| }; | |
| export default AnimatedIcon; | |