import React, { useState } from 'react' import { StyleSheet, Text, View } from 'react-native' import Touchable from 'src/components/Touchable' import DownArrowIcon from 'src/icons/DownArrowIcon' import Colors from 'src/styles/colors' import { typeScale } from 'src/styles/fonts' import { Spacing } from 'src/styles/styles' interface Props { options: { value: T; label: string }[] onValueSelected(value: T): void testId?: string } /* Dropdown component with unscrollable list of options */ function Dropdown(props: Props) { const testID = props.testId ? props.testId : 'Dropdown' const [isOpen, setIsOpen] = useState(false) const [labelSelected, setLabelSelected] = useState() const toggleOpen = () => { setIsOpen((prev) => !prev) } return ( {labelSelected} {!isOpen ? ( ) : ( )} {isOpen && ( {props.options.map((option) => { return ( { setLabelSelected(option.label) toggleOpen() props.onValueSelected(option.value) }} testID={testID + '-' + option.label} key={option.label} > {option.label} ) })} )} ) } const styles = StyleSheet.create({ selectedOptionContainer: { padding: Spacing.Small12, backgroundColor: Colors.textInputBackground, borderColor: Colors.borderSecondary, borderRadius: Spacing.Tiny4, borderWidth: 1, gap: Spacing.Thick24, flexDirection: 'row', alignItems: 'center', }, optionsContainer: { position: 'absolute', top: 0, borderColor: Colors.borderSecondary, borderRadius: Spacing.Tiny4, borderWidth: 1, backgroundColor: Colors.textInputBackground, flexDirection: 'column', width: '100%', }, optionText: { ...typeScale.bodyMedium, flexGrow: 1, }, touchableOption: { padding: Spacing.Small12, }, }) export default Dropdown