animates horizontal slide transitions between steps of a wizard or levels of a drilldown
npm install react-view-slider




Not another carousel; animates horizontal slide transitions between steps of
a form or levels of a drilldown.
- Usage
- Props
- SimpleViewSlider
``sh`
npm install --save react-view-slider
`js
import React from 'react'
import ReactDOM from 'react-dom'
import ViewSlider from 'react-view-slider'
// This function renders the view at the given index.
const renderView = ({ index, active, transitionState }) => (
I am {active ? 'active' : 'inactive'}
transitionState: {transitionState}
// activeView specifies which view should currently be showing. Whenever you change it, ViewSlider will make the
// view at the new activeView horizontally slide into view.
ReactDOM.render(
numViews={3}
activeView={0}
animateHeight
/>,
document.getElementById('root')
)
`
##### renderView: (props: ViewProps) => React.Node (required)
This function renders each view. ViewSlider will call it with the following props:
- index: number - the index of the view (starting at 0)active: boolean
- - whether the view should currently be showingtransitionState: 'in' | 'out' | 'entering' | 'leaving'
- - the view's transition state
##### numViews: number (required)
The number of views present. ViewSlider will only render all views when transitioning; when idle, it will
only render the active view.
##### activeView: number (required)
The index of the view that should be showing. Whenever you change this, ViewSlider will animate a horizontal slide
transition to the view at the new index.
##### spacing: number (default: 1)
How much horizontal space to put between the views. spacing={1.5} will spacespacing={2}
the views apart by 50% of the width, will space the views apart
by 100% of the width, etc.
Views without much horizontal padding or margin of their own will look jammed
together during transitions with a default spacing of 1, so in that casespacing
you'll want to increase the .
A negative number will reverse the view order;
spacing={-1.5} will arrange views from right to left with 50% width viewrtl
spacing. You can also use the property for this, especially if you wantdirection: rtl
the views to inherit for their own content layout.
##### rtl: boolean (default: false)
Whether to use right-to-left layout. This will reverse the view order and apply
direction: rtl to the viewport style, and each view will inherit that layout
direction for its own content as well.
To reverse the view order without
changing layout direction of each view's content, you can use a negative number
for spacing.
##### keepViewsMounted: boolean (default: false)
If true, ViewSlider will keep all views mounted after transitioning, not just the active view.ViewSlider
You may want to use this if there is a noticeable lag while other views mount at the beginning of a transition.
However, it disables height animation and will cause the height of to be the max of all views' heights,fillParent={true}
so you will get best results if you also use .
##### animateHeight: boolean (default: true)
If truthy, ViewSlider will animate its height to match the height of the view at activeView.
##### transitionDuration: number (default: 500)
The duration of the transition between views.
##### transitionTimingFunction: string (default: 'ease')
The timing function for the transition between views.
##### onSlideTransitionEnd: () => any
If given, will be called when the slide transition ends.
##### prefixer: Prefixer
If given, overrides the inline-style-prefixer used to autoprefix inline styles.
##### fillParent: boolean (default: false)
If truthy, ViewSlider will use absolute positioning on itself and its views to fill its parent element.
##### className: string
Any extra class names to add to the root element.
##### style: Object
Extra inline styles to add to the root element.
##### viewportClassName: string
Any extra class names to add to the inner "viewport" element.
##### viewportStyle: Object
Extra inline styles to add to the inner "viewport" element.
##### viewStyle: Object
Extra inline styles to add to the view wrapper elements.
##### innerViewWrapperStyle: Object
Extra inline styles to add to the inner div between the viewStyle div and your
view content element. (The inner div was added to ensure perfect height
animation.)
##### rootRef: (node: ?HTMLDivElement) => any
The ref to pass to the root
element rendered by ViewSlider.#####
viewportRef: (node: ?HTMLDivElement) => anyThe
ref to pass to the viewport element rendered inside the root by ViewSlider.SimpleViewSliderThis is a wrapper for
ViewSlider that takes a single child element. It renders the ViewSlider with the child's key
(converted to a number) as the activeView and caches past child elements by key.$3
`js
import SimpleViewSlider from 'react-view-slider/simple'ReactDOM.render(
This is view 0
,
document.getElementById('root')
)
// Rendering a child with a different key will trigger the transition.
ReactDOM.render(
This is view 1
,
document.getElementById('root')
)
`$3
#####
keepPrecedingViewsMounted: boolean (default: false)If
true, SimpleViewSlider will keep views preceding the active view mounted, but not views following the active view.
(As mentioned above, the order is determined by the children's key`s.)