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-physics-dragger

v2.0.0

Published

> A simple, no-frills horiztonal dragger/slider with physics

Downloads

468

Readme

React Physics Dragger

A simple, no-frills horiztonal dragger/slider with physics

example gif

NPM npm bundle size

▶ Example site

This is a React component which basically adds a wrapper element with horizontal dragging capabilities. It uses a little bit of physics to apply friction and boundary bouncing (similar to Apple's interfaces, and the Flickity carousel).

  • Works with both touch and mouse
  • 0 dependencies
  • Super small

Example usage

yarn add react-physics-dragger
# or
npm i react-physics-dragger

Internally it uses ResizeObserver so you might need to add a polyfill if you support IE11. If so, instructions below.

import Dragger from 'react-physics-dragger'
import ResizeObserver from 'resize-observer-polyfill' // this one works pretty great

const App = () => {
  return (
    <Dragger
      ResizeObserverPolyfill={ResizeObserver} // remember; only if you need it, else it uses window.ResizeObserver
    >
        <div>1</div>
        <div>2</div>
        <div>3</div>
    </Dragger>
  )
}

Props

| Property | Type | Default Value | Description | | :--------------- | :---------------- | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | friction | number | 0.95 | Optional. Lower values feel grippier, higher values feel slippier. | |draggerRef | function | | Optional. Use to access the components internal methods (see below section "Ref Methods") and Example1. | | onFrame | callback function | | Optional. This function is fired on every movement, resize, and mount. It provides one param object includes the x position, progress (from 0 to 1), and dragger dimensions. See Example2. | | onDown | callback function | | Optional. Fired on mouse or touch press. | | onUp | callback function | | Optional. Fired on mouse or touch release. | | onStaticClick | function | | Optional. Fired when an item within the dragger is clicked (or tapped). Useful for avoiding events where dragging can be considered a click. | | setCursorStyles | boolean | true | Optional. If enabled, styles are added/removed to the <html> element for grabbing cursor styles. | | className | string | | Optional. Add your own class name to the outer element | | style | CSSProperties | | Optional. Add your own styles to the outer element | | innerStyle | CSSProperties | | Optional. Add your own styles to the inner element | | disabled | boolean | false | Optional. Enable/disable the component. | ResizeObserverPolyfill | | | Optional. If you need the polyfill pass it in as a prop. |

Ref Methods

| Property | Type | Description | | :------------ | :------- | :--------------------------------------------------------------------------------------------------- | | setPosition | function | Changes the position of the slider. draggerRef.current.setPosition(x, false) where x is the pixel value. Accepts a second argument (boolean, false by default) which determines whether to move to setPosition value instantly. |

Acknowledgements

Inspired by Dave DeSandro's work on Practical UI Physics; https://www.youtube.com/watch?v=90oMnMFozEE and https://codepen.io/desandro/pen/QbPKEq

This library was packaged with https://github.com/transitive-bullshit/create-react-library

License

MIT © nickmcmillan