1.3.0 • Published 7 years ago

react-scrolling-lock v1.3.0

Weekly downloads
91
License
MIT
Repository
github
Last release
7 years ago

React Scrolling Lock

build status npm version

This is a higher order component for preventing page scrolling outside of a given component

It supports both class based components and stateless functional components.

Demo

alt text

https://viralganatra.github.io/demos/react-scrolling-lock/

To build this example, clone this repo, navigate to the example directory and run:

yarn install
npm run start

Installation

Using yarn

yarn add react-scrolling-lock

or NPM

npm install --save react-scrolling-lock

How to use

Basic functionality

import React from 'react';

const Component = () => {
    const scrollingContainerStyles = {
        height: '300px',
        overflow: 'auto',
        width: '200px',
    };

    const scrollingComponentStyles = {
        height: '600px',
    };

    return (
        <div style={scrollingContainerStyles}>
            <div style={scrollingComponentStyles}>Scrolling Component</div>
        </div>
    );
};

export default Component;
import React from 'react';
import ScrollingLock from 'react-scrolling-lock';
import ComponentToScrollLock from './component';

const ComposedComponent = ScrollingLock()(ComponentToScrollLock);

const Demo = () => (
    <div style={{ height: '3000px' }}>
        <ComposedComponent />
    </div>
);

export default Demo;

Customising

This higher order function will add a wrapping div element to your component. By default it will add a style with display: inline-block. If you wish to use a class name you can pass an options object and use the className attribute:

import React from 'react';
import ScrollingLock from 'react-scrolling-lock';
import ComponentToScrollLock from './component';

const ComposedComponent = ScrollingLock({
    className: 'my-class-name'
})(ComponentToScrollLock);

const Demo = () => (
    <div style={{ height: '3000px' }}>
        <ComposedComponent />
    </div>
);

export default Demo;

Compatibility

React 0.14 or greater is required.

License

MIT

1.3.0

7 years ago

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago