import { Check } from 'lucide-react-native'; import { RefObject, useCallback, useState } from 'react'; import { Modal, Pressable, StyleSheet, View } from 'react-native'; import { Text } from './Text'; import { font, radius, shadows, spacing, useColors } from './styles'; type DropdownOption = { label: string; value: string }; type DropdownProps = { triggerRef: RefObject; visible: boolean; onClose: () => void; options: DropdownOption[]; selected?: string; onSelect: (value: string) => void; }; type Position = { top: number; right: number }; export function Dropdown({ triggerRef, visible, onClose, options, selected, onSelect, }: DropdownProps) { const c = useColors(); const [position, setPosition] = useState(null); const measureAndShow = useCallback(() => { triggerRef.current?.measureInWindow((x, y, width, height) => { setPosition({ top: y + height + 4, right: 24 }); }); }, [triggerRef]); if (!visible) return null; return ( {position && ( {options.map((opt, i) => { const isSelected = opt.value === selected; const isLast = i === options.length - 1; return ( [ styles.option, !isLast && { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: c.borderSubtle, }, pressed && { backgroundColor: c.tagBg }, ]} onPress={() => { onSelect(opt.value); onClose(); }} > {opt.label} {isSelected && ( )} ); })} )} ); } const styles = StyleSheet.create({ backdrop: { flex: 1, }, menu: { position: 'absolute', minWidth: 160, borderRadius: radius.md, borderWidth: 1, overflow: 'hidden', }, option: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingVertical: spacing.md, paddingHorizontal: spacing.lg, }, optionText: { fontSize: font.md, fontWeight: '500', }, checkmark: { marginLeft: spacing.sm, }, });