1
1
# react-view-slider
2
2
3
- [ ![ Build Status ] ( https://travis-ci.org/ jcoreio/react-view-slider.svg?branch=master )] ( https://travis-ci.org /jcoreio/react-view-slider )
4
- [ ![ Coverage Status] ( https://codecov.io/gh/jcoreio/react-view-slider/branch/master/graph/badge.svg )] ( https://codecov.io/gh/jcoreio/react-view-slider )
3
+ [ ![ CircleCI ] ( https://circleci.com/gh/ jcoreio/react-view-slider.svg?style=svg )] ( https://circleci.com/gh /jcoreio/react-view-slider )
4
+ [ ![ Coverage Status] ( https://codecov.io/gh/jcoreio/react-view-slider )] ( https://codecov.io/gh/jcoreio/react-view-slider )
5
5
[ ![ semantic-release] ( https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg )] ( https://github.com/semantic-release/semantic-release )
6
6
[ ![ Commitizen friendly] ( https://img.shields.io/badge/commitizen-friendly-brightgreen.svg )] ( http://commitizen.github.io/cz-cli/ )
7
+ [ ![ npm version] ( https://badge.fury.io/js/react-view-slider.svg )] ( https://badge.fury.io/js/react-view-slider )
7
8
8
9
Not another carousel; a simpler component that animates horizontal slide transitions between steps of a wizard or levels
9
10
of a drilldown.
10
11
11
-
12
12
# Table of Contents
13
13
14
14
- [ Usage] ( #usage )
@@ -29,7 +29,15 @@ import ViewSlider from 'react-view-slider'
29
29
30
30
// This function renders the view at the given index.
31
31
// At minimum you should pass the key, ref, style, and className props to the returned element.
32
- const renderView = ({index, key, ref, style, className, active, transitionState}) => (
32
+ const renderView = ({
33
+ index,
34
+ key,
35
+ ref,
36
+ style,
37
+ className,
38
+ active,
39
+ transitionState,
40
+ }) => (
33
41
< div key= {key} ref= {ref} style= {style} className= {className}>
34
42
< h3> View {index}< / h3>
35
43
< p> I am {active ? ' active' : ' inactive' }< / p>
@@ -42,10 +50,10 @@ const renderView = ({index, key, ref, style, className, active, transitionState}
42
50
43
51
ReactDOM .render (
44
52
< ViewSlider
45
- renderView= {renderView}
46
- numViews= {3 }
47
- activeView= {0 }
48
- animateHeight
53
+ renderView= {renderView}
54
+ numViews= {3 }
55
+ activeView= {0 }
56
+ animateHeight
49
57
/ > ,
50
58
document .getElementById (' root' )
51
59
)
@@ -55,24 +63,25 @@ ReactDOM.render(
55
63
56
64
##### ` renderView: (props: ViewProps) => React.Element<any> ` ** (required)**
57
65
58
- This function renders each view. ` ViewSlider ` will call it with the following ` props ` :
59
- * ` index: number ` - the index of the view (starting at 0)
60
- * ` key: number ` - the key you should pass to the returned element
61
- * ` ref: (c: HTMLElement) => any ` - the ref you should pass to the returned element
62
- * ` style: Object ` - the style you should pass to the returned element
63
- * ` active: boolean ` - whether the view should currently be showing
64
- * ` transitionState: 'in' | 'out' | 'entering' | 'leaving' ` - the view's transition state
66
+ This function renders each view. ` ViewSlider ` will call it with the following ` props ` :
67
+
68
+ - ` index: number ` - the index of the view (starting at 0)
69
+ - ` key: number ` - the key you should pass to the returned element
70
+ - ` ref: (c: HTMLElement) => any ` - the ref you should pass to the returned element
71
+ - ` style: Object ` - the style you should pass to the returned element
72
+ - ` active: boolean ` - whether the view should currently be showing
73
+ - ` transitionState: 'in' | 'out' | 'entering' | 'leaving' ` - the view's transition state
65
74
66
75
At minimum you should pass the ` key ` , ` ref ` , ` style ` , and ` className ` props to the returned element.
67
76
68
77
##### ` numViews: number ` ** (required)**
69
78
70
- The number of views present. ` ViewSlider ` will only render all views when transitioning; when idle, it will
79
+ The number of views present. ` ViewSlider ` will only render all views when transitioning; when idle, it will
71
80
only render the active view.
72
81
73
82
##### ` activeView: number ` ** (required)**
74
83
75
- The index of the view that should be showing. Whenever you change this, ` ViewSlider ` will animate a horizontal slide
84
+ The index of the view that should be showing. Whenever you change this, ` ViewSlider ` will animate a horizontal slide
76
85
transition to the view at the new index.
77
86
78
87
##### ` keepViewsMounted: boolean ` (default: ` false ` )
@@ -133,12 +142,12 @@ import ViewSlider from 'react-view-slider/lib/withTransitionContext'
133
142
```
134
143
135
144
This works exactly like ` ViewSlider ` except that it renders its views within a ` TransitionContext ` component from
136
- ` react-transition-context ` with the given ` transitionState ` . This is useful for doing things like focusing an ` <input> `
145
+ ` react-transition-context ` with the given ` transitionState ` . This is useful for doing things like focusing an ` <input> `
137
146
element after one of the views has transitioned in.
138
147
139
148
## ` SimpleViewSlider `
140
149
141
- This is a wrapper for ` ViewSlider ` that takes a single child element. It renders the ` ViewSlider ` with the child's key
150
+ This is a wrapper for ` ViewSlider ` that takes a single child element. It renders the ` ViewSlider ` with the child's key
142
151
(converted to a number) as the ` activeView ` and caches past child elements by key.
143
152
144
153
### Example
@@ -148,24 +157,19 @@ import SimpleViewSlider from 'react-view-slider/lib/simple'
148
157
149
158
ReactDOM .render (
150
159
< SimpleViewSlider>
151
- < div key= {0 }>
152
- This is view 0
153
- < / div>
160
+ < div key= {0 }> This is view 0 < / div>
154
161
< / SimpleViewSlider> ,
155
162
document .getElementById (' root' )
156
163
)
157
164
158
165
// Rendering a child with a different key will trigger the transition.
159
166
ReactDOM .render (
160
167
< SimpleViewSlider>
161
- < div key= {1 }>
162
- This is view 1
163
- < / div>
168
+ < div key= {1 }> This is view 1 < / div>
164
169
< / SimpleViewSlider> ,
165
170
document .getElementById (' root' )
166
171
)
167
172
```
168
173
169
174
If you want to use ` SimpleViewSlider ` with ` react-transition-context ` ,
170
175
use ` react-view-slider/lib/simpleWithTransitionContext ` .
171
-
0 commit comments