-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathCarouselButtons.tsx
81 lines (70 loc) · 2.94 KB
/
CarouselButtons.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React from 'react';
import {View} from 'react-native';
import type {Attachment} from '@components/Attachments/types';
import Button from '@components/Button';
import * as Expensicons from '@components/Icon/Expensicons';
import Tooltip from '@components/Tooltip';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
type CarouselButtonsProps = {
/** Where the arrows should be visible */
shouldShowArrows: boolean;
/** The current page index */
page: number;
/** The attachments from the carousel */
attachments: Attachment[];
/** Callback to go one page back */
onBack: () => void;
/** Callback to go one page forward */
onForward: () => void;
/** Callback for autohiding carousel button arrows */
autoHideArrow?: () => void;
/** Callback for cancelling autohiding of carousel button arrows */
cancelAutoHideArrow?: () => void;
};
function CarouselButtons({page, attachments, shouldShowArrows, onBack, onForward, cancelAutoHideArrow, autoHideArrow}: CarouselButtonsProps) {
const theme = useTheme();
const styles = useThemeStyles();
const isBackDisabled = page === 0;
const isForwardDisabled = page === attachments.length - 1;
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
return shouldShowArrows ? (
<>
{!isBackDisabled && (
<Tooltip text={translate('common.previous')}>
<View style={[styles.attachmentArrow, shouldUseNarrowLayout ? styles.l2 : styles.l8]}>
<Button
small
innerStyles={[styles.arrowIcon]}
icon={Expensicons.BackArrow}
iconFill={theme.text}
onPress={onBack}
onPressIn={cancelAutoHideArrow}
onPressOut={autoHideArrow}
/>
</View>
</Tooltip>
)}
{!isForwardDisabled && (
<Tooltip text={translate('common.next')}>
<View style={[styles.attachmentArrow, shouldUseNarrowLayout ? styles.r2 : styles.r8]}>
<Button
small
innerStyles={[styles.arrowIcon]}
icon={Expensicons.ArrowRight}
iconFill={theme.text}
onPress={onForward}
onPressIn={cancelAutoHideArrow}
onPressOut={autoHideArrow}
/>
</View>
</Tooltip>
)}
</>
) : null;
}
CarouselButtons.displayName = 'CarouselButtons';
export default CarouselButtons;