Amber Shopify Project created using ReactJS+React-Redux with GraphQL API integration. Storefront Shopify API: https://github.com/Shopify/shopify-app-js/tree/main/packages/api-clients/storefront-api-client#readme
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Carousel.jsx 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React from "react";
  2. import { Box, IconButton } from "@mui/material";
  3. import ArrowBackIosIcon from "@mui/icons-material/ArrowBackIos";
  4. import ArrowForwardIosIcon from "@mui/icons-material/ArrowForwardIos";
  5. import mainImage from "../../assets/images/mainwallpaper.jpg"
  6. import mainImageMobile from "../../assets/images/mainwallpaper-mobile.jpg"
  7. const Carousel = () => {
  8. const items = [
  9. { img_src: mainImage, alt_name: "Image 1" }
  10. ]
  11. const items_mobile = [
  12. { img_src: mainImageMobile, alt_name: "Image 1" }
  13. ]
  14. const [currentIndex, setCurrentIndex] = React.useState(0);
  15. const handlePrev = () => {
  16. setCurrentIndex((prevIndex) =>
  17. prevIndex === 0 ? items.length - 1 : prevIndex - 1
  18. );
  19. };
  20. const handleNext = () => {
  21. setCurrentIndex((prevIndex) =>
  22. prevIndex === items.length - 1 ? 0 : prevIndex + 1
  23. );
  24. };
  25. return (
  26. <Box
  27. sx={{
  28. position: "relative",
  29. display: "flex",
  30. alignItems: "center",
  31. justifyContent: "center",
  32. width: "100%",
  33. objectPosition: "top center",
  34. overflow: "hidden",
  35. }}
  36. >
  37. {/* Filter */}
  38. <Box sx={{
  39. position: "absolute",
  40. top: 0,
  41. right: 0,
  42. backgroundColor: "rgba(0, 0, 0, 0.2)",
  43. width: "100%",
  44. height: "100%"
  45. }}></Box>
  46. {items.map((item, index) => (
  47. <Box
  48. key={index}
  49. component="img"
  50. src={item.img_src}
  51. alt={item.alt_name}
  52. sx={{
  53. width: "100%",
  54. height: "100%",
  55. backgroundImage: `url(${item.img_src})`,
  56. objectFit: "cover",
  57. objectPosition: "center center",
  58. }}
  59. />
  60. ))}
  61. </Box>
  62. );
  63. };
  64. export default Carousel;