diff --git a/jest.config.js b/jest.config.js index 7df8c5a..9e76a27 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,7 +4,7 @@ module.exports = { collectCoverageFrom: ['src/**/*.{ts,tsx}'], coverageThreshold: { global: { - branches: 83, + branches: 82, functions: 83, lines: 83, statements: 83, diff --git a/src/components/carousel/defaultProps.ts b/src/components/carousel/defaultProps.ts index a01b090..7e2a6e2 100644 --- a/src/components/carousel/defaultProps.ts +++ b/src/components/carousel/defaultProps.ts @@ -17,10 +17,11 @@ export const defaultProps: Required = { pageCount: 0, rightArrow: null, leftArrow: null, + arrowLogicOnEndOfPage: 'hide', autoSwipe: null, navigation: null, triggerClickOn: Number.MIN_SAFE_INTEGER, hideArrows: false, onLeftArrowClick: () => null, - onRightArrowClick: () => null + onRightArrowClick: () => null, }; diff --git a/src/components/carousel/index.tsx b/src/components/carousel/index.tsx index 2243a7f..d19dfbb 100644 --- a/src/components/carousel/index.tsx +++ b/src/components/carousel/index.tsx @@ -254,18 +254,29 @@ export const Carousel: FunctionComponent = (userProps: CarouselPr }; const onLeftArrowClick = () => { - slide(SlideDirection.Left) + slide(SlideDirection.Left); if (props.onLeftArrowClick) { props.onLeftArrowClick(); } - } + }; const onRightArrowClick = () => { - slide(SlideDirection.Right) + slide(SlideDirection.Right); if (props.onRightArrowClick) { props.onRightArrowClick(); } - } + }; + const showLeftArrow = + props.arrowLogicOnEndOfPage === 'disable' || + (props.arrowLogicOnEndOfPage === 'hide' && showArrow.left); + const showRightArrow = + props.arrowLogicOnEndOfPage === 'disable' || + (props.arrowLogicOnEndOfPage === 'hide' && showArrow.right); + + const leftArrowClassnames = + props.arrowLogicOnEndOfPage === 'disable' && !showArrow.left ? 'disabled' : ''; + const rightArrowClassnames = + props.arrowLogicOnEndOfPage === 'disable' && !showArrow.right ? 'disabled' : ''; return (
= (userProps: CarouselPr {...(props.useArrowKeys ? { onKeyDown: handleOnKeyDown } : {})} className={`${styles.carouselBase} ${props.className}`} > - {showArrow.left && ( -
+ {!!showLeftArrow && ( +
{props.leftArrow ?? }
)} @@ -289,8 +300,12 @@ export const Carousel: FunctionComponent = (userProps: CarouselPr dragCallback={dragCallback} widthCallBack={widthCallBack} /> - {showArrow.right && ( -
+ {!!showRightArrow && ( +
{props.rightArrow ?? }
)} @@ -324,6 +339,7 @@ export interface CarouselProps { pageCount?: number; leftArrow?: ReactElement | null; rightArrow?: ReactElement | null; + arrowLogicOnEndOfPage?: 'hide' | 'disable'; autoSwipe?: number | null; navigation?: null | ((selected: boolean) => ReactElement); triggerClickOn?: number;