// the current active slide of the carousel
activeIndex: PropTypes.number,
// a function which should advance the carousel to the next slide (via activeIndex)
next: PropTypes.func.isRequired,
// a function which should advance the carousel to the previous slide (via activeIndex)
previous: PropTypes.func.isRequired,
// controls if the left and right arrow keys should control the carousel
keyboard: PropTypes.bool,
/* If set to "hover", pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on
* mouseleave. If set to false, hovering over the carousel won't pause it. (default: "hover")
*/
pause: PropTypes.oneOf(['hover', false]),
// Autoplays the carousel after the user manually cycles the first item. If "carousel", autoplays the carousel on load.
// This is how bootstrap defines it... I would prefer a bool named autoplay or something...
ride: PropTypes.oneOf(['carousel']),
// the interval at which the carousel automatically cycles (default: 5000)
interval: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
PropTypes.bool,
]),
children: PropTypes.array,
// called when the mouse enters the Carousel
mouseEnter: PropTypes.func,
// called when the mouse exits the Carousel
mouseLeave: PropTypes.func,
// controls whether the slide animation on the Carousel works or not
slide: PropTypes.bool,
cssModule: PropTypes.object,
};
CarouselItem Properties
CarouselItem.propTypes = {
...Transition.propTypes,
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
in: PropTypes.bool,
cssModule: PropTypes.object,
children: PropTypes.node,
slide: PropTypes.bool,
};
CarouselIndicators Properties
CarouselIndicators.propTypes = {
items: PropTypes.array.isRequired,
activeIndex: PropTypes.number.isRequired,
cssModule: PropTypes.object,
onClickHandler: PropTypes.func.isRequired
};
CarouselCaption.propTypes = {
captionHeader: PropTypes.string,
captionText: PropTypes.string.isRequired,
};
Uncontrolled Carousel
UncontrolledCarousel.propTypes = {
items: PropTypes.array.isRequired,
indicators: PropTypes.bool, // default: true
controls: PropTypes.bool, // default: true
autoPlay: PropTypes.bool, // default: true
};
Carousel using a tag and classname
import React, { Component } from 'react';
import {
Carousel,
CarouselItem,
CarouselControl,
CarouselIndicators,
CarouselCaption
} from 'reactstrap';
const items = [
{
id: 1,
altText: 'Slide 1',
caption: 'Slide 1'
},
{
id: 2,
altText: 'Slide 2',
caption: 'Slide 2'
},
{
id: 3,
altText: 'Slide 3',
caption: 'Slide 3'
}
];
class Example extends Component {
constructor(props) {
super(props);
this.state = { activeIndex: 0 };
this.next = this.next.bind(this);
this.previous = this.previous.bind(this);
this.goToIndex = this.goToIndex.bind(this);
this.onExiting = this.onExiting.bind(this);
this.onExited = this.onExited.bind(this);
}
onExiting() {
this.animating = true;
}
onExited() {
this.animating = false;
}
next() {
if (this.animating) return;
}
previous() {
if (this.animating) return;
const nextIndex = this.state.activeIndex === 0 ? items.length - 1 : this.state.activeIndex - 1;
this.setState({ activeIndex: nextIndex });
}
goToIndex(newIndex) {
if (this.animating) return;
this.setState({ activeIndex: newIndex });
}
render() {
const { activeIndex } = this.state;
const slides = items.map((item) => {
return (
<CarouselItem
className="custom-tag"
tag="div"
key={item.id}
onExiting={this.onExiting}
onExited={this.onExited}
>
<CarouselCaption className="text-danger" captionText={item.caption} captionHeader={item.caption} />
</CarouselItem>
);
});
return (
<div>
<style>
{
`.custom-tag {
max-width: 100%;
height: 500px;
background: black;
}`
}
</style>
<Carousel
activeIndex={activeIndex}
next={this.next}
previous={this.previous}
>
<CarouselIndicators items={items} activeIndex={activeIndex} onClickHandler={this.goToIndex} />
{slides}
<CarouselControl direction="prev" directionText="Previous" onClickHandler={this.previous} />
<CarouselControl direction="next" directionText="Next" onClickHandler={this.next} />
</Carousel>
</div>
);
}
}