Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-view-pager

souporserious93.7kMIT0.6.0

View-Pager/Slider/Carousel powered by React Motion.

react, component, slider, carousel, touch, responsive, flick, gallery, DOM, browser

readme

React View Pager (Prerelease)

Dependency Status

View-Pager/Slider/Carousel powered by React Motion.

react-motion-slider

Note before using

Use at your own risk, API's are subject to change. It's been fairly stable these last few months, but still might change slightly. Once the outstanding issues are fixed I will release 1.0.0.

Usage

yarn add react-view-pager

npm install react-view-pager --save

<script src="https://unpkg.com/react-view-pager/dist/react-view-pager.js"></script>
(UMD library exposed as `ReactViewPager`)

Example

import { ViewPager, Frame, Track, View } from 'react-view-pager'

<ViewPager tag="main">
  <Frame className="frame">
    <Track
      ref={c => this.track = c}
      viewsToShow={2}
      infinite
      className="track"
    >
      <View className="view">1</View>
      <View className="view">2</View>
      <View className="view">3</View>
      <View className="view">4</View>
    </Track>
  </Frame>
  <nav className="pager-controls">
    <a
      className="pager-control pager-control--prev"
      onClick={() => this.track.prev()}
    >
      Prev
    </a>
    <a
      className="pager-control pager-control--next"
      onClick={() => this.track.next()}
    >
      Next
    </a>
  </nav>
</ViewPager>

ViewPager Props

tag: PropTypes.string

The HTML tag for this element. Defaults to div.

Frame Props

tag: PropTypes.string

The HTML tag for this element. Defaults to div.

autoSize: PropTypes.oneOf([true, false, 'width', 'height'])

Animates the wrapper's width and/or height to fit the current view. Defaults to false.

accessibility: PropTypes.bool

Enable tabbing and keyboard navigation.

springConfig: React.PropTypes.objectOf(React.PropTypes.number)

Accepts a React Motion spring config.

Track Props

tag: PropTypes.string

The HTML tag for this element. Defaults to div.

currentView: PropTypes.any

Specify the index or key of a view to move to that view. Use with onViewChange to control the state of the pager.

viewsToShow: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['auto'])])

The number of views visible in the frame at one time. Defaults to 1. Use auto to respect the views's natural or defined dimensions.

viewsToMove: PropTypes.number

The number of views to move upon using prev and next methods. Defaults to 1.

align: PropTypes.number

Pass any number to offset the view from the start of the track. For example, 0 aligns to the start of the track, 0.5 to the center, and 1 aligns to the end.

contain: PropTypes.bool

Prevents empty space from showing in frame. Defaults to false.

infinite: PropTypes.bool

Prepare your pager for intergalactic space travel. Allows the track to wrap to the beginning/end when moving to a view. To infinity and beyond!

instant: PropTypes.bool

Move to a view instantly without any animation. This will control the internal instant state inside of the component.

axis: PropTypes.oneOf(['x', 'y'])

Which axis the track moves on. Defaults to x.

animations: PropTypes.array

Define a limitless array of animation stops. Each object in the array requires a prop and stops property along with an optional unit property.

// scale and fade views as they enter and leave
const animations = [{
  prop: 'scale',
  stops: [
    [-200, 0.85],
    [0, 1],
    [200, 0.85]
  ]
}, {
  prop: 'opacity',
  stops: [
    [-200, 0.15],
    [0, 1],
    [200, 0.15]
  ]
}]

swipe: PropTypes.oneOf([true, false, 'touch', 'mouse'])

Enable touch and/or mouse dragging. Defaults to true.

swipeThreshold: PropTypes.number

The amount the user must swipe to advance views. (frameWidth * swipeThreshold). Defaults to 0.5.

flickTimeout: PropTypes.number

The amount of time in milliseconds that determines if a swipe was a flick or not.

rightToLeft: PropTypes.bool (Coming Soon)

lazyLoad: PropTypes.bool (Coming Soon)

springConfig: React.PropTypes.objectOf(React.PropTypes.number)

Accepts a React Motion spring config.

onSwipeStart: PropTypes.func

Prop callback fired before swipe.

