1- import React , { useState , useRef } from "react" ;
2- import Carousel from "react-elastic-carousel" ;
1+ import React , { useState , useRef , useEffect } from "react" ;
2+ import Carousel from "../../src/ react-elastic-carousel/components/Carousel " ;
33import styled from "styled-components" ;
44
55const Item = styled . div `
@@ -16,7 +16,6 @@ const Item = styled.div`
1616const Layout = styled . div `
1717 display: flex;
1818 flex-direction: column;
19- justify-content: center;
2019 align-items: center;
2120 height: 100vh;
2221` ;
@@ -47,8 +46,12 @@ const CheckBox = ({ label, onToggle, ...rest }) => {
4746 ) ;
4847} ;
4948
49+ const serverItems = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ;
50+
5051const DemoApp = ( ) => {
51- const [ items , setItems ] = useState ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ) ;
52+ const [ show , setShow ] = useState ( true ) ;
53+ const [ enableAutoPlay , setEnableAutoPlay ] = useState ( false ) ;
54+ const [ items , setItems ] = useState ( [ ] ) ;
5255 const [ itemsToShow , setItemsToShow ] = useState ( 3 ) ;
5356 const [ showArrows , setShowArrows ] = useState ( true ) ;
5457 const [ pagination , setPagination ] = useState ( true ) ;
@@ -68,9 +71,20 @@ const DemoApp = () => {
6871
6972 const goTo = ( { target } ) => carouselRef . current . goTo ( Number ( target . value ) ) ;
7073
74+ useEffect ( ( ) => {
75+ setTimeout ( ( ) => {
76+ setItems ( serverItems ) ;
77+ } , 2500 ) ;
78+ } , [ ] ) ;
79+
7180 return (
7281 < Layout >
7382 < ControlsLayout >
83+ < StyledControlFields >
84+ < button onClick = { ( ) => setShow ( ( o ) => ! o ) } >
85+ { `${ show ? "Hide" : "Show" } Carousel` }
86+ </ button >
87+ </ StyledControlFields >
7488 < StyledControlFields >
7589 < button onClick = { addItem } > Add Item</ button >
7690 < button onClick = { removeItem } > Remove Item</ button >
@@ -102,18 +116,26 @@ const DemoApp = () => {
102116 checked = { verticalMode }
103117 onToggle = { setVerticalMode }
104118 />
119+ < CheckBox
120+ label = "Auto Play"
121+ checked = { enableAutoPlay }
122+ onToggle = { setEnableAutoPlay }
123+ />
105124 </ ControlsLayout >
106- < Carousel
107- ref = { carouselRef }
108- verticalMode = { verticalMode }
109- itemsToShow = { itemsToShow }
110- showArrows = { showArrows }
111- pagination = { pagination }
112- >
113- { items . map ( ( item ) => (
114- < Item key = { item } > { item } </ Item >
115- ) ) }
116- </ Carousel >
125+ { show && (
126+ < Carousel
127+ enableAutoPlay = { enableAutoPlay }
128+ ref = { carouselRef }
129+ verticalMode = { verticalMode }
130+ itemsToShow = { itemsToShow }
131+ showArrows = { showArrows }
132+ pagination = { pagination }
133+ >
134+ { items . map ( ( item ) => (
135+ < Item key = { item } > { item } </ Item >
136+ ) ) }
137+ </ Carousel >
138+ ) }
117139 </ Layout >
118140 ) ;
119141} ;
0 commit comments