feat: redesign card scroller

This commit is contained in:
--remove-section committed 2026-01-27 21:37:29 +05:30
1 parent 0131a23dc2
commit ab1aa23725
2 files changed
+150 -80

No files matched your search

+61 -30
View File
@@ -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 { .card-scroller {
// height: 20em; // Override carousel default outline
&:focus {
outline: none;
}
&-slide { &-slide {
overflow: visible; padding-right: 0.5em; // Gap between cards (handled by slide padding instead of gap for carousel)
display: flex; // With react-multi-carousel, better to rely on their gap logic or item class
}
&-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;
}
} }
&-item {
padding-right: 0.6em; // Consistent gap
}
&-header-container { &-header-container {
display: flex; display: flex;
width: 100%; width: 100%;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
margin-bottom: 1em;
min-height: 40px;
} }
&-heading { &-heading {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: flex-start; justify-content: flex-start;
gap: 0.35em; gap: 0.5em;
position: relative; position: relative;
margin-bottom: 0.25em !important; font-weight: 600 !important;
&-decoration { &-decoration {
width: 0.75em; width: 4px;
height: 2px; height: 24px;
background: white; 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 { .hidden-decoration {
+89 -50
View File
@@ -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 Carousel from "react-multi-carousel";
import "react-multi-carousel/lib/styles.css"; import "react-multi-carousel/lib/styles.css";
import { Box } from "@mui/material";
import IconButton from "@mui/material/IconButton"; import IconButton from "@mui/material/IconButton";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import "./cardScroller.scss"; import "./cardScroller.scss";
//@ts-ignore - I don't know the prop type for react-multi-carousel's customRightArrow and customLeftArrow // Custom Header + Button Group component
function RightButton(props) { const ScrollerHeader = ({
const { carouselState, children, rtl, ...restProps } = props; onNext,
onPrevious,
title,
headingProps,
disableDecoration,
currentSlide = 0,
isNextDisabled = false,
}: any) => {
// Basic disable logic for visual feedback
const isFirst = currentSlide === 0;
return ( return (
<IconButton className="card-scroller-button right" {...restProps}> <div
<div className="material-symbols-rounded">chevron_right</div> className={`card-scroller-header-container ${disableDecoration ? "hidden-decoration" : ""}`}
</IconButton> >
<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 = { type CardScrollerProps = {
children: ReactNode; children: ReactNode;
@@ -44,9 +74,13 @@ export default function CardScroller({
disableDecoration = false, disableDecoration = false,
boxProps, boxProps,
}: CardScrollerProps) { }: CardScrollerProps) {
const carouselRef = useRef<any>(null);
const [currentSlide, setCurrentSlide] = useState(0);
const [slidesToShow, setSlidesToShow] = useState(displayCards);
const totalItems = React.Children.count(children);
const responsive = { const responsive = {
superLargeDesktop: { superLargeDesktop: {
// the naming can be any, depends on you.
breakpoint: { max: 4000, min: 3000 }, breakpoint: { max: 4000, min: 3000 },
items: displayCards + 1, items: displayCards + 1,
slidesToSlide: displayCards + 1, slidesToSlide: displayCards + 1,
@@ -55,62 +89,67 @@ export default function CardScroller({
desktop: { desktop: {
breakpoint: { max: 3000, min: 925 }, breakpoint: { max: 3000, min: 925 },
items: displayCards, items: displayCards,
slidesToSlide: displayCards, // optional, default to 1. slidesToSlide: displayCards,
partialVisibilityGutter: 30, partialVisibilityGutter: 30,
}, },
tablet: { tablet: {
breakpoint: { max: 925, min: 600 }, breakpoint: { max: 925, min: 600 },
items: displayCards - 3, items: displayCards - 3,
slidesToSlide: displayCards - 3, // optional, default to 1. slidesToSlide: displayCards - 3,
partialVisibilityGutter: 20, partialVisibilityGutter: 20,
}, },
mobile: { mobile: {
breakpoint: { max: 600, min: 424 }, breakpoint: { max: 600, min: 424 },
items: displayCards - 5, items: displayCards - 5,
slidesToSlide: displayCards - 5, // optional, default to 1. slidesToSlide: displayCards - 5,
partialVisibilityGutter: 10, partialVisibilityGutter: 10,
}, },
smallScreen: { smallScreen: {
breakpoint: { max: 424, min: 0 }, breakpoint: { max: 424, min: 0 },
items: 1, items: 1,
slidesToSlide: 1, // optional, default to 1. slidesToSlide: 1,
partialVisibilityGutter: 10, partialVisibilityGutter: 10,
}, },
}; };
const handleNext = () => {
if (carouselRef.current) {
carouselRef.current.next();
}
};
const handlePrevious = () => {
if (carouselRef.current) {
carouselRef.current.previous();
}
};
return ( return (
<div <div {...boxProps} className="card-scroller-container">
{...boxProps} <ScrollerHeader
className="card-scroller-container" title={title}
style={{ marginBottom: "1.2em" }} headingProps={headingProps}
> disableDecoration={disableDecoration}
<div onNext={handleNext}
style={{ marginBottom: "1.2em" }} onPrevious={handlePrevious}
className={ currentSlide={currentSlide}
disableDecoration isNextDisabled={currentSlide + slidesToShow >= totalItems}
? "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>
<Carousel <Carousel
ref={carouselRef}
swipeable swipeable
draggable draggable
responsive={responsive} responsive={responsive}
arrows arrows={false}
className="card-scroller" className="card-scroller"
customTransition="all .6s" customTransition="transform 400ms ease-in-out"
transitionDuration={600} transitionDuration={400}
customRightArrow={<RightButton />} containerClass="card-scroller-track"
customLeftArrow={<LeftButton />} itemClass="card-scroller-item"
beforeChange={(nextSlide, state) => {
setCurrentSlide(nextSlide);
setSlidesToShow(state.slidesToShow);
}}
> >
{children} {children}
</Carousel> </Carousel>