-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeaturedWidget.jsx
66 lines (58 loc) · 2.04 KB
/
FeaturedWidget.jsx
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
import React, { useState, useEffect } from 'react';
import Carousel from 'react-multi-carousel';
import 'react-multi-carousel/lib/styles.css';
import FeaturedPost from './FeaturedPost';
import { getFeaturedPosts } from '../services';
const responsive = {
superLargeDesktop: {
breakpoint: { max: 4000, min: 1024 },
items: 5,
},
desktop: {
breakpoint: { max: 1024, min: 768 },
items: 3,
},
tablet: {
breakpoint: { max: 768, min: 640 },
items: 2,
},
mobile: {
breakpoint: { max: 640, min: 0 },
items: 1,
},
};
const FeaturedWidget = () => {
const [featuredPosts, setFeaturedPosts] = useState([]);
const [dataLoaded, setDataLoaded] = useState(false);
useEffect(() => {
getFeaturedPosts()
.then((res) => {
setFeaturedPosts(res);
setDataLoaded(true);
})
}, [])
const customLeftArrow = (
<div className="absolute arrow-btn left-0 text-center py-3 cursor-pointer bg-pink-600 rounded-full flex justify-center items-center">
<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M10 19l-7-7m0 0l7-7m-7 7h18" />
</svg>
</div>
);
const customRightArrow = (
<div className="absolute arrow-btn right-0 text-center py-3 cursor-pointer bg-pink-600 rounded-full flex justify-center items-center">
<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 text-white " fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M14 5l7 7m0 0l-7 7m7-7H3" />
</svg>
</div>
);
return (
<div className="mb-8">
<Carousel infinite customLeftArrow={customLeftArrow} customRightArrow={customRightArrow} responsive={responsive} itemClass="px-4">
{dataLoaded && featuredPosts.map((post, index) => (
<FeaturedPost key={index} post={post} />
))}
</Carousel>
</div>
)
}
export default FeaturedWidget;