MCPcopy Create free account
hub / github.com/reactstrap/reactstrap / Example

Function Example

stories/examples/Carousel/CarouselExample.js:31–93  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

29];
30
31function Example(args) {
32 const [activeIndex, setActiveIndex] = useState(0);
33 const [animating, setAnimating] = useState(false);
34
35 const next = () => {
36 if (animating) return;
37 const nextIndex = activeIndex === items.length - 1 ? 0 : activeIndex + 1;
38 setActiveIndex(nextIndex);
39 };
40
41 const previous = () => {
42 if (animating) return;
43 const nextIndex = activeIndex === 0 ? items.length - 1 : activeIndex - 1;
44 setActiveIndex(nextIndex);
45 };
46
47 const goToIndex = (newIndex) => {
48 if (animating) return;
49 setActiveIndex(newIndex);
50 };
51
52 const slides = items.map((item) => {
53 return (
54 <CarouselItem
55 onExiting={() => setAnimating(true)}
56 onExited={() => setAnimating(false)}
57 key={item.src}
58 >
59 <img src={item.src} alt={item.altText} />
60 <CarouselCaption
61 captionText={item.caption}
62 captionHeader={item.caption}
63 />
64 </CarouselItem>
65 );
66 });
67
68 return (
69 <Carousel
70 activeIndex={activeIndex}
71 next={next}
72 previous={previous}
73 {...args}
74 >
75 <CarouselIndicators
76 items={items}
77 activeIndex={activeIndex}
78 onClickHandler={goToIndex}
79 />
80 {slides}
81 <CarouselControl
82 direction="prev"
83 directionText="Previous"
84 onClickHandler={previous}
85 />
86 <CarouselControl
87 direction="next"
88 directionText="Next"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…