-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.native.js
104 lines (94 loc) · 2.37 KB
/
index.native.js
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
/**
* External dependencies
*/
import { TextInput } from 'react-native';
import { useNavigation } from '@react-navigation/native';
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { Icon, chevronRight } from '@wordpress/icons';
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
/**
* Internal dependencies
*/
import styles from './styles.scss';
import BottomSheet from '../bottom-sheet';
import PanelBody from '../../panel/body';
import FooterMessageControl from '../../footer-message-control';
const BottomSheetTextControl = ( {
initialValue,
onChange,
placeholder,
label,
icon,
footerNote,
cellPlaceholder,
disabled,
} ) => {
const [ showSubSheet, setShowSubSheet ] = useState( false );
const navigation = useNavigation();
const goBack = () => {
setShowSubSheet( false );
navigation.goBack();
};
const openSubSheet = () => {
navigation.navigate( BottomSheet.SubSheet.screenName );
setShowSubSheet( true );
};
const horizontalBorderStyle = usePreferredColorSchemeStyle(
styles.horizontalBorder,
styles.horizontalBorderDark
);
const textEditorStyle = usePreferredColorSchemeStyle(
styles.textEditor,
styles.textEditorDark
);
return (
<BottomSheet.SubSheet
navigationButton={
<BottomSheet.Cell
icon={ icon }
label={ label }
onPress={ openSubSheet }
value={ initialValue || '' }
placeholder={ cellPlaceholder || placeholder || '' }
disabled={ disabled }
>
{ disabled ? null : <Icon icon={ chevronRight } /> }
</BottomSheet.Cell>
}
showSheet={ showSubSheet }
>
<>
<BottomSheet.NavBar>
<BottomSheet.NavBar.BackButton onPress={ goBack } />
<BottomSheet.NavBar.Heading>
{ label }
</BottomSheet.NavBar.Heading>
</BottomSheet.NavBar>
<PanelBody style={ horizontalBorderStyle }>
<TextInput
label={ label }
onChangeText={ ( text ) => onChange( text ) }
defaultValue={ initialValue }
multiline
placeholder={ placeholder }
placeholderTextColor="#87a6bc"
style={ textEditorStyle }
textAlignVertical="top"
/>
</PanelBody>
</>
{ footerNote && (
<PanelBody style={ styles.textFooternote }>
<FooterMessageControl
label={ footerNote }
textAlign="left"
/>
</PanelBody>
) }
</BottomSheet.SubSheet>
);
};
export default BottomSheetTextControl;