import { cva, type VariantProps } from 'class-variance-authority'; import * as React from 'react'; import { Pressable, View } from 'react-native'; import { Text, TextClassContext } from '../ui/text'; import { cn } from '../../lib/utils'; import { LucideIcon } from 'lucide-react-native'; import { CircleSnail } from 'react-native-progress'; import { useTheme } from '@react-navigation/native'; const buttonVariants = cva( 'group flex items-center justify-center rounded-md web:ring-offset-background web:transition-colors web:focus-visible:outline-none web:focus-visible:ring-2 web:focus-visible:ring-ring web:focus-visible:ring-offset-2', { variants: { variant: { default: 'bg-primary web:hover:opacity-90 active:opacity-90', destructive: 'bg-destructive web:hover:opacity-90 active:opacity-90', outline: 'border border-input bg-background web:hover:bg-accent web:hover:text-accent-foreground active:bg-accent', secondary: 'bg-secondary web:hover:opacity-80 active:opacity-80', ghost: 'web:hover:bg-accent web:hover:text-accent-foreground active:bg-accent', link: 'web:underline-offset-4 web:hover:underline web:focus:underline', }, size: { default: 'h-10 px-4 py-2 native:h-12 native:px-5 native:py-3', sm: 'h-9 rounded-md px-3', lg: 'h-11 rounded-md px-8 native:h-14', icon: 'h-10 w-10', }, }, defaultVariants: { variant: 'default', size: 'default', }, }, ); const buttonTextVariants = cva( 'web:whitespace-nowrap text-sm native:text-base font-medium text-foreground web:transition-colors', { variants: { variant: { default: 'text-primary-foreground', destructive: 'text-destructive-foreground', outline: 'group-active:text-accent-foreground', secondary: 'text-secondary-foreground group-active:text-secondary-foreground', ghost: 'group-active:text-accent-foreground', link: 'text-primary group-active:underline', }, size: { default: '', sm: '', lg: 'native:text-lg', icon: '', }, }, defaultVariants: { variant: 'default', size: 'default', }, }, ); type ButtonProps = React.ComponentProps & VariantProps & { iconLeft?: React.ReactElement; iconRight?: React.ReactElement; isLoading?: boolean; text?: string; }; function Button({ ref, className, variant, size, children, iconLeft, iconRight, isLoading, text, ...props }: ButtonProps) { const theme = useTheme(); const loadColor = !variant || variant === 'default' ? theme.colors.background : theme.colors.primary; return ( {isLoading ? ( ) : iconLeft ? ( {React.cloneElement(iconLeft, { size: (iconLeft.props as any).size || 16, } as any)} ) : undefined} {text ? {text} : (children as React.ReactNode)} {iconRight ? ( {React.cloneElement(iconRight, { size: (iconRight.props as any).size || 16, } as any)} ) : undefined} ); } export { Button, buttonTextVariants, buttonVariants }; export type { ButtonProps };