3.0.3-alpha • Published 1 year ago

cm-react-indiana-drag-scroll v3.0.3-alpha

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React Indiana Drag Scroll

Implements scroll on drag

Examples / Documentation / Sandbox

NPM JavaScript Style Guide

Welcome to journey!

npm.io

Try it yourself! Go to demo website.

Install

:fire: You're currently looking at the branch for the alpha release. If you're looking for the stable branch, please check out master branch.

npm install --save react-indiana-drag-scroll@next
yarn add react-indiana-drag-scroll@next

Usage

You can use the ScrollContainer component:

import React, { Component } from 'react'
import { ScrollContainer } from 'react-indiana-drag-scroll';
import 'react-indiana-drag-scroll/dist/style.css'

export const Example = () => {
   return (
      <ScrollContainer>
         {/* scrollable content */}
      </ScrollContainer>
   )
};

Or, if you need to get more flexibility you can use useScrollContainer hook:

import { useScrollContainer } from 'react-indiana-drag-scroll';

export const Example = () => {
    const scrollContainer = useScrollContainer(options);
    return (
      <div ref={scrollContainer.ref}>
        {/* scrollable content */}
      </div>
    )
};

In this case you should provide the corresponding styles by yourself (for example, overflow: auto).

Props

PropTypeDescriptionDefault
hideScrollbarsbooleanHide the scrollbarstrue
childrenReactNodeThe content of the scrolling container
onScroll() => voidInvoked when user scrolls the container
onEndScroll() => voidInvoked when scrolling is over completely
onStartScroll() => voidInvoked when scrolling starts
componentElementTypeThe component used for the root node.'div'
classNamestringThe custom classname for the container
styleCSSPropertiesThe custom styles for the container
refElementTypeThe ref to the root node (experimental alternative to getElement)
mouseScrollConfiguration, booleanThe configuration of mouse scroll. The object's fields is described belowtrue

Configuration

FieldTypeDescriptionDefault
rubberBandbooleanThe flag that indicates that rubber band effect should be enabledtrue
inertiabooleanThe flag that indicates that inertial effect should be enabledtrue
overscrollbooleanThe flag that indicates that overscroll effect should be enabled (experimental)false
cursorbooleanThe flag that indicates that cursor should be changed on dragtrue
activationDistanceNumberThe distance that distinguish click and drag start10
ignoreElementsstringSelector for elements that should not trigger the scrolling behaviour (for example, ".modal, dialog" or "*[prevent-drag-scroll]")
buttonsnumber[]The list of mouse button numbers that will activate the scroll by drag1

License

The source code is licensed under MIT, all images (except hieroglyphs) are copyrighted to their respective owner © Norserium