UNPKG

react-flyup-button

Version:

React component to scroll to the top of the page

84 lines (69 loc) โ€ข 3.54 kB
# react-scroll-top-button A simple and customizable React button that smoothly scrolls the page to the top when clicked. --- ## โœจ Features - ๐Ÿงฉ Fully customizable via props - ๐Ÿ“ฑ Flexible positioning (left, right, center) - ๐Ÿ–ฑ๏ธ Optional smooth scroll - ๐ŸŽจ Style with your own className (Tailwind or bootstrap) or inline styles - ๐Ÿชถ Lightweight and easy to integrate ## ๐Ÿ“ฆ Installation ```bash npm install react-flyup-button # or yarn add react-flyup-button ``` ## ๐Ÿš€ Usage ```js import React from "react"; import ScrollToTopButton from "react-flyup-button"; function App() { return ( <div> {/* Your page content */} <ScrollToTopButton /> </div> ); } export default App; ``` ## โš™๏ธ Props (optional) | Prop | Type | Default | Description | | ------------------- | ----------------------------------- | ------------------ | ------------------------------------------------------ | | `className` | `string` | `""` | Custom class name for the button | | `position` | `"left"` \| `"right"` \| `"center"` | `"right"` | Button alignment at the bottom | | `bottom` | `number` | `40` | Distance from bottom (in pixels) | | `left` | `number` | `40` (if left) | Distance from left (in pixels) if position is `"left"` | | `width` | `number` | `50` | Button width in pixels | | `height` | `number` | `50` | Button height in pixels | | `borderRadius` | `number` | `25` | Border radius (for rounded button) | | `backgroundColor` | `string` | `"#333"` | Background color | | `borderColor` | `string` | `"#000"` | Border color | | `borderWidth` | `number` | `1` | Border width (in pixels) | | `cursor` | `string` | `"pointer"` | Cursor style on hover | | `displayAt` | `number` | `300` | Scroll distance (px) after which button appears | | `animationDuration` | `number` | `300` | Animation duration for scroll (ms) | | `smoothScroll` | `boolean` | `true` | Enable smooth scroll | | `children` | `React.ReactNode` | `โ–ฒ` (default icon) | Custom button content (icon/text/etc.) | ## ๐Ÿงช Example with custom props ```js function App() { return ( <div> <ScrollToTopButton position="left" bottom={50} left={20} width={60} height={60} borderRadius={10} backgroundColor="#007BFF" borderColor="#0056b3" borderWidth={2} smoothScroll={true} displayAt={400} /> </div> ); } ```