import * as Haptics from "expo-haptics"; import React, { PropsWithChildren, ReactNode, useMemo } from "react"; import { Text, TouchableOpacity, View } from "react-native"; import { Loader } from "./Loader"; interface ButtonProps extends React.ComponentProps { onPress?: () => void; className?: string; textClassName?: string; disabled?: boolean; children?: string | ReactNode; loading?: boolean; color?: "purple" | "red" | "black"; iconRight?: ReactNode; iconLeft?: ReactNode; justify?: "center" | "between"; } export const Button: React.FC> = ({ onPress, className = "", textClassName = "", disabled = false, loading = false, color = "purple", iconRight, iconLeft, children, justify = "center", ...props }) => { const colorClasses = useMemo(() => { switch (color) { case "purple": return "bg-purple-600 active:bg-purple-700"; case "red": return "bg-red-600"; case "black": return "bg-neutral-900 border border-neutral-800"; } }, [color]); return ( { if (!loading && !disabled && onPress) { onPress(); Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); } }} disabled={disabled || loading} {...props} > {loading ? ( ) : ( {iconLeft ? iconLeft : } {children} {iconRight ? iconRight : } )} ); };