diff options
Diffstat (limited to 'src/view/com/util/forms/RadioGroup.tsx')
-rw-r--r-- | src/view/com/util/forms/RadioGroup.tsx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/view/com/util/forms/RadioGroup.tsx b/src/view/com/util/forms/RadioGroup.tsx new file mode 100644 index 000000000..6684cde5c --- /dev/null +++ b/src/view/com/util/forms/RadioGroup.tsx @@ -0,0 +1,34 @@ +import React, {useState} from 'react' +import {View} from 'react-native' +import {RadioButton} from './RadioButton' + +export interface RadioGroupItem { + label: string + key: string +} + +export function RadioGroup({ + items, + onSelect, +}: { + items: RadioGroupItem[] + onSelect: (key: string) => void +}) { + const [selection, setSelection] = useState<string>('') + const onSelectInner = (key: string) => { + setSelection(key) + onSelect(key) + } + return ( + <View> + {items.map(item => ( + <RadioButton + key={item.key} + label={item.label} + isSelected={item.key === selection} + onPress={() => onSelectInner(item.key)} + /> + ))} + </View> + ) +} |