/* eslint-disable react-native/no-inline-styles */ import React, {forwardRef, useImperativeHandle, useState} from 'react'; import { StyleSheet, Text, TextStyle, TouchableOpacity, TouchableWithoutFeedback, View, ViewStyle, } from 'react-native'; import { RadioButton, RadioButtonProps, TextInput, TextInputProps, } from 'react-native-paper'; import {useTheme} from '../Theme'; type FormFieldProps = Omit< TextInputProps & {initialValue: string}, 'value' | 'onChangeText' | 'ref' >; export type FormFieldRef = { get: () => string | boolean; set: (input: string) => void; }; export const FormField = forwardRef( (props, ref) => { const [input, setInput] = useState( props.initialValue ? props.initialValue : '', ); useImperativeHandle(ref, () => ({ get() { return input; }, set(inp) { setInput(inp); }, })); return ( setInput(text)} /> ); }, ); type RadioGroupProps = Omit< { options: string[]; label: string; viewStyle?: ViewStyle; labelStyle?: TextStyle; initialValue?: string; } & RadioButtonProps, 'status' | 'onPress' | 'value' | 'style' >; type RadioGroupRef = { get: () => string | boolean; set: (input: string) => void; }; export const RadioGroup = forwardRef( (props, ref) => { const [checked, setChecked] = useState( props.initialValue ? props.initialValue : '', ); const onPressHandler = (option: string) => checked === option ? setChecked('') : setChecked(option); useImperativeHandle(ref, () => ({ get() { return checked; }, set(inp) { setChecked(inp); }, })); return ( {props.label} {props.options.map(option => ( onPressHandler(option)} /> onPressHandler(option)}> {option} ))} ); }, ); const RadioButtonStyles = StyleSheet.create({ container: { flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start', }, text: { color: 'black', }, label: { fontSize: 15, fontWeight: 'bold', }, }); export const ToggleGroup = forwardRef( (props, ref) => { const theme = useTheme(); const [checked, setChecked] = useState( props.initialValue ? props.initialValue : '', ); const onPressHandler = (option: string) => checked === option ? setChecked('') : setChecked(option); useImperativeHandle(ref, () => ({ get() { return checked; }, set(inp) { setChecked(inp); }, })); return ( {props.options.map((option, index) => { return ( onPressHandler(option)}> {option} ); })} ); }, ); const ToggleButtonStyles = StyleSheet.create({ container: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', paddingVertical: 20, flex: 1, borderWidth: 2, borderColor: '#B7B7B7', }, text: { fontWeight: 'bold', textTransform: 'uppercase', fontSize: 16, fontFamily: 'Inter-Black', }, label: { fontSize: 15, fontWeight: 'bold', }, });