From ab1aa237259955a12b43aeb175222e365305419c Mon Sep 17 00:00:00 2001 From: --remove-section Date: Tue, 27 Jan 2026 21:37:29 +0530 Subject: [PATCH] feat: redesign card scroller --- src/components/cardScroller/cardScroller.scss | 91 ++++++++---- src/components/cardScroller/cardScroller.tsx | 139 +++++++++++------- 2 files changed, 150 insertions(+), 80 deletions(-) diff --git a/src/components/cardScroller/cardScroller.scss b/src/components/cardScroller/cardScroller.scss index b928bf5..10c5949 100644 --- a/src/components/cardScroller/cardScroller.scss +++ b/src/components/cardScroller/cardScroller.scss @@ -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 { diff --git a/src/components/cardScroller/cardScroller.tsx b/src/components/cardScroller/cardScroller.tsx index 3d2a551..7df68aa 100644 --- a/src/components/cardScroller/cardScroller.tsx +++ b/src/components/cardScroller/cardScroller.tsx @@ -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 ( - -
chevron_right
-
+
+ +
+ {title} + + +
+ + chevron_left + + + chevron_right + +
+
); -} -//@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 ( - -
chevron_left
-
- ); -} +}; type CardScrollerProps = { children: ReactNode; @@ -44,9 +74,13 @@ export default function CardScroller({ disableDecoration = false, boxProps, }: CardScrollerProps) { + const carouselRef = useRef(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 ( -
-
- -
{title} - -
+
+ = totalItems} + /> } - customLeftArrow={} + 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}