const ResponsiveSettings = {
mobile: {
slidesToShow: 1,
slidesToScroll: 1,
decorators: Decorators.mobile,
initialSlideWidth: 300,
responsive: [{
selectors: ["x-small", "small"]
}]
},
tablet: {
slidesToShow: 4,
slidesToScroll: 4,
framePadding: "20px 40px",
decorators: Decorators.tablet,
initialSlideWidth: 60
},
desktop: {
vertical: true,
dragging: false,
slidesToShow: 5,
slidesToScroll: 5,
width: "90px",
framePadding: "40px 0px",
cellSpacing: 20,
decorators: Decorators.desktop,
initialSlideHeight: 61
}
};
const responsive = [
{
selectors: ["large", "x-large", "xx-large"],
settings: desktop
},
{
selectors: ["medium"],
settings: tablet
},
{
selectors: ["x-small", "small"],
settings: mobile
}
];
// parent
class ProductImage extends React.Component {
constructor(props) {
super(props);
// bind context on functions
this._handleHover = this._handleHover.bind(this);
this._handleClick = this._handleClick.bind(this);
// set initial state
this.state = {
activeIndex: 0,
lastIndex: 0
};
}
_handleHover(enter, index) {
return () => (
this.setState({
activeIndex: enter ? index : this.state.lastIndex
})
);
}
_handleClick(index) {
return () => (
this.setState({
activeIndex: index,
lastIndex: index
})
);
}
render() {
const self = this;
const { images } = this.props;
return (
<AltImageCarousel
{...{
images,
handleHover: this._handleHover,
handleClick: this._handleClick,
activeIndex: this.state.activeIndex,
lastIndex: this.state.lastIndex
}}
/>
);
}
}
export const AltImageCarousel = ({
handleHover,
handleClick,
activeIndex,
lastIndex,
images
}) => (
<Carousel {...{responsive}} slideIndex={ lastIndex }>
{
images.map((img, index) => {
const classNameSuffix = activeIndex === index ? "--active" : "";
const className = `prod-AltImageCarousel${classNameSuffix}`;
return (
<img
src={image.thumb}
key={index}
{...{className, img}}
onMouseEnter={handleHover(true, index)}
onMouseLeave={handleHover(false, index)}
onClick={handleClick(index)}
/>
);
})
}
</Carousel>
);