@@ -3,164 +3,164 @@ import Carousel from '../index';
3
3
4
4
require ( '../carousel.less' ) ;
5
5
6
- export default {
7
- component : Carousel ,
8
- title : 'Carousel'
6
+ export default {
7
+ component : Carousel ,
8
+ title : 'Carousel'
9
9
} ;
10
10
11
11
const IMAGES = [
12
- 'http://picsum.photos/400/300' ,
13
- 'http://picsum.photos/275/300' ,
14
- 'http://picsum.photos/400/300' ,
15
- 'http://picsum.photos/350/300' ,
16
- 'http://picsum.photos/250/300' ,
17
- 'http://picsum.photos/375/300' ,
18
- 'http://picsum.photos/425/300' ,
19
- 'http://picsum.photos/325/300'
20
- ] ;
12
+ 'http://picsum.photos/400/300' ,
13
+ 'http://picsum.photos/275/300' ,
14
+ 'http://picsum.photos/400/300' ,
15
+ 'http://picsum.photos/350/300' ,
16
+ 'http://picsum.photos/250/300' ,
17
+ 'http://picsum.photos/375/300' ,
18
+ 'http://picsum.photos/425/300' ,
19
+ 'http://picsum.photos/325/300'
20
+ ] ;
21
21
22
22
const imgElements = IMAGES . map ( ( image , index ) => < img src = { image } key = { index } /> ) ;
23
23
24
24
const CustomDots = ( { numSlides, selectedIndex, goToSlide, title } ) => {
25
- const dots = [ ] ;
26
-
27
- for ( let index = 0 ; index < numSlides ; index ++ ) {
28
- const buttonStyle = {
29
- border : 'none' ,
30
- cursor : 'pointer' ,
31
- background : 'transparent'
32
- } ;
33
-
34
- if ( index === selectedIndex ) {
35
- buttonStyle . color = 'red' ;
36
- }
37
-
38
- dots . push (
39
- < li key = { `dot-${ index } ` } style = { { display : 'inline-block' } } >
40
- < button style = { buttonStyle } onClick = { goToSlide . bind ( null , index ) } > •</ button >
41
- </ li >
42
- ) ;
25
+ const dots = [ ] ;
26
+
27
+ for ( let index = 0 ; index < numSlides ; index ++ ) {
28
+ const buttonStyle = {
29
+ border : 'none' ,
30
+ cursor : 'pointer' ,
31
+ background : 'transparent'
32
+ } ;
33
+
34
+ if ( index === selectedIndex ) {
35
+ buttonStyle . color = 'red' ;
43
36
}
44
37
45
- return (
46
- < div style = { { position : 'absolute' , top : '10px' , right : '10px' , background : 'rgba(114, 114, 114, 0.6)' , zIndex : '1' } } >
47
- < h2 > { title } </ h2 >
48
- < ul style = { { listStyle : 'none' , padding : '0' } } >
49
- { dots }
50
- </ ul >
51
- </ div >
38
+ dots . push (
39
+ < li key = { `dot-${ index } ` } style = { { display : 'inline-block' } } >
40
+ < button style = { buttonStyle } onClick = { goToSlide . bind ( null , index ) } > •</ button >
41
+ </ li >
52
42
) ;
53
- }
43
+ }
44
+
45
+ return (
46
+ < div style = { { position : 'absolute' , top : '10px' , right : '10px' , background : 'rgba(114, 114, 114, 0.6)' , zIndex : '1' } } >
47
+ < h2 > { title } </ h2 >
48
+ < ul style = { { listStyle : 'none' , padding : '0' } } >
49
+ { dots }
50
+ </ ul >
51
+ </ div >
52
+ ) ;
53
+ } ;
54
54
55
- export const infiniteWithCellPadding = ( ) =>
56
- < Carousel width = '450px' cellPadding = { 5 } >
57
- { imgElements }
58
- </ Carousel >
55
+ export const infiniteWithCellPadding = ( ) =>
56
+ < Carousel width = '450px' cellPadding = { 5 } >
57
+ { imgElements }
58
+ </ Carousel > ;
59
59
60
60
export const nonInfiniteWithCellPadding = ( ) =>
61
- < Carousel infinite = { false } width = '450px' cellPadding = { 5 } >
62
- { imgElements }
63
- </ Carousel >
64
-
65
- export const fadeTransition = ( ) =>
66
- < Carousel
67
- width = '450px'
68
- slideHeight = '300px'
69
- transitionDuration = { 1000 }
70
- draggable = { false }
71
- transition = 'fade'
72
- >
73
- { imgElements }
74
- </ Carousel >
61
+ < Carousel infinite = { false } width = '450px' cellPadding = { 5 } >
62
+ { imgElements }
63
+ </ Carousel > ;
64
+
65
+ export const fadeTransition = ( ) =>
66
+ < Carousel
67
+ width = '450px'
68
+ slideHeight = '300px'
69
+ transitionDuration = { 1000 }
70
+ draggable = { false }
71
+ transition = 'fade'
72
+ >
73
+ { imgElements }
74
+ </ Carousel > ;
75
75
76
76
export const infiniteWithOnly2Slides = ( ) =>
77
- < Carousel width = '450px' arrows = { false } slideHeight = '300px' >
78
- < img src = 'http://picsum.photos/325/300' />
79
- < img src = 'http://picsum.photos/350/300' />
80
- </ Carousel >
81
-
82
- export const infiniteWithOnly1Slide = ( ) =>
83
- < Carousel
84
- width = '450px'
85
- infinite = { true }
86
- arrows = { false }
87
- dots = { false }
88
- >
89
- < img src = 'http://picsum.photos/325/300' />
90
- </ Carousel >
91
-
92
- export const autoplayWithBackgroundImages = ( ) =>
93
- < Carousel
94
- width = '100%'
95
- slideWidth = '100%'
96
- slideHeight = '70vh'
97
- arrows = { false }
98
- autoplay = { true }
99
- >
100
- < div style = { { backgroundImage : 'url(http://picsum.photos/600/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
101
- < div style = { { backgroundImage : 'url(http://picsum.photos/650/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
102
- < div style = { { backgroundImage : 'url(http://picsum.photos/675/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
103
- < div style = { { backgroundImage : 'url(http://picsum.photos/700/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
104
- </ Carousel >
105
-
106
- export const backgroundImagesWithFade = ( ) =>
107
- < Carousel
108
- width = '100%'
109
- slideWidth = '100%'
110
- slideHeight = '70vh'
111
- transition = 'fade'
112
- transitionDuration = { 1000 }
113
- autoplay = { true }
114
- arrows = { true }
115
- >
116
- < div style = { { backgroundImage : 'url(http://picsum.photos/600/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
117
- < div style = { { backgroundImage : 'url(http://picsum.photos/650/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
118
- < div style = { { backgroundImage : 'url(http://picsum.photos/675/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
119
- < div style = { { backgroundImage : 'url(http://picsum.photos/700/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
120
- < div style = { { backgroundImage : 'url(http://picsum.photos/750/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
121
- < div style = { { backgroundImage : 'url(http://picsum.photos/725/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
122
- < div style = { { backgroundImage : 'url(http://picsum.photos/625/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
123
- </ Carousel >
124
-
125
- export const customDotsComponent = ( ) =>
126
- < Carousel
127
- width = '450px'
128
- cellPadding = { 5 }
129
- infinite = { false }
130
- dots = { false }
131
- arrows = { false }
132
- autoplay = { true }
133
- controls = { [ { component : CustomDots , props : { title : 'My Slides' } , position : 'top' } ] }
134
- transitionDuration = { 0 }
135
- >
136
- { imgElements }
137
- </ Carousel >
77
+ < Carousel width = '450px' arrows = { false } slideHeight = '300px' >
78
+ < img src = 'http://picsum.photos/325/300' />
79
+ < img src = 'http://picsum.photos/350/300' />
80
+ </ Carousel > ;
81
+
82
+ export const infiniteWithOnly1Slide = ( ) =>
83
+ < Carousel
84
+ width = '450px'
85
+ infinite = { true }
86
+ arrows = { false }
87
+ dots = { false }
88
+ >
89
+ < img src = 'http://picsum.photos/325/300' />
90
+ </ Carousel > ;
91
+
92
+ export const autoplayWithBackgroundImages = ( ) =>
93
+ < Carousel
94
+ width = '100%'
95
+ slideWidth = '100%'
96
+ slideHeight = '70vh'
97
+ arrows = { false }
98
+ autoplay = { true }
99
+ >
100
+ < div style = { { backgroundImage : 'url(http://picsum.photos/600/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
101
+ < div style = { { backgroundImage : 'url(http://picsum.photos/650/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
102
+ < div style = { { backgroundImage : 'url(http://picsum.photos/675/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
103
+ < div style = { { backgroundImage : 'url(http://picsum.photos/700/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
104
+ </ Carousel > ;
105
+
106
+ export const backgroundImagesWithFade = ( ) =>
107
+ < Carousel
108
+ width = '100%'
109
+ slideWidth = '100%'
110
+ slideHeight = '70vh'
111
+ transition = 'fade'
112
+ transitionDuration = { 1000 }
113
+ autoplay = { true }
114
+ arrows = { true }
115
+ >
116
+ < div style = { { backgroundImage : 'url(http://picsum.photos/600/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
117
+ < div style = { { backgroundImage : 'url(http://picsum.photos/650/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
118
+ < div style = { { backgroundImage : 'url(http://picsum.photos/675/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
119
+ < div style = { { backgroundImage : 'url(http://picsum.photos/700/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
120
+ < div style = { { backgroundImage : 'url(http://picsum.photos/750/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
121
+ < div style = { { backgroundImage : 'url(http://picsum.photos/725/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
122
+ < div style = { { backgroundImage : 'url(http://picsum.photos/625/300)' , backgroundSize : 'cover' , height : '100%' , width : '100%' } } />
123
+ </ Carousel > ;
124
+
125
+ export const customDotsComponent = ( ) =>
126
+ < Carousel
127
+ width = '450px'
128
+ cellPadding = { 5 }
129
+ infinite = { false }
130
+ dots = { false }
131
+ arrows = { false }
132
+ autoplay = { true }
133
+ controls = { [ { component : CustomDots , props : { title : 'My Slides' } , position : 'top' } ] }
134
+ transitionDuration = { 0 }
135
+ >
136
+ { imgElements }
137
+ </ Carousel > ;
138
138
139
139
export const addImages = ( ) => {
140
- const [ images , setImages ] = useState ( [ IMAGES [ 0 ] ] ) ;
140
+ const [ images , setImages ] = useState ( [ IMAGES [ 0 ] ] ) ;
141
141
142
- const addImage = ( ) => {
143
- if ( images . length < IMAGES . length ) {
144
- setImages ( images . concat ( IMAGES [ images . length ] ) ) ;
145
- }
142
+ const addImage = ( ) => {
143
+ if ( images . length < IMAGES . length ) {
144
+ setImages ( images . concat ( IMAGES [ images . length ] ) ) ;
146
145
}
146
+ } ;
147
147
148
- return (
149
- < Fragment >
150
- < Carousel
151
- width = '450px'
152
- cellPadding = { 5 }
153
- infinite = { true }
154
- dots = { false }
155
- arrows = { false }
156
- autoplay = { false }
157
- controls = { [ { component : CustomDots , props : { title : 'My Slides' } , position : 'top' } ] }
158
- >
159
- {
160
- images . map ( ( image , index ) => < img key = { index } src = { image } /> )
161
- }
162
- </ Carousel >
163
- < button onClick = { addImage } > Add Image</ button >
164
- </ Fragment >
165
- )
166
- }
148
+ return (
149
+ < Fragment >
150
+ < Carousel
151
+ width = '450px'
152
+ cellPadding = { 5 }
153
+ infinite = { true }
154
+ dots = { false }
155
+ arrows = { false }
156
+ autoplay = { false }
157
+ controls = { [ { component : CustomDots , props : { title : 'My Slides' } , position : 'top' } ] }
158
+ >
159
+ {
160
+ images . map ( ( image , index ) => < img key = { index } src = { image } /> )
161
+ }
162
+ </ Carousel >
163
+ < button onClick = { addImage } > Add Image</ button >
164
+ </ Fragment >
165
+ ) ;
166
+ } ;
0 commit comments