-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
index.native.js
117 lines (109 loc) · 2.85 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
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* External dependencies
*/
import { View } from 'react-native';
/**
* WordPress dependencies
*/
import { useNavigation } from '@react-navigation/native';
import { useState } from '@wordpress/element';
import { Icon, chevronRight, check } from '@wordpress/icons';
import { __, sprintf } from '@wordpress/i18n';
import { BottomSheet } from '@wordpress/components';
/**
* Internal dependencies
*/
import styles from './style.scss';
const BottomSheetSelectControl = ( {
label,
icon,
options: items,
onChange,
value: selectedValue,
} ) => {
const [ showSubSheet, setShowSubSheet ] = useState( false );
const navigation = useNavigation();
const onChangeValue = ( value ) => {
return () => {
goBack();
onChange( value );
};
};
const selectedOption = items.find(
( option ) => option.value === selectedValue
);
const goBack = () => {
setShowSubSheet( false );
navigation.goBack();
};
const openSubSheet = () => {
navigation.navigate( BottomSheet.SubSheet.screenName );
setShowSubSheet( true );
};
return (
<BottomSheet.SubSheet
navigationButton={
<BottomSheet.Cell
label={ label }
separatorType="none"
icon={ icon }
value={ selectedOption.label }
onPress={ openSubSheet }
accessibilityRole={ 'button' }
accessibilityLabel={ sprintf(
// translators: %1$s: Select control button label e.g. "Button width". %2$s: Select control option value e.g: "Auto, 25%".
__( '%1$s. Currently selected: %2$s' ),
label,
selectedOption.label
) }
accessibilityHint={ sprintf(
// translators: %s: Select control button label e.g. "Button width"
__( 'Navigates to select %s' ),
label
) }
>
<Icon icon={ chevronRight }></Icon>
</BottomSheet.Cell>
}
showSheet={ showSubSheet }
>
<>
<BottomSheet.NavBar>
<BottomSheet.NavBar.BackButton onPress={ goBack } />
<BottomSheet.NavBar.Heading>
{ label }
</BottomSheet.NavBar.Heading>
</BottomSheet.NavBar>
<View style={ styles.selectControl }>
{ items.map( ( item, index ) => (
<BottomSheet.Cell
customActionButton
separatorType="none"
label={ item.label }
icon={ item.icon }
onPress={ onChangeValue( item.value ) }
leftAlign={ true }
key={ index }
accessibilityRole={ 'button' }
accessibilityLabel={
item.value === selectedValue
? sprintf(
// translators: %s: Select control option value e.g: "Auto, 25%".
__( 'Selected: %s' ),
item.label
)
: item.label
}
accessibilityHint={ __( 'Double tap to select' ) }
>
{ item.value === selectedValue && (
<Icon icon={ check }></Icon>
) }
</BottomSheet.Cell>
) ) }
</View>
</>
</BottomSheet.SubSheet>
);
};
export default BottomSheetSelectControl;