-
Notifications
You must be signed in to change notification settings - Fork 293
/
Copy pathcarousel-with-custom-dots.js
93 lines (85 loc) · 1.91 KB
/
carousel-with-custom-dots.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React from "react";
import Carousel from "react-multi-carousel";
import classNames from "classnames";
import Avatar from "@material-ui/core/Avatar";
import articles from "./data.json";
import Card from "./card";
import "./carousel-with-custom-dots.css";
const responsive = {
desktop: {
breakpoint: {
max: 3000,
min: 1024
},
items: 3,
slidesToSlide: 2,
partialVisibilityGutter: 40
},
mobile: {
breakpoint: {
max: 464,
min: 0
},
items: 2,
slidesToSlide: 2,
partialVisibilityGutter: 30
},
tablet: {
breakpoint: {
max: 1024,
min: 200
},
items: 1,
slidesToSlide: 1,
partialVisibilityGutter: 30
}
};
const ArticleCard = ({ imageUrl, link, title }) => {
return <Card link={link} image={imageUrl} headline={title} />;
};
class CarouselWithCustomDots extends React.PureComponent {
render() {
const { deviceType } = this.props;
const children = articles
.slice(0, 6)
.map(article => <ArticleCard key={article.title} {...article} />);
const images = articles.map(article => (
<Avatar key={article.title} src={article.imageUrl} />
));
const CustomDot = ({
index,
onClick,
active
}) => {
return (
<button
onClick={e => {
onClick();
e.preventDefault();
}}
className={classNames("custom-dot", {
"custom-dot--active": active
})}
>
{React.Children.toArray(images)[index]}
</button>
);
};
return (
<Carousel
showDots
deviceType={deviceType}
ssr
slidesToSlide={1}
containerClass="carousel-with-custom-dots"
responsive={responsive}
partialVisible
infinite
customDot={<CustomDot />}
>
{children}
</Carousel>
);
}
}
export default CarouselWithCustomDots;