-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathValueSelectorModal.tsx
65 lines (60 loc) · 2.24 KB
/
ValueSelectorModal.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
import React, {useMemo} from 'react';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Modal from '@components/Modal';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/RadioListItem';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import type {ValueSelectorModalProps} from './types';
function ValueSelectorModal({
items = [],
selectedItem,
label = '',
isVisible,
onClose,
onItemSelected,
shouldShowTooltips = true,
onBackdropPress,
shouldEnableKeyboardAvoidingView = true,
}: ValueSelectorModalProps) {
const styles = useThemeStyles();
const sections = useMemo(
() => [{data: items.map((item) => ({value: item.value, alternateText: item.description, text: item.label ?? '', isSelected: item === selectedItem, keyForList: item.value ?? ''}))}],
[items, selectedItem],
);
return (
<Modal
type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED}
isVisible={isVisible}
onClose={() => onClose?.()}
onModalHide={onClose}
hideModalContentWhileAnimating
useNativeDriver
onBackdropPress={onBackdropPress}
>
<ScreenWrapper
style={styles.pb0}
includePaddingTop={false}
includeSafeAreaPaddingBottom
testID={ValueSelectorModal.displayName}
shouldEnableKeyboardAvoidingView={shouldEnableKeyboardAvoidingView}
>
<HeaderWithBackButton
title={label}
onBackButtonPress={onClose}
/>
<SelectionList
sections={sections}
onSelectRow={(item) => onItemSelected?.(item)}
initiallyFocusedOptionKey={selectedItem?.value}
shouldStopPropagation
shouldShowTooltips={shouldShowTooltips}
ListItem={RadioListItem}
/>
</ScreenWrapper>
</Modal>
);
}
ValueSelectorModal.displayName = 'ValueSelectorModal';
export default ValueSelectorModal;