From f0b059925ddcdd67075fb9d8a2c020e73b5870e0 Mon Sep 17 00:00:00 2001 From: Tejas Date: Thu, 31 Oct 2024 17:48:04 +0530 Subject: [PATCH 1/2] hide controls when totalSlides < visibleItems --- .../src/components/Carousel/Carousel.web.tsx | 66 ++++++++++--------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/packages/blade/src/components/Carousel/Carousel.web.tsx b/packages/blade/src/components/Carousel/Carousel.web.tsx index ed2f609ed4a..d13305a89ad 100644 --- a/packages/blade/src/components/Carousel/Carousel.web.tsx +++ b/packages/blade/src/components/Carousel/Carousel.web.tsx @@ -39,6 +39,7 @@ type ControlsProp = Required< onIndicatorButtonClick: (index: number) => void; onNextButtonClick: () => void; onPreviousButtonClick: () => void; + showControls: boolean; }; const Controls = ({ @@ -51,43 +52,46 @@ const Controls = ({ onPreviousButtonClick, indicatorVariant, navigationButtonVariant, + showControls, }: ControlsProp): React.ReactElement => { - if (navigationButtonPosition === 'bottom') { - return ( - - - {showIndicators ? ( + if (showControls) { + if (navigationButtonPosition === 'bottom') { + return ( + + + {showIndicators ? ( + + ) : null} + + + ); + } + + if (showIndicators && navigationButtonPosition === 'side') { + return ( + - ) : null} - - - ); - } - - if (showIndicators && navigationButtonPosition === 'side') { - return ( - - - - ); + + ); + } } return <>; @@ -308,6 +312,7 @@ const Carousel = ({ const shouldNavButtonsFloat = isResponsive && navigationButtonPosition === 'side'; const totalNumberOfSlides = React.Children.count(children); const numberOfIndicators = Math.ceil(totalNumberOfSlides / _visibleItems); + const shouldShowControls = totalNumberOfSlides > _visibleItems; // hide next/prev button on reaching start/end when carousel is responsive // in non-responsive carousel we always show the next/prev buttons to allow looping @@ -586,6 +591,7 @@ const Carousel = ({ onPreviousButtonClick={goToPreviousSlide} indicatorVariant={indicatorVariant} navigationButtonVariant={navigationButtonVariant} + showControls={shouldShowControls} /> From 8543f1f6e3615e3a003ce6904a0f603d22a886c2 Mon Sep 17 00:00:00 2001 From: Tejas Date: Thu, 31 Oct 2024 18:30:35 +0530 Subject: [PATCH 2/2] Fixed side and floating buttons --- packages/blade/src/components/Carousel/Carousel.web.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/blade/src/components/Carousel/Carousel.web.tsx b/packages/blade/src/components/Carousel/Carousel.web.tsx index d13305a89ad..e8d96e81f85 100644 --- a/packages/blade/src/components/Carousel/Carousel.web.tsx +++ b/packages/blade/src/components/Carousel/Carousel.web.tsx @@ -534,7 +534,7 @@ const Carousel = ({ flexDirection="row" height="100%" > - {shouldShowPrevButton && shouldNavButtonsFloat ? ( + {shouldShowPrevButton && shouldNavButtonsFloat && shouldShowControls ? ( ) : null} - {isNavButtonsOnSide ? ( + {isNavButtonsOnSide && shouldShowControls ? ( {children} - {shouldShowNextButton && shouldNavButtonsFloat ? ( + {shouldShowNextButton && shouldNavButtonsFloat && shouldShowControls ? ( ) : null} - {isNavButtonsOnSide ? ( + {isNavButtonsOnSide && shouldShowControls ? (