Update CardScroller and start using Mui Cards

This commit is contained in:
prayag17 committed 2023-03-19 22:30:08 +05:30
1 parent 6cb5130b08
commit 03323d954e
8 files changed
+399 -238

No files matched your search

+46 -44
View File
@@ -1,6 +1,6 @@
/** @format */
import { useRef, useEffect } from "react";
import { useState, useEffect } from "react";
import PropTypes from "prop-types";
import Carousel from "react-multi-carousel";
@@ -10,41 +10,13 @@ import { MdiChevronLeft } from "../icons/mdiChevronLeft";
import { MdiChevronRight } from "../icons/mdiChevronRight";
import { styled } from "@mui/material/styles";
import Button from "@mui/material/Button";
import IconButton from "@mui/material/IconButton";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import ButtonGroup from "@mui/material/ButtonGroup";
import "./cardScroller.module.scss";
const CarouselButton = styled(Button)(() => ({
color: "white",
height: "100%",
}));
const SliderButtonRight = ({ onClick }) => {
return (
<CarouselButton
onClick={() => onClick()}
className="card-scroller-button right"
variant="text"
>
<MdiChevronRight />
</CarouselButton>
);
};
const SliderButtonLeft = ({ onClick }) => {
return (
<CarouselButton
onClick={() => onClick()}
className="card-scroller-button left"
variant="text"
>
<MdiChevronLeft />
</CarouselButton>
);
};
export const CardScroller = ({ children, displayCards }) => {
export const CardScroller = ({ children, displayCards, title }) => {
const responsive = {
desktop: {
breakpoint: { max: 3000, min: 1024 },
@@ -63,21 +35,51 @@ export const CardScroller = ({ children, displayCards }) => {
},
};
const [carouselRef, setCarouselRef] = useState();
return (
<Carousel
swipeable={false}
draggable={false}
responsive={responsive}
arrows={true}
customRightArrow={<SliderButtonRight />}
customLeftArrow={<SliderButtonLeft />}
className="card-scroller"
>
{children}
</Carousel>
<Box className="card-scroller-container">
<Box sx={{ mb: 2 }} className="card-scroller-header-container">
<Typography
variant="h4"
color="textPrimary"
className="card-scroller-heading"
>
<div className="card-scroller-heading-decoration"></div>{" "}
{title}
</Typography>
<ButtonGroup className="card-scroller-button-group">
<IconButton
className="card-scroller-button"
onClick={() => carouselRef.previous()}
>
<MdiChevronLeft />
</IconButton>
<IconButton
className="card-scroller-button"
onClick={() => carouselRef.next()}
>
<MdiChevronRight />
</IconButton>
</ButtonGroup>
</Box>
<Carousel
swipeable={false}
draggable={false}
responsive={responsive}
arrows={false}
ref={(el) => setCarouselRef(el)}
// customButtonGroup={<HomeSectionHeader />}
// renderButtonGroupOutside={true}
className="card-scroller"
>
{children}
</Carousel>
</Box>
);
};
CardScroller.propTypes = {
displayCards: PropTypes.number.isRequired,
title: PropTypes.string.isRequired,
};
@@ -7,23 +7,25 @@
display: flex;
}
&-button {
color: white;
position: absolute !important;
top: 49%;
transform: translateY(-50%);
background-color: $clr-background-dark !important;
border-radius: $border-radius-intensity-1 !important;
opacity: 0;
transition: opacity $transition-time-default !important;
&:hover,
&:focus {
opacity: 1;
}
&.right {
right: 0%;
}
&.left {
left: 0%;
aspect-ratio: 1;
}
&-header-container {
display: flex;
width: 100%;
justify-content: space-between;
align-items: center;
}
&-heading {
display: flex;
align-items: center;
justify-content: flex-start;
gap: 0.35em;
position: relative;
margin-bottom: 0.25em !important;
&-decoration {
width: 0.75em;
height: 3px;
background: white;
}
}
}