Skip to content

Commit 6b77374

Browse files
kaanersoyKaan Ersoy
andauthored
feat: add disabled logic for arrows (#120)
Co-authored-by: Kaan Ersoy <[email protected]>
1 parent bef4a18 commit 6b77374

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
collectCoverageFrom: ['src/**/*.{ts,tsx}'],
55
coverageThreshold: {
66
global: {
7-
branches: 83,
7+
branches: 82,
88
functions: 83,
99
lines: 83,
1010
statements: 83,

src/components/carousel/defaultProps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ export const defaultProps: Required<CarouselProps> = {
1717
pageCount: 0,
1818
rightArrow: null,
1919
leftArrow: null,
20+
arrowLogicOnEndOfPage: 'hide',
2021
autoSwipe: null,
2122
navigation: null,
2223
triggerClickOn: Number.MIN_SAFE_INTEGER,
2324
hideArrows: false,
2425
onLeftArrowClick: () => null,
25-
onRightArrowClick: () => null
26+
onRightArrowClick: () => null,
2627
};

src/components/carousel/index.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,29 @@ export const Carousel: FunctionComponent<CarouselProps> = (userProps: CarouselPr
254254
};
255255

256256
const onLeftArrowClick = () => {
257-
slide(SlideDirection.Left)
257+
slide(SlideDirection.Left);
258258
if (props.onLeftArrowClick) {
259259
props.onLeftArrowClick();
260260
}
261-
}
261+
};
262262

263263
const onRightArrowClick = () => {
264-
slide(SlideDirection.Right)
264+
slide(SlideDirection.Right);
265265
if (props.onRightArrowClick) {
266266
props.onRightArrowClick();
267267
}
268-
}
268+
};
269+
const showLeftArrow =
270+
props.arrowLogicOnEndOfPage === 'disable' ||
271+
(props.arrowLogicOnEndOfPage === 'hide' && showArrow.left);
272+
const showRightArrow =
273+
props.arrowLogicOnEndOfPage === 'disable' ||
274+
(props.arrowLogicOnEndOfPage === 'hide' && showArrow.right);
275+
276+
const leftArrowClassnames =
277+
props.arrowLogicOnEndOfPage === 'disable' && !showArrow.left ? 'disabled' : '';
278+
const rightArrowClassnames =
279+
props.arrowLogicOnEndOfPage === 'disable' && !showArrow.right ? 'disabled' : '';
269280

270281
return (
271282
<div
@@ -275,8 +286,8 @@ export const Carousel: FunctionComponent<CarouselProps> = (userProps: CarouselPr
275286
{...(props.useArrowKeys ? { onKeyDown: handleOnKeyDown } : {})}
276287
className={`${styles.carouselBase} ${props.className}`}
277288
>
278-
{showArrow.left && (
279-
<div onClick={onLeftArrowClick}>
289+
{!!showLeftArrow && (
290+
<div className={leftArrowClassnames} onClick={onLeftArrowClick}>
280291
{props.leftArrow ?? <Arrow direction="left" />}
281292
</div>
282293
)}
@@ -289,8 +300,12 @@ export const Carousel: FunctionComponent<CarouselProps> = (userProps: CarouselPr
289300
dragCallback={dragCallback}
290301
widthCallBack={widthCallBack}
291302
/>
292-
{showArrow.right && (
293-
<div onClick={onRightArrowClick} ref={slideButtonRef}>
303+
{!!showRightArrow && (
304+
<div
305+
className={rightArrowClassnames}
306+
onClick={onRightArrowClick}
307+
ref={slideButtonRef}
308+
>
294309
{props.rightArrow ?? <Arrow direction="right" />}
295310
</div>
296311
)}
@@ -324,6 +339,7 @@ export interface CarouselProps {
324339
pageCount?: number;
325340
leftArrow?: ReactElement | null;
326341
rightArrow?: ReactElement | null;
342+
arrowLogicOnEndOfPage?: 'hide' | 'disable';
327343
autoSwipe?: number | null;
328344
navigation?: null | ((selected: boolean) => ReactElement);
329345
triggerClickOn?: number;

0 commit comments

Comments
 (0)