import { useState, type ReactNode } from "react";
import { Ionicons } from "@expo/vector-icons";
import {
Pressable,
Switch,
TextInput,
View,
type TextInputProps,
} from "react-native";
import { Text } from "@/components/ui/Text";
import { colors, fonts, radii } from "@/lib/theme";
type FieldProps = TextInputProps & {
label?: string;
icon?: keyof typeof Ionicons.glyphMap;
error?: string;
hint?: string;
secure?: boolean;
};
export function Field({
label,
icon,
error,
hint,
secure,
style,
...rest
}: FieldProps) {
const [focused, setFocused] = useState(false);
const [hidden, setHidden] = useState(!!secure);
const borderColor = error ? colors.danger : focused ? colors.brand : colors.line;
return (
{label ? (
{label}
) : null}
{icon ? (
) : null}
setFocused(true)}
onBlur={() => setFocused(false)}
style={[
{
flex: 1,
fontFamily: fonts.regular,
fontSize: 14,
color: colors.ink,
paddingVertical: 0,
},
style,
]}
{...rest}
/>
{secure ? (
setHidden(!hidden)} hitSlop={8}>
) : null}
{error ? (
{error}
) : hint ? (
{hint}
) : null}
);
}
export function SwitchRow({
title,
subtitle,
value,
onValueChange,
icon,
last,
}: {
title: string;
subtitle?: string;
value: boolean;
onValueChange: (v: boolean) => void;
icon?: keyof typeof Ionicons.glyphMap;
last?: boolean;
}) {
return (
{icon ? (
) : null}
{title}
{subtitle ? (
{subtitle}
) : null}
);
}
/** Radio-style selectable row used for payment methods and addresses. */
export function OptionRow({
title,
subtitle,
selected,
onPress,
icon,
trailing,
last,
}: {
title: string;
subtitle?: string;
selected: boolean;
onPress: () => void;
icon?: keyof typeof Ionicons.glyphMap;
trailing?: ReactNode;
last?: boolean;
}) {
return (
{icon ? (
) : null}
{title}
{subtitle ? (
{subtitle}
) : null}
{trailing}
);
}