feat: redesign card scroller
This commit is contained in:
2 files changed
+150
-80
No files matched your search
@@ -1,51 +1,82 @@
|
||||
@use "@/styles/variables.scss" as *;
|
||||
|
||||
.card-scroller-container {
|
||||
margin-bottom: 2.5em;
|
||||
position: relative;
|
||||
|
||||
// Ensure the container handles overflow if needed, but usually Carousel handles it
|
||||
}
|
||||
|
||||
.card-scroller {
|
||||
// height: 20em;
|
||||
// Override carousel default outline
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
&-slide {
|
||||
overflow: visible;
|
||||
display: flex;
|
||||
}
|
||||
&-button {
|
||||
position: absolute !important;
|
||||
height: 100%;
|
||||
font-size: 1em !important;
|
||||
width: $page-margin;
|
||||
&.right{
|
||||
border-radius: $border-radius-default 0 0 $border-radius-default !important;
|
||||
right: -$page-margin;
|
||||
}
|
||||
&.left{
|
||||
border-radius: 0 $border-radius-default $border-radius-default 0 !important;
|
||||
left: -$page-margin;
|
||||
}
|
||||
.material-symbols-rounded{
|
||||
font-size: 3.2em;
|
||||
--wght: 200;
|
||||
--opsz: 48;
|
||||
}
|
||||
padding-right: 0.5em; // Gap between cards (handled by slide padding instead of gap for carousel)
|
||||
// With react-multi-carousel, better to rely on their gap logic or item class
|
||||
}
|
||||
|
||||
&-item {
|
||||
padding-right: 0.6em; // Consistent gap
|
||||
}
|
||||
|
||||
&-header-container {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1em;
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
&-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
gap: 0.35em;
|
||||
gap: 0.5em;
|
||||
position: relative;
|
||||
margin-bottom: 0.25em !important;
|
||||
font-weight: 600 !important;
|
||||
|
||||
&-decoration {
|
||||
width: 0.75em;
|
||||
height: 2px;
|
||||
background: white;
|
||||
width: 4px;
|
||||
height: 24px;
|
||||
background: $clr-accent-default;
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
||||
&-container .MuiButtonGroup-outlined{
|
||||
gap: 1em;
|
||||
}
|
||||
|
||||
&-controls {
|
||||
display: flex;
|
||||
gap: 0.5em;
|
||||
|
||||
.scroller-nav-btn {
|
||||
background-color: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.05);
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
transition: all 0.2s ease;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
|
||||
&:hover {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
color: #fff;
|
||||
border-color: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
// Disabled state
|
||||
&.Mui-disabled {
|
||||
background-color: transparent;
|
||||
border-color: transparent;
|
||||
color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.material-symbols-rounded {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hidden-decoration {
|
||||
|
||||
@@ -1,31 +1,61 @@
|
||||
import React, { type ReactNode } from "react";
|
||||
|
||||
import React, { type ReactNode, useRef, useState } from "react";
|
||||
import Carousel from "react-multi-carousel";
|
||||
import "react-multi-carousel/lib/styles.css";
|
||||
|
||||
import { Box } from "@mui/material";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import "./cardScroller.scss";
|
||||
|
||||
//@ts-ignore - I don't know the prop type for react-multi-carousel's customRightArrow and customLeftArrow
|
||||
function RightButton(props) {
|
||||
const { carouselState, children, rtl, ...restProps } = props;
|
||||
// Custom Header + Button Group component
|
||||
const ScrollerHeader = ({
|
||||
onNext,
|
||||
onPrevious,
|
||||
title,
|
||||
headingProps,
|
||||
disableDecoration,
|
||||
currentSlide = 0,
|
||||
isNextDisabled = false,
|
||||
}: any) => {
|
||||
// Basic disable logic for visual feedback
|
||||
const isFirst = currentSlide === 0;
|
||||
|
||||
return (
|
||||
<IconButton className="card-scroller-button right" {...restProps}>
|
||||
<div className="material-symbols-rounded">chevron_right</div>
|
||||
</IconButton>
|
||||
<div
|
||||
className={`card-scroller-header-container ${disableDecoration ? "hidden-decoration" : ""}`}
|
||||
>
|
||||
<Typography
|
||||
variant="h5"
|
||||
color="textPrimary"
|
||||
className="card-scroller-heading"
|
||||
{...headingProps}
|
||||
>
|
||||
<div className="card-scroller-heading-decoration" />
|
||||
{title}
|
||||
</Typography>
|
||||
|
||||
<div className="card-scroller-controls">
|
||||
<IconButton
|
||||
onClick={onPrevious}
|
||||
disabled={isFirst}
|
||||
size="small"
|
||||
className="scroller-nav-btn"
|
||||
>
|
||||
<span className="material-symbols-rounded">chevron_left</span>
|
||||
</IconButton>
|
||||
<IconButton
|
||||
onClick={onNext}
|
||||
disabled={isNextDisabled}
|
||||
size="small"
|
||||
className="scroller-nav-btn"
|
||||
>
|
||||
<span className="material-symbols-rounded">chevron_right</span>
|
||||
</IconButton>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
//@ts-ignore - I don't know the prop type for react-multi-carousel's customRightArrow and customLeftArrow
|
||||
function LeftButton(props) {
|
||||
const { carouselState, children, rtl, ...restProps } = props;
|
||||
return (
|
||||
<IconButton className="card-scroller-button left" {...restProps}>
|
||||
<div className="material-symbols-rounded">chevron_left</div>
|
||||
</IconButton>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
type CardScrollerProps = {
|
||||
children: ReactNode;
|
||||
@@ -44,9 +74,13 @@ export default function CardScroller({
|
||||
disableDecoration = false,
|
||||
boxProps,
|
||||
}: CardScrollerProps) {
|
||||
const carouselRef = useRef<any>(null);
|
||||
const [currentSlide, setCurrentSlide] = useState(0);
|
||||
const [slidesToShow, setSlidesToShow] = useState(displayCards);
|
||||
const totalItems = React.Children.count(children);
|
||||
|
||||
const responsive = {
|
||||
superLargeDesktop: {
|
||||
// the naming can be any, depends on you.
|
||||
breakpoint: { max: 4000, min: 3000 },
|
||||
items: displayCards + 1,
|
||||
slidesToSlide: displayCards + 1,
|
||||
@@ -55,62 +89,67 @@ export default function CardScroller({
|
||||
desktop: {
|
||||
breakpoint: { max: 3000, min: 925 },
|
||||
items: displayCards,
|
||||
slidesToSlide: displayCards, // optional, default to 1.
|
||||
slidesToSlide: displayCards,
|
||||
partialVisibilityGutter: 30,
|
||||
},
|
||||
tablet: {
|
||||
breakpoint: { max: 925, min: 600 },
|
||||
items: displayCards - 3,
|
||||
slidesToSlide: displayCards - 3, // optional, default to 1.
|
||||
slidesToSlide: displayCards - 3,
|
||||
partialVisibilityGutter: 20,
|
||||
},
|
||||
mobile: {
|
||||
breakpoint: { max: 600, min: 424 },
|
||||
items: displayCards - 5,
|
||||
slidesToSlide: displayCards - 5, // optional, default to 1.
|
||||
slidesToSlide: displayCards - 5,
|
||||
partialVisibilityGutter: 10,
|
||||
},
|
||||
smallScreen: {
|
||||
breakpoint: { max: 424, min: 0 },
|
||||
items: 1,
|
||||
slidesToSlide: 1, // optional, default to 1.
|
||||
slidesToSlide: 1,
|
||||
partialVisibilityGutter: 10,
|
||||
},
|
||||
};
|
||||
|
||||
const handleNext = () => {
|
||||
if (carouselRef.current) {
|
||||
carouselRef.current.next();
|
||||
}
|
||||
};
|
||||
|
||||
const handlePrevious = () => {
|
||||
if (carouselRef.current) {
|
||||
carouselRef.current.previous();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
{...boxProps}
|
||||
className="card-scroller-container"
|
||||
style={{ marginBottom: "1.2em" }}
|
||||
>
|
||||
<div
|
||||
style={{ marginBottom: "1.2em" }}
|
||||
className={
|
||||
disableDecoration
|
||||
? "card-scroller-header-container hidden-decoration"
|
||||
: "card-scroller-header-container"
|
||||
}
|
||||
>
|
||||
<Typography
|
||||
variant="h5"
|
||||
color="textPrimary"
|
||||
className="card-scroller-heading"
|
||||
{...headingProps}
|
||||
>
|
||||
<div className="card-scroller-heading-decoration" /> {title}
|
||||
</Typography>
|
||||
</div>
|
||||
<div {...boxProps} className="card-scroller-container">
|
||||
<ScrollerHeader
|
||||
title={title}
|
||||
headingProps={headingProps}
|
||||
disableDecoration={disableDecoration}
|
||||
onNext={handleNext}
|
||||
onPrevious={handlePrevious}
|
||||
currentSlide={currentSlide}
|
||||
isNextDisabled={currentSlide + slidesToShow >= totalItems}
|
||||
/>
|
||||
<Carousel
|
||||
ref={carouselRef}
|
||||
swipeable
|
||||
draggable
|
||||
responsive={responsive}
|
||||
arrows
|
||||
arrows={false}
|
||||
className="card-scroller"
|
||||
customTransition="all .6s"
|
||||
transitionDuration={600}
|
||||
customRightArrow={<RightButton />}
|
||||
customLeftArrow={<LeftButton />}
|
||||
customTransition="transform 400ms ease-in-out"
|
||||
transitionDuration={400}
|
||||
containerClass="card-scroller-track"
|
||||
itemClass="card-scroller-item"
|
||||
beforeChange={(nextSlide, state) => {
|
||||
setCurrentSlide(nextSlide);
|
||||
setSlidesToShow(state.slidesToShow);
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Carousel>
|
||||
|
||||
Reference in new issue
Block a user