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-scroll-marker

v0.2.2

Published

Indicate the active section of a page based on scroll position.

Downloads

834

Readme

react-scroll-marker

NPM version Test build status Bundle size Bundle size

Indicate the active section of a page based on scroll position.

Install

You can install react-scroll-marker with NPM or Yarn.

npm install react-scroll-marker --save-exact
yarn add react-scroll-marker --exact

We encourage pinning the version number until react-scroll-marker reaches 1.0.0. We may ship breaking changes in 0.x.x versions.

Usage example

import {
  ScrollMarkerContainer,
  ScrollMarkerLink,
  ScrollMarkerSection
} from "react-scroll-marker";

const Page = () => (
  <ScrollMarkerContainer>
    <nav>
      <ScrollMarkerLink id="overview">
        {({ isActive, onClick }) => (
          <a
            href="/about/#overview"
            onClick={onClick}
            style={{ fontWeight: isActive ? "bold" : "normal" }}
          >
            Overview
          </a>
        )}
      </ScrollMarkerLink>
      <ScrollMarkerLink id="history">
        {({ isActive, onClick }) => (
          <a
            href="/about/#history"
            onClick={onClick}
            style={{ fontWeight: isActive ? "bold" : "normal" }}
          >
            History
          </a>
        )}
      </ScrollMarkerLink>
    </nav>
    <main>
      <ScrollMarkerSection id="overview">
        {({ id }) => (
          <section>
            <h2 id={id}>Overview</h2>
            <p>…</p>
          </section>
        )}
      </ScrollMarkerSection>

      <ScrollMarkerSection id="history">
        {({ id }) => (
          <section>
            <h2 id={id}>History</h2>
            <p>…</p>
          </section>
        )}
      </ScrollMarkerSection>
    </main>
  </ScrollMarkerContainer>
);

API

This package exports three components: ScrollMarkerContainer, ScrollMarkerLink, and ScrollMarkerSection. Here's the documentation for each.

ScrollMarkerContainer

The outermost container that wraps the ScrollMarkerLink and ScrollMarkerSection components. This component exists so that the other two components can communicate.

Props

| Prop | Type | Description | | ---------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------- | | children | node, required | The navigation and content on your page. The children should include instances of ScrollMarkerLink and ScrollMarkerSection. |

ScrollMarkerLink

This component wraps each nav item and tells you whether the nav item is active.

Props

| Prop | Type | Description | | ---------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | children | func, required | This component expects a function as the children. The function will receive an object with two properties: isActive and onClick. isActive is a boolean that indicates whether the nav item is currently being viewed. onClick is a function that should be passed to the anchor tag. It makes the highlighting more reliable. | | id | string, required | The id of the section that corresponds to the nav item. There should be a corresponding ScrollMarkerSection with the same id. |

ScrollMarkerSection

This component wraps sections of content on a page. It communicates with ScrollMarkerContainer as users scroll, firing events when a new section comes into view.

Props

| Prop | Type | Description | | ---------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | children | func, required | This component expects a function as the children. The function will receive an object with a single id property. The id should then be passed to a heading in the section. You'll notice that the value of the id is the same as the string passed in as the id prop. We provide it as a small convenience so that consumers don't need to duplicate it in two places. | | id | string, required | The id of the section on the page. There should be a corresponding ScrollMarkerLink with the same id. |