import Icon, { IconName } from '@components/Icon' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { useState } from 'react' import { AccessibilityProps, Pressable, StyleProp, View, ViewStyle } from 'react-native' import { Loading } from './Loading' import CustomText from './Text' export type Props = { accessibilityLabel?: AccessibilityProps['accessibilityLabel'] accessibilityHint?: AccessibilityProps['accessibilityHint'] style?: StyleProp selected?: boolean loading?: boolean destructive?: boolean disabled?: boolean size?: 'S' | 'M' | 'L' fontBold?: boolean spacing?: 'XS' | 'S' | 'M' | 'L' round?: boolean overlay?: boolean onPress: () => void } & ({ type: 'icon'; content: IconName } | { type: 'text'; content: string }) const Button: React.FC = ({ accessibilityLabel, accessibilityHint, style: customStyle, type, content, selected, loading = false, destructive = false, disabled = false, size = 'M', fontBold = false, spacing = 'S', round = false, overlay = false, onPress }) => { const { colors } = useTheme() const loadingSpinkit = () => loading ? ( ) : null const mainColor = () => { if (selected) { return colors.blue } else if (overlay) { return colors.primaryOverlay } else if (disabled || loading) { return colors.disabled } else { if (destructive) { return colors.red } else { return colors.primaryDefault } } } const children = () => { switch (type) { case 'icon': return ( <> {loadingSpinkit()} ) case 'text': return ( <> {loadingSpinkit()} ) } } const [layoutHeight, setLayoutHeight] = useState() return ( setLayoutHeight(nativeEvent.layout.height) })} testID='base' onPress={onPress} children={children()} disabled={selected || disabled || loading} /> ) } export default Button