-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathindex.tsx
58 lines (51 loc) · 1.99 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
import React, {forwardRef, useState} from 'react';
import type {ForwardedRef} from 'react';
import {View} from 'react-native';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import TextSelectorModal from './TextSelectorModal';
import type {TextPickerProps} from './types';
function TextPicker({value, description, placeholder = '', errorText = '', onInputChange, furtherDetails, rightLabel, ...rest}: TextPickerProps, forwardedRef: ForwardedRef<View>) {
const styles = useThemeStyles();
const [isPickerVisible, setIsPickerVisible] = useState(false);
const showPickerModal = () => {
setIsPickerVisible(true);
};
const hidePickerModal = () => {
setIsPickerVisible(false);
};
const updateInput = (updatedValue: string) => {
if (updatedValue !== value) {
onInputChange?.(updatedValue);
}
hidePickerModal();
};
return (
<View>
<MenuItemWithTopDescription
ref={forwardedRef}
shouldShowRightIcon
title={value ?? placeholder ?? ''}
description={description}
onPress={showPickerModal}
furtherDetails={furtherDetails}
rightLabel={rightLabel}
brickRoadIndicator={errorText ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={errorText}
style={[styles.moneyRequestMenuItem]}
/>
<TextSelectorModal
value={value}
isVisible={isPickerVisible}
description={description}
onClose={hidePickerModal}
onValueSelected={updateInput}
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
/>
</View>
);
}
TextPicker.displayName = 'TextPicker';
export default forwardRef(TextPicker);