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

use-scroller

v1.2.0

Published

A lightweight library that enables smooth scrolling for HTML elements using simple React hooks provided by the package. This library offers additional scrolling features and provides several callback functions for customizable scroll operations.

Downloads

4

Readme

use-scroller

A lightweight library that enables smooth scrolling for HTML elements using simple React hooks provided by the package. This library offers additional scrolling features and provides several callback functions for customizable scroll operations.

Installation

#YARN
yarn add use-scroller

#NPM
npm install use-scroller

#PNPM
pnpm install use-scroller

Usage

Scroll state

import { useScroll } from 'use-scroller'

export default function ScrollStateExample() {
  const { ref, state } = useScroll<HTMLDivElement>()

  return (
    <>
      <p>Scroll State:</p>
      <pre>{JSON.stringify(state, null, 2)}</pre>
      <div ref={ref} style={{ height: '200px', overflowY: 'scroll' }}>
        {/* Your content */}
      </div>
    </>
  )
}

Carousel

import { useScroll } from 'use-scroller'

export default function CarouselExample() {
  const { ref, scrollLeft, scrollRight } = useScroll<HTMLDivElement>()

  return (
    <>
      <button onClick={() => scrollLeft()}>Scroll Left</button>
      <button onClick={() => scrollRight()}>Scroll Right</button>

      <div ref={ref} style={{ width: '400px', overflowX: 'scroll' }}>
        {/* Your carousel content */}
      </div>
    </>
  )
}

Box

import { useScroll } from 'use-scroller'

export default function BoxExample() {
  const { ref, scrollLeft, scrollRight, scrollTop, scrollBottom, scrollToCenter } =
    useScroll<HTMLDivElement>()

  return (
    <>
      <button onClick={() => scrollToCenter()}>Scroll to Center</button>
      <button onClick={() => scrollLeft()}>Scroll Left</button>
      <button onClick={() => scrollRight()}>Scroll Right</button>
      <button onClick={() => scrollTop()}>Scroll to Top</button>
      <button onClick={() => scrollBottom()}>Scroll to Bottom</button>
      <div ref={ref} style={{ width: '300px', height: '300px', overflow: 'scroll' }}>
        {/* Your content */}
      </div>
    </>
  )
}

Scroll to target

import { useWindowScroll } from 'use-scroller'

export default function ScrollToTargetExample() {
  const { scrollToTarget } = useWindowScroll()
  const ref1 = useRef(null)
  const ref2 = useRef(null)
  const ref3 = useRef(null)

  return (
    <>
      <button onClick={() => scrollToTarget(ref1)}>Scroll to Target 1</button>
      <button onClick={() => scrollToTarget(ref2)}>Scroll to Target 2</button>
      <button onClick={() => scrollToTarget(ref3)}>Scroll to Target 3</button>

      <div>
        <div ref={ref1} style={{ height: '400px', backgroundColor: 'lightcoral' }}>
          Target 1
        </div>
        <div ref={ref2} style={{ height: '400px', backgroundColor: 'lightseagreen' }}>
          Target 2
        </div>
        <div ref={ref3} style={{ height: '400px', backgroundColor: 'lightsalmon' }}>
          Target 3
        </div>
      </div>
    </>
  )
}

API Documentation

Available Hooks

useScroll

This hook is designed to handle element scroll events, enabling smooth scrolling for specified HTML elements.

Options
  • direction (Type: horizontal or vertical, Default: vertical): Specifies the desired scroll direction. You can set it to horizontal or vertical based on your needs.

  • duration (Type: number, Default: 300): Sets the animation duration for scrolling. Adjust this value to control the speed of the scroll animation.

  • easingOption (Type: EasingOptions, Default: ease-in-out): Determines the type of animation to use for scrolling. You can choose from various easing options such as ease-in, ease-out, ease-in-out, etc., to customize the scroll animation's behavior.

useWindowScroll

This hook is tailored to handle window scroll events, making it easy to manage scrolling operations within the entire window.

Options
  • duration (Type: number, Default: 300): Specifies the animation duration for scrolling operations. Adjust this value to control the speed of the scroll animation.

  • easingOption (Type: EasingOptions, Default: ease-in-out): Defines the type of animation to use for scrolling within the window. You can choose from various easing options to customize the scroll animation's behavior.

Feel free to update and expand this documentation further based on your library's features and usage patterns.