import React, { useState } from 'react'; import { View, Text, TouchableOpacity, FlatList, ViewProps, } from 'react-native'; import ChevronDownIcon from '../icons/chevron-down.svg'; import ChevronUpIcon from '../icons/chevron-up.svg'; import InformationGray from '../icons/information-gray.svg'; import { classNames } from '../utils'; import { RadioButton } from './RadioButton'; export interface DropdownOption { label: string; value: string; } export interface SingleSelectDropdownProps extends ViewProps { label?: string; disabled?: boolean; caption?: string; options: DropdownOption[]; onSelect: (item: DropdownOption) => void; selectedValue?: DropdownOption; placeholder?: string; className?: string; } export const SingleSelectDropdown: React.FC = ({ label, options, disabled = false, caption, onSelect, selectedValue, placeholder = 'Select an option', className, ...restOfProps }) => { const [dropdownVisible, setDropdownVisible] = useState(false); const handleSelect = (value: DropdownOption) => { onSelect(value); setDropdownVisible(false); }; return ( {label && ( {label} )} !disabled ? setDropdownVisible(!dropdownVisible) : undefined } > {selectedValue?.label || placeholder} {dropdownVisible ? : } {caption && ( {caption} )} {dropdownVisible && ( String(item?.value)} renderItem={({ item, index }) => ( handleSelect(item)} className={classNames( 'flex p-3 rounded-lg flex-row items-center w-full', `${selectedValue?.value === item?.value && 'bg-[#F2EEFF]'}`, `${index !== options?.length - 1 ? 'mb-2' : ''}` )} > handleSelect(item)} /> {item?.label} )} /> )} ); };