forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToggleButtonExample.tsx
113 lines (106 loc) · 3.36 KB
/
ToggleButtonExample.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
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
import * as React from 'react';
import { View, StyleSheet, ImageBackground } from 'react-native';
import { ToggleButton, List, useTheme } from 'react-native-paper';
type StatusState = 'checked' | 'unchecked';
const ToggleButtonExample = () => {
const [first, setFirst] = React.useState<string>('bold');
const [fruit, setFruit] = React.useState<string>('watermelon');
const [status, setStatus] = React.useState<StatusState>('checked');
const {
colors: { background },
} = useTheme();
return (
<View style={[styles.container, { backgroundColor: background }]}>
<List.Section title="Single">
<View style={styles.padding}>
<ToggleButton
icon="android"
value="android"
status={status}
onPress={(status) =>
setStatus(status === 'checked' ? 'unchecked' : 'checked')
}
/>
</View>
</List.Section>
<List.Section title="Group">
<ToggleButton.Row
value={first}
onValueChange={(value: string) => setFirst(value)}
style={styles.padding}
>
<ToggleButton disabled icon="format-italic" value="italic" />
<ToggleButton icon="format-bold" value="bold" />
<ToggleButton icon="format-underline" value="underlined" />
<ToggleButton icon="format-color-text" value="format-color" />
</ToggleButton.Row>
</List.Section>
<List.Section title="Custom">
<View style={[styles.padding, styles.row]}>
<ToggleButton.Group
value={fruit}
onValueChange={(value: string) => setFruit(value)}
>
<ImageBackground
style={{
width: 143,
height: 153,
margin: 2,
}}
source={{
uri:
'https://images.pexels.com/photos/1068534/pexels-photo-1068534.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260',
}}
>
<ToggleButton
value="watermelon"
size={24}
style={{
position: 'absolute',
right: 0,
}}
color="white"
icon={fruit === 'watermelon' ? 'heart' : 'heart-outline'}
/>
</ImageBackground>
<ImageBackground
style={{
width: 143,
height: 153,
margin: 2,
}}
source={{
uri:
'https://images.pexels.com/photos/46174/strawberries-berries-fruit-freshness-46174.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260',
}}
>
<ToggleButton
value="strawberries"
size={24}
style={{
position: 'absolute',
right: 0,
}}
color="white"
icon={fruit === 'strawberries' ? 'heart' : 'heart-outline'}
/>
</ImageBackground>
</ToggleButton.Group>
</View>
</List.Section>
</View>
);
};
ToggleButtonExample.title = 'Toggle Button';
const styles = StyleSheet.create({
container: {
flex: 1,
},
padding: {
paddingHorizontal: 16,
},
row: {
flexDirection: 'row',
},
});
export default ToggleButtonExample;