Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/keidrun/reactstrap-scrollspy

Scrollspy library for Reactstrap to create an automatically update navigation easily and flexibly.
https://github.com/keidrun/reactstrap-scrollspy

bootstrap bootstrap4 component navbar navigation react react-component reactstrap scroll scrollspy

Last synced: about 2 months ago
JSON representation

Scrollspy library for Reactstrap to create an automatically update navigation easily and flexibly.

Awesome Lists containing this project

README

        

# reactstrap-scrollspy

[![NPM version][npm-image]][npm-url] [![npm module downloads][npm-downloads-image]][npm-downloads-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url] [![License: MIT][license-image]][license-url]

Scrollspy library for [Reactstrap](https://github.com/reactstrap/reactstrap) to create an automatically update navigation easily and flexibly.

## Demo

:fire: [Enjoy :+1:](https://keidrun.github.io/reactstrap-scrollspy/) :fire:

## Install

```bash
npm i reactstrap-scrollspy
```

Or

```bash
yarn add reactstrap-scrollspy
```

## Usage

This library provides `Scrollspy` and `ScrollspyNavLink` components.

### Scrollspy

You should wrap your components in `Scrollspy`. This has mainly two props, which are `names` and `homeIndex`. `names` is used to identify each component wrapped by this, so you should give unique names' list that arranged in order. Then, `homeIndex` is an index number to identify home component such as `Header`.

#### Props

```javascript
type Props = {
names: Array,
homeIndex?: number,
topOffset?: string | number,
bottomOffset?: string | number,
delayMs?: number,
children: ChildrenArray,
}
```

#### Default Props

```javascript
Scrollspy.defaultProps = {
homeIndex: 0,
topOffset: '50%',
bottomOffset: '40%',
delayMs: 50,
}
```

#### Example

```javascript
// @flow
import React from 'react'

import { Scrollspy } from 'reactstrap-scrollspy'
...

function App() {
return (
<>








>
)
}

export default App
```

### ScrollspyNavLink

You should wrap `NavLink` provided by `reactstrap` in `ScrollspyNavLink`. This has an one prop, which is `name`. `name` is used to identify a `NavLink` and notify `Scrollspy` of it automatically.

#### Props

```javascript
type Props = {
name: string,
children: Element,
}
```

#### Example

```javascript
// @flow
import React, { useState } from 'react'
import { Collapse, Navbar as ReactstrapNavbar, NavbarToggler, Nav, NavItem, NavLink } from 'reactstrap'

import { ScrollspyNavLink } from 'reactstrap-scrollspy'

function Navbar() {
...
return (

...



Home




Section1




Section2




Section3



...

)
}

export default Navbar
```

## Peer dependencies

- [React](https://github.com/facebook/react)
- ReactDOM
- [Reactstrap](https://github.com/reactstrap/reactstrap)

[npm-url]: https://npmjs.org/package/reactstrap-scrollspy
[npm-image]: https://badge.fury.io/js/reactstrap-scrollspy.svg
[npm-downloads-url]: https://npmjs.org/package/reactstrap-scrollspy
[npm-downloads-image]: https://img.shields.io/npm/dt/reactstrap-scrollspy.svg
[travis-url]: https://travis-ci.org/keidrun/reactstrap-scrollspy
[travis-image]: https://secure.travis-ci.org/keidrun/reactstrap-scrollspy.svg?branch=master
[depstat-url]: https://david-dm.org/keidrun/reactstrap-scrollspy
[depstat-image]: https://david-dm.org/keidrun/reactstrap-scrollspy.svg
[license-url]: https://opensource.org/licenses/MIT
[license-image]: https://img.shields.io/badge/License-MIT-yellow.svg