yahoo/react-stickynode

Name: react-stickynode

Owner: Yahoo Inc.

Description: A performant and comprehensive React sticky component.

Created: 2015-10-28 14:58:19.0

Updated: 2018-05-24 15:15:56.0

Pushed: 2018-05-24 15:15:54.0

Homepage:

Size: 207

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

react-stickynode

npm version Build Status Coverage Status Dependency Status devDependency Status

A performant and comprehensive React sticky component.

A sticky component wraps a sticky target and remains the target in viewport as an user scrolls the page. Most sticky components handle the case where the sticky target is shorter then viewport, but not the case where a sticky target taller then viewport. The reason is the behavior expectation and implementation is much more complicated.

react-stickynode handles not only regular case but the long sticky target case in a natural way. In regular case, when scrolling page down, react-stickynode will stick to the top of viewport. But in the case of taller sticky target, it will scroll along with the page until its bottom reaches the bottom of viewport. In other words, it looks like the bottom of viewport pulls the bottom of a sticky target down when scrolling page down. On the other hand, when scrolling page up, the top of viewport pulls the top of a sticky target up.

This behavior gives the content in a tall sticky target more chance to be shown. This is especially good for the case where many ADs are in the right rail.

Another highlight is that react-stickynode can handle the case where a sticky target uses percentage as its width unit. For a responsive designed page, it is especially useful.

Features
Usage

The sticky uses Modernizr csstransforms3d and prefixed features to detect IE8/9, so it can downgrade not to use transform3d.

http://modernizr.com/download/?-csstransforms3d-prefixed

rt Sticky from 'react-stickynode';

cky enabled={true} top={50} bottomBoundary={1200}>
<YourComponent/>
icky>
s
rt Sticky from 'react-stickynode';

cky top='#header' bottomBoundary='#content'>
<YourComponent/>
icky>
Props
Handling State Change

You can be notified when the state of the sticky component changes by passing a callback to the onStateChange prop. The callback will receive an object in the format {status: CURRENT_STATUS}, with CURRENT_STATUS being an integer representing the status:

You can access the statuses as static constants to use for comparison.

rt Sticky from 'react-stickynode';

t handleStateChange = (status) => {
if (status.status === Sticky.STATUS_FIXED) {
    console.log('the component is sticky');
}


cky onStateChange={handleStateChange}>
<YourComponent/>
icky>
Freezing

You can provide a function in the shouldFreeze prop which will tell the component to temporarily stop updating during prop and state changes, as well as ignore scroll and resize events. This function should return a boolean indicating whether the component should currently be frozen.

Install & Development

Install

install react-stickynode

Unit Test

t unit
License

This software is free to use under the BSD license. See the LICENSE file for license text and copyright information.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.