select_button.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React from 'react';
  2. import {
  3. Text,
  4. View,
  5. StyleSheet,
  6. ViewStyle,
  7. StyleProp,
  8. TouchableOpacity
  9. } from 'react-native';
  10. type Option = {
  11. label: string;
  12. };
  13. interface SingleSelectButtonGroupProps {
  14. options: Option[];
  15. onSelectionChange: (value: string) => void;
  16. extendedStyle?: StyleProp<ViewStyle>;
  17. selectedOption: string | null | undefined;
  18. }
  19. const SingleSelectButtonGroup: React.FC<SingleSelectButtonGroupProps> = ({
  20. options,
  21. onSelectionChange,
  22. extendedStyle,
  23. selectedOption
  24. }) => {
  25. return (
  26. <View>
  27. {options.map((option, index) => (
  28. <TouchableOpacity
  29. key={index}
  30. style={[
  31. styles.button,
  32. selectedOption === option.label &&
  33. styles.selectedButton,
  34. extendedStyle
  35. ]}
  36. onPress={() => onSelectionChange(option.label)}
  37. >
  38. <Text style={{ fontSize: 16 }}>{option.label}</Text>
  39. <View
  40. style={[
  41. styles.circle,
  42. selectedOption === option.label &&
  43. styles.selectedCircle
  44. ]}
  45. />
  46. </TouchableOpacity>
  47. ))}
  48. </View>
  49. );
  50. };
  51. const styles = StyleSheet.create({
  52. button: {
  53. maxWidth: '100%',
  54. padding: 20,
  55. marginBottom: 10,
  56. borderWidth: 1,
  57. justifyContent: 'space-between',
  58. alignItems: 'center',
  59. flexDirection: 'row',
  60. borderRadius: 12,
  61. borderColor: '#bbbbbb'
  62. },
  63. circle: {
  64. width: 10,
  65. height: 10,
  66. borderRadius: 5,
  67. backgroundColor: '#e8e8e8',
  68. borderWidth: 1,
  69. borderColor: '#bbbbbb'
  70. },
  71. selectedButton: {
  72. borderWidth: 1,
  73. borderColor: '#949494'
  74. },
  75. selectedCircle: {
  76. backgroundColor: '#949494'
  77. },
  78. redOutline: {
  79. borderWidth: 1,
  80. borderColor: 'red'
  81. }
  82. });
  83. export default SingleSelectButtonGroup;