forked from mrzachnugent/react-native-reusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
radio-group.tsx
49 lines (46 loc) · 1.32 KB
/
radio-group.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
import * as React from 'react';
import { View } from 'react-native';
import { Label, LabelText } from '~/components/ui/label';
import { RadioGroup, RadioGroupItem } from '~/components/ui/radio-group';
export default function RadioGroupScreen() {
const [value, setValue] = React.useState('Comfortable');
function onLabelPress(label: string) {
return () => {
setValue(label);
};
}
return (
<View className='flex-1 justify-center items-center p-6'>
<RadioGroup value={value} onValueChange={setValue} className='gap-3'>
<RadioGroupItemWithLabel
value='Default'
onLabelPress={onLabelPress('Default')}
/>
<RadioGroupItemWithLabel
value='Comfortable'
onLabelPress={onLabelPress('Comfortable')}
/>
<RadioGroupItemWithLabel
value='Compact'
onLabelPress={onLabelPress('Compact')}
/>
</RadioGroup>
</View>
);
}
function RadioGroupItemWithLabel({
value,
onLabelPress,
}: {
value: string;
onLabelPress: () => void;
}) {
return (
<View className={'flex-row gap-2 items-center'}>
<RadioGroupItem aria-labelledby={`label-for-${value}`} value={value} />
<Label onPress={onLabelPress}>
<LabelText nativeID={`label-for-${value}`}>{value}</LabelText>
</Label>
</View>
);
}