Spaces:
Running
Running
Download frontend/src/components/BackToTop.jsx from manojkumarsh/pdfbazaar: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/spaces/manojkumarsh/pdfbazaar/resolve/main/frontend/src/components/BackToTop.jsx
- Command line
-
hf download hf://spaces/manojkumarsh/pdfbazaar/frontend/src/components/BackToTop.jsx
-
curl -L -o BackToTop.jsx https://huggingface.co/spaces/manojkumarsh/pdfbazaar/resolve/main/frontend/src/components/BackToTop.jsx
1.65 kB
| import React, { useState, useEffect } from 'react'; | |
| import { ChevronUp } from 'lucide-react'; | |
| const BackToTop = () => { | |
| const [visible, setVisible] = useState(false); | |
| useEffect(() => { | |
| const toggleVisibility = () => { | |
| if (window.pageYOffset > 300) { | |
| setVisible(true); | |
| } else { | |
| setVisible(false); | |
| } | |
| }; | |
| window.addEventListener('scroll', toggleVisibility); | |
| return () => window.removeEventListener('scroll', toggleVisibility); | |
| }, []); | |
| const scrollToTop = () => { | |
| window.scrollTo({ | |
| top: 0, | |
| behavior: 'smooth' | |
| }); | |
| }; | |
| if (!visible) return null; | |
| return ( | |
| <button | |
| onClick={scrollToTop} | |
| style={{ | |
| position: 'fixed', | |
| bottom: '30px', | |
| right: '30px', | |
| width: '50px', | |
| height: '50px', | |
| borderRadius: '50%', | |
| background: 'var(--primary)', | |
| color: 'white', | |
| border: 'none', | |
| boxShadow: '0 4px 15px rgba(79, 70, 229, 0.4)', | |
| cursor: 'pointer', | |
| display: 'flex', | |
| alignItems: 'center', | |
| justifyContent: 'center', | |
| zIndex: 1000, | |
| transition: 'all 0.3s ease' | |
| }} | |
| onMouseEnter={(e) => e.target.style.transform = 'scale(1.1)'} | |
| onMouseLeave={(e) => e.target.style.transform = 'scale(1)'} | |
| > | |
| <ChevronUp size={24} /> | |
| </button> | |
| ); | |
| }; | |
| export default BackToTop; | |