npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-single-page-navigation

v1.0.1

Published

React Render Props single page scroll navigation component

Downloads

55

Readme

Features

  • ☁️Lightweight (~2kB)
  • 🎉 Dependency Free
  • 💪 Written in TypeScript
  • 🔥Render props

Installation

npm install react-single-page-navigation --save #npm
yarn add react-single-page-navigation #yarn

Example

Example

Usage

import ScrollNavigation from 'react-single-page-navigation';

const App = () => (
  <ScrollNavigation elements={{ TopOfThePage: {}, BottomOfThePage: {} }}>
    {({ refs, activeElement, goTo }) => (
      <div>
        <div ref={refs.TopOfThePage} onClick={() => goTo('BottomOfThePage')}>
          Top Element {activeElement === 'TopOfThePage' && 'is active!'}
        </div>
        <div ref={refs.BottomOfThePage} onClick={() => goTo('TopOfThePage')}>
          Bottom Element {activeElement === 'BottomOfThePage' && 'is active!'}
        </div>
      </div>
    )}
  </ScrollNavigation>
);

Props

Componenet props

elements (required) object: Object with name of tracked sections as keys and config object as values. Object has to be complete during mounting of the component - as for now there is no support for dynamic elements

interface IElements {
  [elementName: string]: object;
}

example:

const config = {}; no config available yet // TODO
const elements = { EL1Name: config, EL2Name: config };
<ScrollNavigation elements={elements}>

shouldEnableHistory? (optional) boolean (default undefined): Set to true to modify history when navigating to element (enable back button);

shouldEnableHistory?: boolean

shouldModifyUrl? boolean (default undefined): Set to true to modify url when navigating to element (add http://yoururl.com/#ElementName)
shouldEnableHistory has to be set to true as well for it to work;

shouldModifyUrl?: boolean

offset? number (default undefined): Scrolltop offset in pixels, useful for fixed navbars

offset?: number

Render prop props

refs: Object with same keys as elements and createRef as values. All refs have to be created.

{
  [key in keyof IElements]: React.RefObject<>
}

goTo: function that takes as argument element key or number. When called it will initiate scroll transition to given element or to given scroll position. You can modify scroll position additionally to global offset with section offset with third parameter offset. To go to top use goTo(0), to go to top plus 100px use goto(0, "smooth", 100), to go to EL2Name use goTo("EL2Name")

(scrollTo: keyof IElements | number, behaviour:  "auto" | "instant" | "smooth" = "smooth", offset?: number) => void

activeElement: Key of element that is active in the current scroll position (takes at least 50% of the view).

keyof IElements