onSwipeMove: PropTypes.func

Prop callback fired during swipe.

onSwipeEnd: PropTypes.func

Prop callback fired after swipe.

onScroll: PropTypes.func

Prop callback fired when track is scrolling. Useful for parallax or progress bars.

onViewChange: PropTypes.func

Prop callback fired when view changes. Passes back the newly selected indicies.

onRest: PropTypes.func

Prop callback fired after track scrolling animation settles.

Public methods

prev

Moves to the previous view.

next

Advances to the next view.

scrollTo

Scroll to a view by it's index or key.

View Props

tag: PropTypes.string

The HTML tag for this element. Defaults to div.

Running Locally

clone repo

git clone git@github.com:souporserious/react-view-pager.git

move into folder

cd ~/react-view-pager

install dependencies

npm install

run dev mode

npm run dev

open your browser and visit: http://localhost:8080/

changelog

CHANGELOG

0.6.0

Update dependencies

Add peer dependencies for React 16

0.5.1

Update react-motion #63

0.5.0

Support React 15.5.0 PropTypes #58

Update react-motion and resize-observer-polyfill dependency version

0.5.0-prerelease.10

Fix build on NPM

0.5.0-prerelease.9

Replace minivents with mitt

Add tabbable so we can trap focus within current slides

0.5.0-prerelease.8

Use ResizeObserver.default if available. Fixes #48

0.5.0-prerelease.7

Only require ResizeObserver polyfill when window is available

Stop observing view after it has been removed

0.5.0-prerelease.6

Apply spring config prop in Frame component

0.5.0-prerelease.5

Fix old destroy method left over from window resize

Listen for hydration event to update Frame component size

0.5.0-prerelease.4

Use resize-observer-polyfill to make sure the pager is always calculated with proper view dimensions

Hide view visually until it has been added to the pager

General cleanup

0.5.0-prerelease.3

emit viewChange when viewsToShow options have changed

beforeViewChange -> onViewChange

afterViewChange -> onRest

Allow autoSize prop to size width and/or height

Use verticalAlign: top on views to keep them in frame when using autoSize

Added mandatory View component that replaces previous views that were cloned. This will help us keep some control over props that need to be applied.

0.5.0-prerelease.2

Fixes updating props after mount

Fixes the indices in callbacks to return proper indices in view

Replaced from, to object returned in beforeViewChange callback with currentIndicies

No more absolute positioning! This is cool because now we can use things like flexbox and not get weird values due to absolute positioned views.

0.5.0-prerelease.1

General cleanup

Fixes Avoid call to window in window-less environment #28

Fixes beforeViewChange being called twice

Fixes onScroll callback to allow use of setState

Moved main props to the Track component

Added ViewPager wrapper component. It was a hard decision to add another component, but this will allow some cool animations and other features.

Added AnimatedView component to allow animations that are relative to the pager.

Updated animation-bus to 0.2.0

0.5.0-prerelease

Major Update again, sorry for the big changes. This has been a rough road, but I feel it has finally smoothed out and I'm very happy with where everything is at.

Name Change react-motion-slider -> react-view-pager

Breaking Changes

Props changed

currentIndex && currentKey -> currentView

slidesToShow -> viewsToShow

slidesToMove -> viewsToMove

vertical -> axis

autoHeight -> autoSize

Props added

contain

animations

accessibility

onSwipeStart

onSwipeMove

onSwipeEnd

onScroll

beforeViewChange

afterViewChange

0.4.2

Use constructor in Slider to fix undefined props in IE10

0.4.1

Fix npm build

0.4.0

Refactored all code... again. Props are mostly the same, some new ones added. Future changes will be documented better.

0.3.0

Breaking Changes Upgraded to React Motion 0.3.0

0.2.0

Breaking Changes Refactored almost all code, somewhat similiar API, touch support and some other props were removed for now, will be back in soon

Slider now moves directly to new slides rather than running through everything in between

If using a custom component be sure to pass the style prop passed in to apply proper styles for moving slides around. Look in example folder for implementation.

0.1.0

Breaking Changes defaultSlide prop is now currentKey, pass the slides key to navigate to it

exposed as the component Slider now instead of and an object