191 lines
3.6 KiB
TypeScript
191 lines
3.6 KiB
TypeScript
import React from "react";
|
|
import {
|
|
Pressable,
|
|
StyleSheet,
|
|
Switch,
|
|
Text,
|
|
View,
|
|
} from "react-native";
|
|
import { Ionicons } from "@expo/vector-icons";
|
|
import {
|
|
moderateScale,
|
|
scale,
|
|
verticalScale,
|
|
} from "react-native-size-matters";
|
|
|
|
import { Colors } from "@/theme";
|
|
|
|
interface ProfileMenuItemProps {
|
|
icon: keyof typeof Ionicons.glyphMap;
|
|
title: string;
|
|
subtitle?: string;
|
|
value?: string | number;
|
|
onPress?: () => void;
|
|
showArrow?: boolean;
|
|
isLast?: boolean;
|
|
isSwitch?: boolean;
|
|
switchValue?: boolean;
|
|
onSwitchChange?: (value: boolean) => void;
|
|
}
|
|
|
|
export default function ProfileMenuItem({
|
|
icon,
|
|
title,
|
|
subtitle,
|
|
value,
|
|
onPress,
|
|
showArrow = true,
|
|
isLast = false,
|
|
isSwitch = false,
|
|
switchValue = false,
|
|
onSwitchChange,
|
|
}: ProfileMenuItemProps) {
|
|
const handlePress = () => {
|
|
if (isSwitch && onSwitchChange) {
|
|
onSwitchChange(!switchValue);
|
|
} else if (onPress) {
|
|
onPress();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Pressable
|
|
accessibilityRole={isSwitch ? "switch" : "button"}
|
|
onPress={handlePress}
|
|
style={({ pressed }) => [
|
|
styles.container,
|
|
!isLast && styles.border,
|
|
pressed && !isSwitch && styles.pressed,
|
|
]}
|
|
>
|
|
<View style={styles.leftSection}>
|
|
<View style={styles.iconContainer}>
|
|
<Ionicons
|
|
name={icon}
|
|
size={moderateScale(18)}
|
|
color="#6B7280"
|
|
/>
|
|
</View>
|
|
|
|
<View style={styles.textContainer}>
|
|
<Text
|
|
numberOfLines={1}
|
|
style={styles.title}
|
|
>
|
|
{title}
|
|
</Text>
|
|
{!!subtitle && (
|
|
<Text
|
|
numberOfLines={1}
|
|
style={styles.subtitle}
|
|
>
|
|
{subtitle}
|
|
</Text>
|
|
)}
|
|
</View>
|
|
</View>
|
|
|
|
<View style={styles.rightSection}>
|
|
{value !== undefined && !isSwitch && (
|
|
<Text
|
|
numberOfLines={1}
|
|
style={styles.value}
|
|
>
|
|
{value}
|
|
</Text>
|
|
)}
|
|
|
|
{isSwitch ? (
|
|
<View style={{ pointerEvents: "none" }}>
|
|
<Switch
|
|
value={switchValue}
|
|
onValueChange={onSwitchChange}
|
|
trackColor={{ false: "#E2E8F0", true: Colors.primary }}
|
|
thumbColor="#FFFFFF"
|
|
/>
|
|
</View>
|
|
) : showArrow ? (
|
|
<Ionicons
|
|
name="chevron-forward"
|
|
size={moderateScale(18)}
|
|
color="#B8B8B8"
|
|
/>
|
|
) : null}
|
|
</View>
|
|
</Pressable>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
minHeight: verticalScale(54),
|
|
|
|
flexDirection: "row",
|
|
|
|
alignItems: "center",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
paddingHorizontal: scale(16),
|
|
|
|
backgroundColor: "#FFFFFF",
|
|
},
|
|
|
|
border: {
|
|
borderBottomWidth: 1,
|
|
borderBottomColor: "#F1F3F5",
|
|
},
|
|
|
|
leftSection: {
|
|
flex: 1,
|
|
|
|
flexDirection: "row",
|
|
|
|
alignItems: "center",
|
|
|
|
marginRight: scale(12),
|
|
},
|
|
|
|
iconContainer: {
|
|
width: scale(28),
|
|
|
|
justifyContent: "center",
|
|
|
|
alignItems: "center",
|
|
|
|
marginRight: scale(10),
|
|
},
|
|
|
|
textContainer: {
|
|
flex: 1,
|
|
justifyContent: "center",
|
|
},
|
|
|
|
title: {
|
|
fontSize: moderateScale(14),
|
|
fontWeight: "500",
|
|
color: Colors.text,
|
|
},
|
|
|
|
subtitle: {
|
|
fontSize: moderateScale(11),
|
|
color: "#94A3B8",
|
|
marginTop: verticalScale(2),
|
|
},
|
|
|
|
rightSection: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
},
|
|
|
|
value: {
|
|
marginRight: scale(6),
|
|
fontSize: moderateScale(13),
|
|
color: "#6B7280",
|
|
fontWeight: "500",
|
|
},
|
|
|
|
pressed: {
|
|
backgroundColor: "#F8F9FA",
|
|
},
|
|
}); |