-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarousel.js
106 lines (97 loc) · 2.96 KB
/
Carousel.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
94
95
96
97
98
99
100
101
102
103
104
105
106
import { useState, useEffect } from "react";
import { Box, Text, Heading, Container, Stack, Badge } from "@chakra-ui/react";
import Slider from "react-slick";
import { getMealImagesAPI } from "../../api/thirdPartyApi.js";
// Settings for the slider
const settings = {
dots: true,
arrows: true,
fade: true,
infinite: true,
autoplay: true,
speed: 500,
autoplaySpeed: 1500,
slidesToShow: 1,
slidesToScroll: 1,
};
export default function Carousel() {
const [mealDBimages, setMealDBImages] = useState([]);
const cards = mealDBimages.meals;
// Fetching Data
useEffect(() => {
const makeImageRequest = async () => {
setMealDBImages(await getMealImagesAPI());
};
makeImageRequest();
}, []);
return cards ? (
<Box
position={"relative"}
height={"600px"}
width={"full"}
overflow={"hidden"}
>
{/* CSS files for react-slick */}
<link
rel="stylesheet"
type="text/css"
charSet="UTF-8"
href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.css"
/>
<link
rel="stylesheet"
type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick-theme.min.css"
/>
{/* Slider */}
<Slider {...settings}>
{cards.map((url, index) => (
<Box
key={index}
height={"6xl"}
position="relative"
backgroundPosition="center"
backgroundRepeat="no-repeat"
// cover, that scales an image to fill the container completely without cropping too much area of the image:
backgroundSize="cover"
backgroundImage={`url(${url.strMealThumb})`}
>
{/* This is the block you need to change, to customize the caption */}
<Container size="container.lg" height="600px" position="relative">
<Stack
spacing={6}
w={"full"}
maxW={"lg"}
position="absolute"
top="50%"
transform="translate(0, -50%)"
>
<Heading
textAlign="center"
color="white"
fontSize="6xl"
fontWeight="extrabold"
>
GURUPRASAD
</Heading>
<Text textAlign="center" as="i">
<Badge borderRadius="full" px="2" colorScheme="teal">
Passionate about good food and service
</Badge>
</Text>
<Text textAlign="center">
<Badge borderRadius="full" px="2" colorScheme="green">
Veg Tiffin and meals
</Badge>
</Text>
</Stack>
</Container>
</Box>
))}
</Slider>
</Box>
) : (
<div>Loading</div>
);
}
// credit: https://chakra-templates.dev/page-sections/carousels