|
24 | 24 | yarn add react-ui-scrollspy |
25 | 25 | ``` |
26 | 26 |
|
27 | | -## ⚙️ Getting started |
| 27 | +## ⚙️ Usage |
28 | 28 |
|
29 | 29 | 1. In your navigation component |
30 | 30 |
|
@@ -68,15 +68,44 @@ import ScrollSpy from "react-ui-scrollspy"; |
68 | 68 |
|
69 | 69 | ## 💡 Props |
70 | 70 |
|
71 | | -| Attributes | Type | Description | Default | Required | |
72 | | -| :------------------------- | :----------------------------------------- | :--------------------------------------------------------------------------------------------------------------------- | :------ | :------- | |
73 | | -| `children` | `ReactNode` | Each direct child `Element` should contain an `id` | - | yes | |
74 | | -| `scrollThrottle` | `number` | in `milliseconds` to throttle the `onscroll` event. Lower the number, better the response, higher the performance cost | 300 | no | |
75 | | -| `navContainerRef` | `MutableRefObject<HTMLDivElement \| null>` | `ref` to your navigation container containing items with `data-to-scrollspy-id` attributes | - | no | |
76 | | -| `onUpdateCallback` | `(id: string) => void` | Executes this function whenever you scroll to an `Element`, callback returns the `id` of that `Element` as well | - | no | |
77 | | -| `parentScrollContainerRef` | `MutableRefObject<HTMLDivElement \| null>` | If you want to spy only on a particular scrollable `container (Element)` then pass a ref of the same to this prop | - | no | |
78 | | -| `offsetTop` | `number` | spy will be fired when it has been scrolled `offsetTop` beyond `50%` to the top of the containing element | 0 | no | |
79 | | -| `offsetBottom` | `number` | spy will be fired when it has been scrolled `offsetBottom` beyond `50%` to the bottom of the containing element | 0 | no | |
| 71 | +### Children |
| 72 | + |
| 73 | +| Attributes | Type | Description | Default | Required | |
| 74 | +| :--------- | :---------- | :------------------------------------------------- | :------ | :------- | |
| 75 | +| `children` | `ReactNode` | Each direct child `Element` should contain an `id` | - | yes | |
| 76 | + |
| 77 | +### Refs |
| 78 | + |
| 79 | +| Attributes | Type | Description | Default | Required | |
| 80 | +| :------------------------- | :------------------------------------------------ | :---------------------------------------------------------------------------------------------------------------- | :------ | :------- | |
| 81 | +| `navContainerRef` | MutableRefObject<br><HTMLDivElement \| null><br/> | `ref` to your navigation container containing items with `data-to-scrollspy-id` attributes | - | no | |
| 82 | +| `parentScrollContainerRef` | MutableRefObject<br><HTMLDivElement \| null><br/> | If you want to spy only on a particular scrollable `container (Element)` then pass a ref of the same to this prop | - | no | |
| 83 | + |
| 84 | +### Throlle |
| 85 | + |
| 86 | +| Attributes | Type | Description | Default | Required | |
| 87 | +| :--------------- | :------- | :--------------------------------------------------------------------------------------------------------------------- | :------ | :------- | |
| 88 | +| `scrollThrottle` | `number` | In `milliseconds` to throttle the `onscroll` event. Lower the number, better the response, higher the performance cost | `300` | no | |
| 89 | + |
| 90 | +### Callback |
| 91 | + |
| 92 | +| Attributes | Type | Description | Default | Required | |
| 93 | +| :----------------- | :--------------------- | :-------------------------------------------------------------------------------------------------------------- | :------ | :------- | |
| 94 | +| `onUpdateCallback` | `(id: string) => void` | Executes this function whenever you scroll to an `Element`, callback returns the `id` of that `Element` as well | - | no | |
| 95 | + |
| 96 | +### Offsets |
| 97 | + |
| 98 | +| Attributes | Type | Description | Default | Required | |
| 99 | +| :------------- | :------- | :-------------------------------------------------------------------------------------------------------------- | :------ | :------- | |
| 100 | +| `offsetTop` | `number` | Spy will be fired when it has been scrolled `offsetTop` beyond `50%` to the top of the containing element | `0` | no | |
| 101 | +| `offsetBottom` | `number` | Spy will be fired when it has been scrolled `offsetBottom` beyond `50%` to the bottom of the containing element | `0` | no | |
| 102 | + |
| 103 | +### Customize Attributes |
| 104 | + |
| 105 | +| Attributes | Type | Description | Default | Required | |
| 106 | +| :----------------- | :------- | :----------------------------------------------------------- | :-------------------- | :------- | |
| 107 | +| `useDataAttribute` | `string` | To customize the string after `data-` | `"to-scrollspy-id"` | no | |
| 108 | +| `activeClass` | `string` | To customize the `class` added when the `Element` is in view | `"active-scroll-spy"` | no | |
80 | 109 |
|
81 | 110 | ## 📝 Authors |
82 | 111 |
|
|
0 commit comments