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-scrolling-sections

v3.0.3

Published

React library to provide a declarative scroll to between sections

Downloads

3

Readme

react-scroll-section

Build Status npm package Netlify Status

Live demo ✨

Why you should use it? 🤔

When you think about implementing a scrollTo functionality in a website the first thing it will your mind will be jQuery, using the following line of code:

$('#target').scroll();

I won't deny that actually works, but the problem comes when you start working with frameworks based on component, like React.

Manage the navigation to another section and which section can be hard task without a state management library.

This library will help you to avoid thinking all the possible edges cases and focus on the final result, which is just provide an easy navigation inside your app.

Built with 🔧

Just React! Using the following API:

  • Context: using the of <Consumer /> and <Provider />.
  • Ref: new createRef API
  • Hooks: useScrollSection and useScrollSections to interact with the registered sections.

Installation

# npm
> npm install react-scroll-section

# yarn
> yarn add react-scroll-section

Usage

The library provides the following components:

  • ScrollingProvider: responsible to link Section and SectionLink and know which Section is selected.
  • Section: renders a <section /> tag that receives an ID and register itself in ScrollingProvider.
  • useScrollSection: React Hook given the id of the section returns if the section is selected and a callback to scroll to it.
  • useScrollSection: returns an array of all the sections with id, selected and scrollTo.

Examples

Using SectionLink (Static Menu)

import React from 'react';
import {
  ScrollingProvider,
  useScrollSection,
  Section,
} from 'react-scroll-section';

const StaticMenu = () => {
  const homeSection = useScrollSection('home');
  const aboutSection = useScrollSection('about');

  return (
    <ul>
      <li onClick={homeSection.onClick} selected={homeSection.selected}>
        Home
      </li>
      <li onClick={aboutSection.onClick} selected={aboutSection.selected}>
        About
      </li>
    </ul>
  );
};

const App = () => (
  <ScrollingProvider>
    <StaticMenu />
    <Section id="home">MY HOME</Section>
    <Section id="about">ABOUT ME</Section>
  </ScrollingProvider>
);

Using SectionLinks (Dynamic Menu)

import React from 'react';
import {
  ScrollingProvider,
  useScrollSections,
  Section,
} from 'react-scroll-section';

export const DynamicMenu = () => {
  const sections = useScrollSections();

  return (
    <ul>
      {sections.map(({ id, onClick, selected }) => (
        <li key={id} onClick={onClick} selected={selected}>
          {id.toUpperCase()}
        </li>
      ))}
    </ul>
  );
};

const App = () => (
  <ScrollingProvider>
    <DynamicMenu />
    <Section id="home">Home section</Section>
    <Section id="about">About section</Section>
  </ScrollingProvider>
);

Props

ScrollingProvider

| Property | Type | Required | Default | Description | | ---------------- | ---------------------------- | -------- | -------- | --------------------------------------------------------- | | debounceDelay | number | false | 50 | time to wait until the calculation of the current section | | scrollBehavior | string | false | "smooth" | scrolling style | | children | ReactNode | false | null | React component | | offset | number | false | null | Vertical offset the modifies the final scrolling position |

Section

| Property | Type | Required | Default | Description | | ---------- | ----------- | -------- | ------- | --------------- | | children | ReactNode | false | null | Section content | | id | string | true | - | Section ID |

Contributing

Setup project

  • Running yarn install in the component's root directory will install everything you need for development.

Demo Development Server

Testing

  • yarn test: executes Cypress and run test. Remember to execute yarn start in order to have a successful result.
  • yarn test:open: opens Cypress interface which allows you to execute test individually and preview the order execution of the tests.

Building

  • yarn build: builds the library, this is necessary to be published to npm.

Contribute ❤️

I'm always open for suggestions and improvements, so don't hesitate to open an Issue or new Pull Request 😁

License 🔖

MIT.