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-scrollbar-x

v0.4.4

Published

ScrollArea component for react

Downloads

18

Readme

build status npm package npm downloads

react-scrollbar

Simple ScrollArea component built for React.

Demo

npm install react-scrollbar-x --save

React Scrollbar requires React 0.13 or later

Features:

  • built with and for React
  • horizontal and vertical scrollbars
  • touch support
  • scrollbar dragging and clicking
  • smooth scrolling
  • universal app support
  • customizable styles
  • and more...

Usage examples

React 0.14

    var React = require('react');
    var ReactDOM = require('react-dom');
    var ScrollArea = require('react-scrollbar');

    var App = React.createClass({
      render() {
        return (
          <ScrollArea
            speed={0.8}
            className="area"
            contentClassName="content"
            horizontal={false}
            >
            <div>Some long content.</div>
          </ScrollArea>
        );
      }
    });

    ReactDOM.render(<App/>, document.body);

React 0.13

For React 0.13 you need to wrap <ScrollArea> child into a function.

<ScrollArea>
    { () => <div>Some long content. </div> }
</ScrollArea>

Version without boundled css styles

If you prefer including scrollbar without css styles boundled inline to js file it's possible to import package without them. It's useful when you want to make custom css changes in scrollbars without using !important in each line.

    var ScrollArea = require('react-scrollbar/no-css');

Then include scrollArea.css file into your project.

Run the example app

git clone https://github.com/souhe/reactScrollbar.git
cd reactScrollbar
npm install
gulp watch

then open http://localhost:8003.

Using in universal app

ScrollArea component has now full universal app support. It's only one requirement: you have to use react-scrollbar in no-css version and then include css file into your project manually (see this). It's because of issue in webpack style-loader which is used to bundle css styles into main js file.

API

Props

    <ScrollArea
        speed={Number}
        className={String}
        style={Object}
        contentClassName={String}
        contentStyle={Object}
        horizontal={Boolean}
        horizontalContainerStyle={Object}
        horizontalScrollbarStyle={Object}
        vertical={Boolean}
        verticalContainerStyle={Object}
        verticalScrollbarStyle={Object}
        onScroll={(value) => {}}
        contentWindow={Object}
        ownerDocument={Object}
        smoothScrolling={Boolean}
        minScrollSize={Number}
        swapWheelAxes={Boolean}
    >

speed

Scroll speed applied to mouse wheel event. Default: 1

onScroll

onScroll(value: Object) event which can notify the parent component when the container scrolls.

  • value: Object - informations about current position
  • value.leftPosition: Number - content left position (distance in pixels from the left side of container)
  • value.topPosition: Number - content top position (distance in pixels from the top of container)
  • value.containerHeight: Number - container height
  • value.containerWidth: Number - container width
  • value.realHeight: Number - real content height
  • value.realWidth: Number - real content width

className

CSS class names added to main scroll area component.

style

Inline styles applied to the main scroll area component.

contentClassName

CSS class names added to element with scroll area content.

contentStyle

Inline styles applied to element with scroll area content.

horizontal

When set to false, horizontal scrollbar will not be available. Default: true

horizontalContainerStyle

Inline styles applied to horizontal scrollbar's container.

horizontalScrollbarStyle

Inline styles applied to horizontal scrollbar.

vertical

When set to false, vertical scrollbar will not be available, regardless of the content height. Default: true

verticalContainerStyle

Inline styles applied to vertical scrollbar's container.

verticalScrollbarStyle

Inline styles applied to vertical scrollbar.

contentWindow

You can override window to make scrollarea works inside iframe. Default: window

ownerDocument

You can override document to make scrollarea works inside iframe. Default: document

smoothScrolling

When set to true, smooth scrolling for both scrollbars is enabled. Default: false

minScrollSize

Using this prop it's possible to set minimal size in px for both scrollbars.

swapWheelAxes

After set to true, mouse wheel event has swapped directions. So normal scrolling moves horizontal scrollbar and scrolling with SHIFT key moves vertical scrollbar. It could be useful for applications with horizontal layout. Default: false

Context

In context of each <ScrollArea> child could be injected an object scrollArea contains method:

refresh()

That method allows manual refreshing of the scrollbar.

React 0.14 example using ES6 syntax:

class App extends React.Component {
    render(){
        return (
            <ScrollArea>
                <Content />
            </ScrollArea>
        );
    }
}

class Content extends React.Component {
    render(){
        return (
            <div onClick={this.handleSomeAction.bind(this)}> Some long content </div>
        );
    }

    handleSomeAction(){
        this.context.scrollArea.refresh();
    }
}

Content.contextTypes = {
    scrollArea: React.PropTypes.object
};

scrollTop()

It allows to scroll to the top of ScrollArea component.

scrollBottom()

It allows to scroll to the bottom of ScrollArea component.

scrollYTo(topPosition)

It moves vertical scrollbar. topPosition is a distance between the top of scrollArea container and the top of scrollArea content.

scrollLeft()

It allows to scroll to the left of ScrollArea component.

scrollRight()

It allows to scroll to the right of ScrollArea component.

scrollXTo(leftPosition)

It moves horizontal scrollbar. leftPosition is a distance between left edge of scrollArea container and left edge of scrollArea content.

Change log

Every release is documented on the Github Releases page.

License

MIT