1. // the current active slide of the carousel
    2. activeIndex: PropTypes.number,
    3. // a function which should advance the carousel to the next slide (via activeIndex)
    4. next: PropTypes.func.isRequired,
    5. // a function which should advance the carousel to the previous slide (via activeIndex)
    6. previous: PropTypes.func.isRequired,
    7. // controls if the left and right arrow keys should control the carousel
    8. keyboard: PropTypes.bool,
    9. /* If set to "hover", pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on
    10. * mouseleave. If set to false, hovering over the carousel won't pause it. (default: "hover")
    11. */
    12. pause: PropTypes.oneOf(['hover', false]),
    13. // Autoplays the carousel after the user manually cycles the first item. If "carousel", autoplays the carousel on load.
    14. // This is how bootstrap defines it... I would prefer a bool named autoplay or something...
    15. ride: PropTypes.oneOf(['carousel']),
    16. // the interval at which the carousel automatically cycles (default: 5000)
    17. interval: PropTypes.oneOfType([
    18. PropTypes.number,
    19. PropTypes.string,
    20. PropTypes.bool,
    21. ]),
    22. children: PropTypes.array,
    23. // called when the mouse enters the Carousel
    24. mouseEnter: PropTypes.func,
    25. // called when the mouse exits the Carousel
    26. mouseLeave: PropTypes.func,
    27. // controls whether the slide animation on the Carousel works or not
    28. slide: PropTypes.bool,
    29. cssModule: PropTypes.object,
    30. };

    CarouselItem Properties

    1. CarouselItem.propTypes = {
    2. ...Transition.propTypes,
    3. tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
    4. in: PropTypes.bool,
    5. cssModule: PropTypes.object,
    6. children: PropTypes.node,
    7. slide: PropTypes.bool,
    8. };

    CarouselIndicators Properties

    1. CarouselIndicators.propTypes = {
    2. items: PropTypes.array.isRequired,
    3. activeIndex: PropTypes.number.isRequired,
    4. cssModule: PropTypes.object,
    5. onClickHandler: PropTypes.func.isRequired
    6. };
    1. CarouselCaption.propTypes = {
    2. captionHeader: PropTypes.string,
    3. captionText: PropTypes.string.isRequired,
    4. };

    Uncontrolled Carousel

    1. UncontrolledCarousel.propTypes = {
    2. items: PropTypes.array.isRequired,
    3. indicators: PropTypes.bool, // default: true
    4. controls: PropTypes.bool, // default: true
    5. autoPlay: PropTypes.bool, // default: true
    6. };

    Carousel using a tag and classname

    1. import React, { Component } from 'react';
    2. import {
    3. Carousel,
    4. CarouselItem,
    5. CarouselControl,
    6. CarouselIndicators,
    7. CarouselCaption
    8. } from 'reactstrap';
    9. const items = [
    10. {
    11. id: 1,
    12. altText: 'Slide 1',
    13. caption: 'Slide 1'
    14. },
    15. {
    16. id: 2,
    17. altText: 'Slide 2',
    18. caption: 'Slide 2'
    19. },
    20. {
    21. id: 3,
    22. altText: 'Slide 3',
    23. caption: 'Slide 3'
    24. }
    25. ];
    26. class Example extends Component {
    27. constructor(props) {
    28. super(props);
    29. this.state = { activeIndex: 0 };
    30. this.next = this.next.bind(this);
    31. this.previous = this.previous.bind(this);
    32. this.goToIndex = this.goToIndex.bind(this);
    33. this.onExiting = this.onExiting.bind(this);
    34. this.onExited = this.onExited.bind(this);
    35. }
    36. onExiting() {
    37. this.animating = true;
    38. }
    39. onExited() {
    40. this.animating = false;
    41. }
    42. next() {
    43. if (this.animating) return;
    44. }
    45. previous() {
    46. if (this.animating) return;
    47. const nextIndex = this.state.activeIndex === 0 ? items.length - 1 : this.state.activeIndex - 1;
    48. this.setState({ activeIndex: nextIndex });
    49. }
    50. goToIndex(newIndex) {
    51. if (this.animating) return;
    52. this.setState({ activeIndex: newIndex });
    53. }
    54. render() {
    55. const { activeIndex } = this.state;
    56. const slides = items.map((item) => {
    57. return (
    58. <CarouselItem
    59. className="custom-tag"
    60. tag="div"
    61. key={item.id}
    62. onExiting={this.onExiting}
    63. onExited={this.onExited}
    64. >
    65. <CarouselCaption className="text-danger" captionText={item.caption} captionHeader={item.caption} />
    66. </CarouselItem>
    67. );
    68. });
    69. return (
    70. <div>
    71. <style>
    72. {
    73. `.custom-tag {
    74. max-width: 100%;
    75. height: 500px;
    76. background: black;
    77. }`
    78. }
    79. </style>
    80. <Carousel
    81. activeIndex={activeIndex}
    82. next={this.next}
    83. previous={this.previous}
    84. >
    85. <CarouselIndicators items={items} activeIndex={activeIndex} onClickHandler={this.goToIndex} />
    86. {slides}
    87. <CarouselControl direction="prev" directionText="Previous" onClickHandler={this.previous} />
    88. <CarouselControl direction="next" directionText="Next" onClickHandler={this.next} />
    89. </Carousel>
    90. </div>
    91. );
    92. }
    93. }