select_button.tsx 1.7 KB

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