1.4.1 • Published 3 months ago

react-cool-scrollbar v1.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

npm NPM License ReactJS

react-cool-scrollbar

It's a simple react library for a customized browser independent scrollbar for your web page

Installation

npm

npm install react-cool-scrollbar

or yarn

yarn add react-cool-scrollbar

Demo

Here you can find a demo

Features

  • Scrollbar customization (external component can be provided as scroll thumb or track)
  • Customizable scrollbar width

How to use

import component and styles

Import ReactCoolScrollbar component and styles

import { ReactCoolScrollbar } from "react-cool-scrollbar"; //scroller component
import "react-cool-scrollbar/dist/style.css"; //style files

Using the component

You can use the component like below example-

function App() {
  return (
    <div className="app">
      {/** .app {display: flex;} */}

      <ReactCoolScrollbar>
        {/** your scrollable content here */}
      </ReactCoolScrollbar>
    </div>
  );
}

export default App;

You must import the style file to make the scrollbar work.\ Make sure the parent of ReactCoolScrollbar component must be the scroll host of the scrollable content.\ Make the style property of the parent as display:flex. This will work in most cases.

Props

  • scrollBarVisibility: This prop can receive 3 types of conditions to make the scrollbar visible on the UI.

    • always: Scrollbar will be always visible.
    • onhover: Scrollbar will be visible on hover the scroll container.
    • onscroll: Scrollbar will be visible on scrolling the page.
  • scrollerWidth : Receives a number as input to set the width of the scrollbar.

  • className : Can be used to style the custom scrollbar. The className will be applied on the container of scrollTrack and scrollThumb

  • customScrollTrack : You can customize the scroll track by passing a component or a function that will return a component.

    • Example:
      <ReactCoolScrollbar
        customScrollTrack={<div className="custom-scroll"></div>}
      >
        {/** your scrollable content here */}
      </ReactCoolScrollbar>
      or
      <ReactCoolScrollbar
        customScrollTrack={(props) => (
          <div className="custom-scroll" {...props}></div>
        )}
      >
        {/** your scrollable content here */}
      </ReactCoolScrollbar>
      The passed component or function will receive the following props
     handleMouseDown: (e: MouseEvent<HTMLDivElement>) => void;
     handleMouseUp: (e: MouseEvent<HTMLDivElement>) => void;

    If you use a separate component or function then you have to pass every received prop to your component.

  • customScrollThumb : Same as customScrollTrack prop but it will customize the scroll thumb component. This component will receive prop

    •     handleMouseDown: (e: MouseEvent<HTMLDivElement>) => void;
      you have to be careful here that these props are passing down to your custom component properly

License

MIT

1.3.7

3 months ago

1.3.6

3 months ago

1.4.1

3 months ago

1.4.0

3 months ago

1.3.8

3 months ago

1.3.5

4 months ago

1.3.4

4 months ago

1.3.3

4 months ago

1.3.2

4 months ago

1.3.1

4 months ago

1.3.0

4 months ago

1.2.8

11 months ago

1.2.7

11 months ago

1.2.6

11 months ago

1.2.5

11 months ago

1.2.4

11 months ago

1.2.3

11 months ago

1.2.2

11 months ago

1.2.1-beta

11 months ago

1.2.0

11 months ago

1.1.21

11 months ago

1.1.20

11 months ago

1.1.19

11 months ago

1.1.18

11 months ago

1.1.17

11 months ago

1.1.16

11 months ago

1.1.15

11 months ago

1.1.14

11 months ago

1.1.13

11 months ago

1.1.12

11 months ago

1.1.11

11 months ago

1.1.10

11 months ago

1.1.9

11 months ago

1.1.8

11 months ago

1.1.7

11 months ago

1.1.6

11 months ago

1.1.5

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago