// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { Carousel as ReactstrapCarousel, CarouselCaption, CarouselControl, CarouselIndicators, CarouselItem, } from "reactstrap"; import './Carousel.scss'; import { getImageResource } from "./Utils"; export class Carousel 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() { const {items} = this.props; if (this.animating) return; const nextIndex = this.state.activeIndex === items.length - 1 ? 0 : this.state.activeIndex + 1; this.setState({activeIndex : nextIndex}); } previous() { const {items} = this.props; 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 {items} = this.props; const {activeIndex} = this.state; const slides = items.map((item, index) => { return ( {item.altText}/ ); }); return (
{slides}
); } } Carousel.propTypes = { items : PropTypes.array }; Carousel.defaultProps = { items : [] };