UNPKG

reactbits-mcp-server

Version:

MCP Server for React Bits - Access 99+ React components with animations, backgrounds, and UI elements

58 lines (51 loc) β€’ 1.68 kB
import { Button, Icon } from "@chakra-ui/react"; import { useState, useEffect } from "react"; import { FiArrowUp } from "react-icons/fi"; import { toast } from 'sonner' const BackToTopButton = () => { const [visible, setVisible] = useState(false); const messages = [ '🐴 Country roads, take me home!', 'πŸš€ To infinity and beyond!', '🦾 Get to the choppa!', 'πŸš• Grove Street, home...', 'πŸ‰ Fus Ro Dah!', 'πŸ„ The princess is in another castle!', 'πŸ¦Έβ€β™‚οΈ Avengers, assemble!', 'πŸ—‘οΈ It’s dangerous to go alone! Take this.', 'πŸ“œ A wizard is never late.', 'πŸ’ Foul Tarnished, in search of the Elden Ring!', '🐊 See you later, alligator.', 'πŸ”₯ Dracarys!' ]; const getRandomMessage = (messages) => messages[Math.floor(Math.random() * messages.length)]; const scrollToTop = () => { window.scrollTo(0, 0); toast(getRandomMessage(messages)); } useEffect(() => { const onScroll = () => setVisible(window.scrollY > 500); window.addEventListener("scroll", onScroll); return () => window.removeEventListener("scroll", onScroll); }, []); return ( <Button fontWeight={500} rounded='xl' py={4} right='2.3em' position='fixed' zIndex={98} boxShadow="10px 0 25px rgba(0, 0, 6, 1)" transition="0.3s ease" className="back-to-top" opacity={visible ? 1 : 0} bottom={visible ? '2.5em' : '1em'} cursor={visible ? 'pointer' : 'default'} onClick={() => visible && scrollToTop()} > <Icon as={FiArrowUp} color="#fff" boxSize={4}/> </Button> ); }; export default BackToTopButton;