-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
BaseListItem.tsx
113 lines (104 loc) · 4.22 KB
/
BaseListItem.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React from 'react';
import {View} from 'react-native';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import type {BaseListItemProps, ListItem} from './types';
function BaseListItem<TItem extends ListItem>({
item,
pressableStyle,
wrapperStyle,
selectMultipleStyle,
isDisabled = false,
shouldPreventDefaultFocusOnSelectRow = false,
canSelectMultiple = false,
onSelectRow,
onDismissError = () => {},
rightHandSideComponent,
keyForList,
errors,
pendingAction,
FooterComponent,
children,
}: BaseListItemProps<TItem>) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const rightHandSideComponentRender = () => {
if (canSelectMultiple || !rightHandSideComponent) {
return null;
}
if (typeof rightHandSideComponent === 'function') {
return rightHandSideComponent(item);
}
return rightHandSideComponent;
};
return (
<OfflineWithFeedback
onClose={() => onDismissError(item)}
pendingAction={pendingAction}
errors={errors}
errorRowStyles={styles.ph5}
>
<PressableWithFeedback
onPress={() => onSelectRow(item)}
disabled={isDisabled}
accessibilityLabel={item.text}
role={CONST.ROLE.BUTTON}
hoverDimmingValue={1}
hoverStyle={styles.hoveredComponentBG}
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
onMouseDown={shouldPreventDefaultFocusOnSelectRow ? (e) => e.preventDefault() : undefined}
nativeID={keyForList}
style={pressableStyle}
>
{({hovered}) => (
<>
<View style={wrapperStyle}>
{canSelectMultiple && (
<View
role={CONST.ROLE.BUTTON}
style={StyleUtils.getCheckboxPressableStyle()}
>
<View style={selectMultipleStyle}>
{item.isSelected && (
<Icon
src={Expensicons.Checkmark}
fill={theme.textLight}
height={14}
width={14}
/>
)}
</View>
</View>
)}
{typeof children === 'function' ? children(hovered) : children}
{!canSelectMultiple && item.isSelected && !rightHandSideComponent && (
<View
style={[styles.flexRow, styles.alignItemsCenter, styles.ml3]}
accessible={false}
>
<View>
<Icon
src={Expensicons.Checkmark}
fill={theme.success}
/>
</View>
</View>
)}
{rightHandSideComponentRender()}
</View>
{FooterComponent}
</>
)}
</PressableWithFeedback>
</OfflineWithFeedback>
);
}
BaseListItem.displayName = 'BaseListItem';
export default BaseListItem;