// components/Select.tsx import { GStyles } from "@/styles/global-styles"; import React, { useState } from "react"; import { FlatList, Modal, Pressable, Text, TouchableOpacity, View, } from "react-native"; type SelectItem = { label: string; value: string | number; }; type SelectProps = { label?: string; placeholder?: string; data: SelectItem[]; value?: string | number | null; required?: boolean; // <-- new prop disabled?: boolean; // <-- tambahkan prop disabled onChange: (value: string | number) => void; borderRadius?: number; }; const SelectCustom: React.FC = ({ label, placeholder = "Pilih opsi", data, value, required = false, // <-- default false disabled = false, // <-- default false onChange, borderRadius = 8, }) => { const [modalVisible, setModalVisible] = useState(false); const selectedItem = data.find((item) => item.value === value); const hasError = required && value === null; // <-- check if empty and required return ( {label && ( {label} {required && *} )} !disabled && setModalVisible(true)} > {selectedItem?.label || placeholder} setModalVisible(false)} > String(item.value)} renderItem={({ item }) => ( { onChange(item.value); setModalVisible(false); }} > {item.label} )} /> {/* Optional Error Message */} {hasError && ( Harap pilih salah satu )} ); }; export default SelectCustom;