130 lines
2.7 KiB
TypeScript
130 lines
2.7 KiB
TypeScript
import React from 'react';
|
|
import {
|
|
Modal,
|
|
View,
|
|
Text,
|
|
TouchableOpacity,
|
|
StyleSheet,
|
|
Pressable,
|
|
ActivityIndicator,
|
|
} from 'react-native';
|
|
import colors from '../Color';
|
|
|
|
type ConfirmDialogProps = {
|
|
visible: boolean;
|
|
title?: string;
|
|
message: string;
|
|
confirmText?: string;
|
|
cancelText?: string;
|
|
onConfirm: () => void;
|
|
onClose: () => void;
|
|
loading:boolean
|
|
};
|
|
|
|
const ConfirmDialog: React.FC<ConfirmDialogProps> = ({
|
|
visible,
|
|
title = 'Confirm',
|
|
message,
|
|
confirmText = 'Confirm',
|
|
cancelText = 'Cancel',
|
|
onConfirm,
|
|
onClose,
|
|
loading,
|
|
}) => {
|
|
return (
|
|
<Modal
|
|
visible={visible}
|
|
transparent
|
|
animationType="fade"
|
|
statusBarTranslucent
|
|
onRequestClose={onClose}
|
|
>
|
|
{/* Overlay (click to close) */}
|
|
<Pressable style={styles.overlay} onPress={onClose}>
|
|
{/* Stop propagation */}
|
|
<Pressable style={styles.container}>
|
|
{/* Title */}
|
|
<Text style={styles.title}>{title}</Text>
|
|
|
|
{/* Message */}
|
|
<Text style={styles.message}>{message}</Text>
|
|
|
|
{/* Actions */}
|
|
<View style={styles.actions}>
|
|
<TouchableOpacity style={styles.cancelBtn} onPress={onClose}>
|
|
<Text style={styles.cancelText}>{cancelText}</Text>
|
|
</TouchableOpacity>
|
|
|
|
<TouchableOpacity
|
|
style={styles.confirmBtn}
|
|
onPress={() => {
|
|
onConfirm();
|
|
onClose();
|
|
}}
|
|
>
|
|
{ !loading ?<Text style={styles.confirmText}>{confirmText}</Text>:<ActivityIndicator
|
|
color={colors.primary}
|
|
size={30}
|
|
/>}
|
|
</TouchableOpacity>
|
|
</View>
|
|
</Pressable>
|
|
</Pressable>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default ConfirmDialog;
|
|
|
|
const styles = StyleSheet.create({
|
|
overlay: {
|
|
flex: 1,
|
|
backgroundColor: 'rgba(0,0,0,0.5)',
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
},
|
|
container: {
|
|
width: '85%',
|
|
backgroundColor: '#fff',
|
|
borderRadius: 12,
|
|
padding: 20,
|
|
elevation: 5,
|
|
},
|
|
title: {
|
|
fontSize: 18,
|
|
fontWeight: '600',
|
|
marginBottom: 8,
|
|
textAlign: 'center',
|
|
},
|
|
message: {
|
|
fontSize: 15,
|
|
color: '#444',
|
|
textAlign: 'center',
|
|
marginBottom: 20,
|
|
},
|
|
actions: {
|
|
flexDirection: 'row',
|
|
justifyContent: 'flex-end',
|
|
},
|
|
cancelBtn: {
|
|
paddingVertical: 10,
|
|
paddingHorizontal: 16,
|
|
marginRight: 10,
|
|
},
|
|
cancelText: {
|
|
fontSize: 14,
|
|
color: '#666',
|
|
},
|
|
confirmBtn: {
|
|
backgroundColor: colors.primary,
|
|
paddingVertical: 10,
|
|
paddingHorizontal: 18,
|
|
borderRadius: 10,
|
|
},
|
|
confirmText: {
|
|
color: '#fff',
|
|
fontSize: 14,
|
|
fontWeight: '500',
|
|
},
|
|
});
|