-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathRadioButtonExample.tsx
More file actions
104 lines (96 loc) · 2.98 KB
/
RadioButtonExample.tsx
File metadata and controls
104 lines (96 loc) · 2.98 KB
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
import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import {
MD2Colors,
MD3Colors,
Paragraph,
RadioButton,
Text,
TouchableRipple,
} from 'react-native-paper';
import { useExampleTheme } from '../hooks/useExampleTheme';
import ScreenWrapper from '../ScreenWrapper';
type State = 'normal' | 'normal-ios' | 'normal-item' | 'custom';
const RadioButtonExample = () => {
const [checked, setChecked] = React.useState<State>('normal');
const { isV3 } = useExampleTheme();
const TextComponent = isV3 ? Text : Paragraph;
return (
<ScreenWrapper style={styles.container}>
<TouchableRipple onPress={() => setChecked('normal')}>
<View style={styles.row}>
<TextComponent>Normal - Material Design</TextComponent>
<View pointerEvents="none">
<RadioButton.Android
value="normal"
status={checked === 'normal' ? 'checked' : 'unchecked'}
/>
</View>
</View>
</TouchableRipple>
<TouchableRipple onPress={() => setChecked('normal-ios')}>
<View style={styles.row}>
<TextComponent>Normal 2 - IOS</TextComponent>
<View pointerEvents="none">
<RadioButton.IOS
value="normal-ios"
status={checked === 'normal-ios' ? 'checked' : 'unchecked'}
/>
</View>
</View>
</TouchableRipple>
<TouchableRipple onPress={() => setChecked('custom')}>
<View style={styles.row}>
<TextComponent>Custom</TextComponent>
<View pointerEvents="none">
<RadioButton
value="custom"
color={isV3 ? MD3Colors.error70 : MD2Colors.blue500}
status={checked === 'custom' ? 'checked' : 'unchecked'}
/>
</View>
</View>
</TouchableRipple>
<RadioButton.Item
label="Normal 3 - Item"
value="normal-item"
status={checked === 'normal-item' ? 'checked' : 'unchecked'}
onPress={() => setChecked('normal-item')}
/>
<View style={styles.row}>
<TextComponent>Checked (Disabled)</TextComponent>
<RadioButton value="first" status="checked" disabled />
</View>
<View style={styles.row}>
<TextComponent>Unchecked (Disabled)</TextComponent>
<RadioButton value="second" status="unchecked" disabled />
</View>
<RadioButton.Item
label="Checked - Item (Disabled)"
value="third"
status="checked"
disabled
/>
<RadioButton.Item
label="Unchecked - Item (Disabled)"
value="fourth"
status="unchecked"
disabled
/>
</ScreenWrapper>
);
};
RadioButtonExample.title = 'Radio Button';
const styles = StyleSheet.create({
container: {
paddingVertical: 8,
},
row: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingVertical: 8,
paddingHorizontal: 16,
},
});
export default RadioButtonExample;