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

v1.1.0

Published

Looking for same scroll behavior on all devices.

Downloads

33

Readme

react-universal-scroll

Installation

npm install react-universal-scroll
yarn add react-universal-scroll
pnpm add react-universal-scroll

Features

Wheel, Touch, BarMove, Drag event support

You can disable each behavior by props.

behavior.gif

horizontal direction support

horizontal.gif

Quick Start

Simply wrap your element with Scroll component and pass dir prop to it.
It is going to make your element scrollable in the direction you want.
width or height are not required for the <Scroll> component if your component inside of flex or something layout. (if not, you should set width or height)

<Scroll dir={"vertical"} style={{
    width:150,// if you going to fixed size, set on here
    height:300 
}}>
    <ul>
        <li>Google</li>
        <li>Facebook</li>
        <li>Microsoft</li>
        <li>Apple</li>
        <li>Amazon</li>
        <li>Google</li>
        <li>Facebook</li>
        <li>Microsoft</li>
        <li>Apple</li>
        <li>Amazon</li>
    </ul>
</Scroll>

quick-start.png

Advanced Usage

If you want to use background, you can use it in the parent element of the Scroll component.
If not, it will crop by area of overflow: hidden.

background

<Scroll
  dir={"vertical"}
  style={
    {
      background: "gray", // set background color here
    }
  }
>
  <ul
    style={{
      // background: "gray", // x don't use background color
    }}
  >
    <li>Google</li>
    <li>Facebook</li>
    <li>Microsoft</li>
    <li>Apple</li>
    <li>Amazon</li>
    <li>Google</li>
    <li>Facebook</li>
    <li>Microsoft</li>
    <li>Apple</li>
    <li>Amazon</li>
  </ul>
</Scroll>

bg-example.png

inline size

If you want to set scroll position to fit the content, make Scroll component to inline.

<Scroll
    dir={"vertical"}
    style={{
        display: "inline-block",
    }}
>
    <ul>
        <li>Google</li>
        <li>Facebook</li>
        <li>Microsoft</li>
        <li>Apple</li>
        <li>Amazon</li>
        <li>Google</li>
        <li>Facebook</li>
        <li>Microsoft</li>
        <li>Apple</li>
        <li>Amazon</li>
    </ul>
</Scroll>

inline.png

Grab options

By default, grab event change cursor to grabbing.

Disable the grab option by passing false to the grab prop.

<Scroll dir={"horizontal"} grab={false}>
    // ...
</Scroll>

// or 

<Scroll dir={"horizontal"} grab={{
    useGrabCursor:true
}}>
    // ...
</Scroll>

Wheel options

<Scroll dir={"horizontal"} wheel={false}>
    // ...
</Scroll>

The amount of scroll per wheel event and the direction of the scroll can be adjusted.

<Scroll dir={"horizontal"} wheel={{
    step:100,
    reverse:false
}}>
    // ...
</Scroll>

step:1
wheel-step-1.gif

step:100
wheel-step-100.gif

Full options

<Scroll
    style={{
        width: 500,
        background: "#f1f1f1",
    }}
    dir={"horizontal"}
    wheel={{
        step: 30,
        reverse: false,
    }}
    grab={{
        useGrabCursor: true,
    }}
    bar={{
        size: 10,
        marginFromEdge: 3,
        style: {
            background: "#575757",
        },
        track: {
            size: 16,
            style: {
                background: "#bebebe",
            },
        },
    }}
>
// ...    
</Scroll>

full-options.gif

useScrollControl hook

If you want to control the scroll position, you can use the useScrollControl hook.
It returns the current object that has the scrollTo method.
Only ratio option is available for now.

import { Scroll } from "./lib";
import { useScrollControl } from "./lib/hooks/useScrollControl";
function App() {
  const control = useScrollControl();
  return (
    <div>
      <Scroll control={control} >
          // ...
      </Scroll>
      <button
        onClick={() => {
          control.current.scrollTo({ ratio: 0.5 }); // 0 ~ 1
        }}
      >
        Scroll right
      </button>
    </div>
  );
}

export default App;