GithubHelp home page GithubHelp logo

keidrun / reactstrap-scrollspy Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 4.24 MB

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

Home Page: https://keidrun.github.io/reactstrap-scrollspy/

License: MIT License

JavaScript 94.63% HTML 2.28% Shell 3.08%
scrollspy scroll react react-component reactstrap bootstrap bootstrap4 navigation component navbar

reactstrap-scrollspy's Introduction

reactstrap-scrollspy

NPM version npm module downloads Build Status Dependency Status License: MIT

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

Demo

๐Ÿ”ฅ Enjoy ๐Ÿ‘ ๐Ÿ”ฅ

Install

npm i reactstrap-scrollspy

Or

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

type Props = {
  names: Array<string | null>,
  homeIndex?: number,
  topOffset?: string | number,
  bottomOffset?: string | number,
  delayMs?: number,
  children: ChildrenArray<any>,
}

Default Props

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

Example

// @flow
import React from 'react'

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

function App() {
  return (
    <>
      <Scrollspy
        names={['navbar', 'header', 'section-1', 'section-2', 'section-3', null]}
        homeIndex={1}
      >
        <Navbar />
        <Header />
        <Section1 />
        <Section2 />
        <Section3 />
        <Footer />
      </Scrollspy>
    </>
  )
}

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

type Props = {
  name: string,
  children: Element<any>,
}

Example

// @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 (
    <ReactstrapNavbar expand="md" fixed="top" className="...">
      ...
        <Nav navbar className="...">
          <NavItem>
            <ScrollspyNavLink name="header">
              <NavLink href="#header">Home</NavLink>
            </ScrollspyNavLink>
          </NavItem>
          <NavItem>
            <ScrollspyNavLink name="section-1">
              <NavLink href="#section-1">Section1</NavLink>
            </ScrollspyNavLink>
          </NavItem>
          <NavItem>
            <ScrollspyNavLink name="section-2">
              <NavLink href="#section-2">Section2</NavLink>
            </ScrollspyNavLink>
          </NavItem>
          <NavItem>
            <ScrollspyNavLink name="section-3">
              <NavLink href="#section-3">Section3</NavLink>
            </ScrollspyNavLink>
          </NavItem>
        </Nav>
      ...
    </ReactstrapNavbar>
  )
}

export default Navbar

Peer dependencies

reactstrap-scrollspy's People

Contributors

dependabot[bot] avatar keidrun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

regnen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.