|
| 1 | +<div align="center"> |
| 2 | + |
1 | 3 | # React UI ScrollSpy |
| 4 | + |
| 5 | +[](https://npmjs.com/package/react-ui-scrollspy) [](https://npmjs.com/package/react-ui-scrollspy) |
| 6 | +[](https://raw.githubusercontent.com/pettiboy/react-ui-scrollspy/main/LICENSE) |
| 7 | +[](https://github.com/pettiboy/react-ui-scrollspy/pulls) |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +</div> |
| 14 | + |
| 15 | +## ✨ Installation |
| 16 | + |
| 17 | +```bash |
| 18 | +npm install --save react-ui-scrollspy |
| 19 | +``` |
| 20 | + |
| 21 | +OR |
| 22 | + |
| 23 | +```bash |
| 24 | +yarn add react-ui-scrollspy |
| 25 | +``` |
| 26 | + |
| 27 | +## ⚙️ Getting started |
| 28 | + |
| 29 | +1. In your navigation component |
| 30 | + |
| 31 | +```tsx |
| 32 | +<div> |
| 33 | + <p data-to-scrollspy-id="first">Section 1</p> |
| 34 | + <p data-to-scrollspy-id="second">Section 2</p> |
| 35 | +</div> |
| 36 | +``` |
| 37 | + |
| 38 | +2. Wrap the elements you want to spy on in the `<ScrollSpy>` component. |
| 39 | + |
| 40 | +```tsx |
| 41 | +import ScrollSpy from "react-ui-scrollspy"; |
| 42 | + |
| 43 | +<ScrollSpy> |
| 44 | + <div id="first"> |
| 45 | + Lorem ipsum dolor sit amet consectetur adipisicing elit. Aut dolores |
| 46 | + veritatis doloremque fugit. Soluta aperiam atque inventore deleniti, |
| 47 | + voluptatibus non fuga eos magni natus vel, rerum excepturi expedita. |
| 48 | + Tempore, vero! |
| 49 | + </div> |
| 50 | + <div id="second"> |
| 51 | + Lorem ipsum dolor sit amet consectetur adipisicing elit. Aut dolores |
| 52 | + veritatis doloremque fugit. Soluta aperiam atque inventore deleniti, |
| 53 | + voluptatibus non fuga eos magni natus vel, rerum excepturi expedita. |
| 54 | + Tempore, vero! |
| 55 | + </div> |
| 56 | +</ScrollSpy>; |
| 57 | +``` |
| 58 | + |
| 59 | +3. Write styles for when the navigation element which is active in your `index.css` |
| 60 | + |
| 61 | +```css |
| 62 | +.active-scroll-spy { |
| 63 | + background-color: yellowgreen; |
| 64 | + border-radius: 15px; |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +## 💡 Props |
| 69 | + |
| 70 | +| Attributes | Type | Description | Default | Required | |
| 71 | +| :---------------- | :----------------------------------------- | :--------------------------------------------------------------------------------------------------------------------- | :------ | :------- | |
| 72 | +| `scrollThrottle` | `number` | in `milliseconds` to throttle the `onscroll` event. Lower the number, better the response, higher the performance cost | 300 | no | |
| 73 | +| `children` | `ReactNode` | - | - | yes | |
| 74 | +| `navContainerRef` | `MutableRefObject<HTMLDivElement \| null>` | `ref` to your navigation container containing items with `data-to-scrollspy-id` attributes | - | no | |
| 75 | + |
| 76 | +## 📝 Authors |
| 77 | + |
| 78 | +- Hussain Pettiwala ([@pettiboy](https://github.com/pettiboy)) |
0 commit comments