import { useState } from "react"; import { View } from "react-native"; import RNReactNativeHapticFeedback from "react-native-haptic-feedback"; import { useIOTheme } from "../../context"; import { IOColors, IOSelectionTickVisualParams } from "../../core"; import { useIOFontDynamicScale } from "../../utils/accessibility"; import { Icon } from "../icons"; import { HStack } from "../layout"; import { AnimatedRadio } from "../radio/AnimatedRadio"; import { BodySmall, H6 } from "../typography"; import { PressableListItemBase } from "./PressableListItemBase"; export type ListItemRadioWithAmountProps = { onValueChange?: (newValue: boolean) => void; selected?: boolean; label: string; formattedAmountString: string; accessibilityLabel?: string; } & ( | { isSuggested?: false; suggestReason?: never; } | { isSuggested?: true; suggestReason: string; } ); export const ListItemRadioWithAmount = ({ onValueChange, selected, label, accessibilityLabel, isSuggested = false, suggestReason, formattedAmountString }: ListItemRadioWithAmountProps) => { const { dynamicFontScale } = useIOFontDynamicScale(); const [toggleValue, setToggleValue] = useState(selected ?? false); const pressHandler = () => { RNReactNativeHapticFeedback.trigger("impactLight"); setToggleValue(val => !val); if (onValueChange !== undefined) { onValueChange(!toggleValue); } }; const theme = useIOTheme(); const suggestColor: IOColors = "hanPurple-500"; const defaultAccessibilityLabel = `${label} ${formattedAmountString} ${ suggestReason ?? "" }`; return (
{label}
{isSuggested && ( {suggestReason} )}
{formattedAmountString}
); };