import * as React from 'react'; import { ActivityIndicator, Pressable, TouchableOpacity, View, ViewStyle, } from 'react-native'; import { getColor } from './style-utils'; import Text from './text'; interface IconProps { icon: React.ReactNode; gap?: string | number; } interface BorderInterface { borderWidth: string; borderColor: string; } export type ButtonVariant = | 'primary' | 'primaryLow' | 'secondary' | 'secondaryLow' | 'outlined' | 'danger' | 'dangerLow'; interface ButtonPreset { backgroundColor: string; textColor: string; } const BUTTON_PRESETS: Record = { primary: { backgroundColor: 'emerald-500', textColor: 'white', }, primaryLow: { backgroundColor: 'rgba(16, 185, 129, 0.1)', textColor: 'emerald-500', }, secondary: { backgroundColor: 'gray-900', textColor: 'white', }, secondaryLow: { backgroundColor: 'gray-100', textColor: 'gray-900', }, outlined: { backgroundColor: 'white', textColor: 'gray-900', }, danger: { backgroundColor: 'red-500', textColor: 'white', }, dangerLow: { backgroundColor: 'rgba(239, 68, 68, 0.1)', textColor: 'red-500', }, }; interface ButtonProps { variant?: ButtonVariant; text?: string; textColor?: string; backgroundColor?: string; width?: string; height?: string; shape?: 'pill' | 'round'; radius?: string; loading?: boolean; disabled?: boolean; border?: BorderInterface; leftIcon?: IconProps; rightIcon?: IconProps; className?: string; style?: ViewStyle; onPress?: () => void; } export default function Button({ variant, loading = false, text = 'default', textColor, backgroundColor, width = 'w-full', height = 'h-[56px]', shape, radius = 'rounded-2xl', disabled = false, border = { borderWidth: '0', borderColor: 'transparent' }, onPress, leftIcon, rightIcon, className, style, }: ButtonProps) { const preset = variant ? BUTTON_PRESETS[variant] : null; const defaultStyles = { backgroundColor: preset?.backgroundColor || 'black', textColor: preset?.textColor || 'white', border: variant === 'outlined' ? { borderWidth: '1', borderColor: 'gray-300' } : { borderWidth: '0', borderColor: 'transparent' }, width: 'w-full', height: 'h-14', radius: shape === 'pill' ? 'rounded-full' : 'rounded-2xl', }; const finalStyles = { backgroundColor: backgroundColor || defaultStyles.backgroundColor, textColor: textColor || defaultStyles.textColor, border: variant === 'outlined' ? { borderWidth: '1', borderColor: 'gray-300' } : border || defaultStyles.border, width: width || defaultStyles.width, height: height || defaultStyles.height, radius: shape ? shape === 'pill' ? 'rounded-full' : 'rounded-2xl' : radius || defaultStyles.radius, }; const getMarginStyle = (gap?: string | number, isLeft: boolean = true) => { if (!gap) return {}; if (typeof gap === 'number') { return isLeft ? { marginRight: gap } : { marginLeft: gap }; } return { className: gap }; // string인 경우 className으로 반환 }; return ( {loading ? ( ) : ( {leftIcon && ( {leftIcon.icon} )} {/* {text} */} {text} {rightIcon && ( {rightIcon.icon} )} )} ); }