Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dimslaev/scrollnav

Nicely overflowing navigation for React.
https://github.com/dimslaev/scrollnav

Last synced: 13 days ago
JSON representation

Nicely overflowing navigation for React.

Awesome Lists containing this project

README

        

### Scrollnav v1.2.2

The `useScrollNav` hook allows you to add a scrollable wrapper around nav items while giving you full control over the UI.

#### NPM Package

```
npm i @dims/scrollnav
```

#### Usage

```javascript
import { useScrollNav } from '@dims/scrollnav';
const ExampleNavComponent = () => {
const listRef = React.useRef();
const { canScrollPrev, canScrollNext, scrollPrev, scrollNext } = useScrollNav(
{ listRef }
);
return (


  • nav item 1

  • nav item 2

  • nav item 3

  • nav item 4


{canScrollPrev && <}
{canScrollNext && >}

);
};
```

#### Example

See `./src/Example.jsx`.

Hook params:

```md
| Prop | Type | Required | Description |
| -------------- | ------ | -------- | ------------------------------------------------- |
| listRef | Object | yes | Ref of the direct parent of your nav items |
| scrollStepSize | Number | no | % of the container width to scroll on arrow click |
| triggerUpdate | Bool | no | Programatically trigger a re-render |
```

Hook returns:

```md
| Prop | Type |
| ------------------ | ------------ |
| canScrollPrev | Bool |
| canScrollNext | Bool |
| scrollPrev | Func |
| scrollNext | Func |
| scrollToChildIndex | Func(number) |
```