import { useEffect, useRef } from "react" import { StyleProp, View, ViewStyle, Animated } from "react-native" import { useAppTheme } from "@/theme/context" import { $styles } from "@/theme/styles" import { s } from "@/utils/responsive" import { $inputOuterBase, BaseToggleInputProps, ToggleProps, Toggle } from "./Toggle" export interface RadioToggleProps extends Omit, "ToggleInput"> { /** * Optional style prop that affects the dot View. */ inputDetailStyle?: ViewStyle } interface RadioInputProps extends BaseToggleInputProps {} /** * @param {RadioToggleProps} props - The props for the `Radio` component. * @see [Documentation and Examples]{@link https://docs.infinite.red/ignite-cli/boilerplate/app/components/Radio} * @returns {JSX.Element} The rendered `Radio` component. */ export function Radio(props: RadioToggleProps) { return } function RadioInput(props: RadioInputProps) { const { on, status, disabled, outerStyle: $outerStyleOverride, innerStyle: $innerStyleOverride, detailStyle: $detailStyleOverride, } = props const { theme: { colors }, } = useAppTheme() const opacity = useRef(new Animated.Value(0)) useEffect(() => { Animated.timing(opacity.current, { toValue: on ? 1 : 0, duration: 300, useNativeDriver: true, }).start() }, [on]) const offBackgroundColor = [ disabled && colors.palette.neutral400, status === "error" && colors.errorBackground, colors.palette.neutral200, ].filter(Boolean)[0] const outerBorderColor = [ disabled && colors.palette.neutral400, status === "error" && colors.error, !on && colors.palette.neutral800, colors.palette.secondary500, ].filter(Boolean)[0] const onBackgroundColor = [ disabled && colors.transparent, status === "error" && colors.errorBackground, colors.palette.neutral100, ].filter(Boolean)[0] const dotBackgroundColor = [ disabled && colors.palette.neutral600, status === "error" && colors.error, colors.palette.secondary500, ].filter(Boolean)[0] return ( ) } const $radioDetail: ViewStyle = { width: s(12), height: s(12), borderRadius: s(6), } const $inputOuter: StyleProp = [$inputOuterBase, { borderRadius: s(12) }]