-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathindex.tsx
96 lines (78 loc) · 2.78 KB
/
index.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
import React, {useState} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import CONST from '@src/CONST';
import PushRowModal from './PushRowModal';
type PushRowWithModalProps = {
/** The list of options that we want to display where key is option code and value is option name */
optionsList: Record<string, string>;
/** Current value of the selected item */
value?: string;
/** Function called whenever list item is selected */
onInputChange?: (value: string, key?: string) => void;
/** Additional styles to apply to container */
wrapperStyles?: StyleProp<ViewStyle>;
/** The description for the picker */
description: string;
/** The title of the modal */
modalHeaderTitle: string;
/** The title of the search input */
searchInputTitle: string;
/** Whether the selected option is editable */
shouldAllowChange?: boolean;
/** Text to display on error message */
errorText?: string;
/** The ID of the input that should be reset when the value changes */
stateInputIDToReset?: string;
};
function PushRowWithModal({
value,
optionsList,
wrapperStyles,
description,
modalHeaderTitle,
searchInputTitle,
shouldAllowChange = true,
errorText,
onInputChange = () => {},
stateInputIDToReset,
}: PushRowWithModalProps) {
const [isModalVisible, setIsModalVisible] = useState(false);
const handleModalClose = () => {
setIsModalVisible(false);
};
const handleModalOpen = () => {
setIsModalVisible(true);
};
const handleOptionChange = (optionValue: string) => {
onInputChange(optionValue);
if (stateInputIDToReset) {
onInputChange('', stateInputIDToReset);
}
};
return (
<>
<MenuItemWithTopDescription
description={description}
title={value ? optionsList[value] : ''}
shouldShowRightIcon={shouldAllowChange}
onPress={handleModalOpen}
wrapperStyle={wrapperStyles}
interactive={shouldAllowChange}
brickRoadIndicator={errorText ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={errorText}
/>
<PushRowModal
isVisible={isModalVisible}
selectedOption={value ?? ''}
onOptionChange={handleOptionChange}
onClose={handleModalClose}
optionsList={optionsList}
headerTitle={modalHeaderTitle}
searchInputTitle={searchInputTitle}
/>
</>
);
}
PushRowWithModal.displayName = 'PushRowWithModal';
export default PushRowWithModal;