import React, { useContext } from 'react'; import { StyleSheet, TouchableOpacity, TouchableOpacityProps, } from 'react-native'; import { ApplicationContext, ComponentContext, MiniAppContext, } from '../Context'; import { Colors } from '../Consts'; import { Icon } from '../Icon'; import styles from './styles'; export interface IconButtonProps extends TouchableOpacityProps { /** * Represents the name or key of the icon to be displayed on the IconButton. * It is a required property. */ icon: string; /** * Optional. Defines the visual style of the IconButton. */ type?: 'primary' | 'tonal' | 'secondary' | 'danger' | 'outline' | 'disabled'; /** * Optional. Defines the size of the IconButton. */ size?: 'large' | 'small'; /** * Optional. Params auto tracking component. */ params?: any; } const IconButton: React.FC = ({ type = 'primary', icon, size, params, ...rest }) => { const { theme } = useContext(ApplicationContext); const context = useContext(MiniAppContext); const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false; /** * get size icon button */ const getSizeStyle = () => { if (size === 'small') { return styles.small; } return styles.large; }; /** * get style for icon button by type */ const getTypeStyle = () => { switch (type) { case 'disabled': return { backgroundColor: theme.colors.background.disable, }; case 'primary': return { backgroundColor: theme.colors.primary }; case 'secondary': return { backgroundColor: theme.colors.background.surface, borderWidth: 1, borderColor: theme.colors.border.default, }; case 'outline': return { backgroundColor: theme.colors.background.surface, borderWidth: 1, borderColor: theme.colors.primary, }; case 'tonal': return { backgroundColor: theme.colors.background.tonal, }; case 'danger': return { backgroundColor: theme.colors.error.primary, }; default: return { backgroundColor: theme.colors.primary }; } }; /** * get color for icon */ const getIconColor = () => { switch (type) { case 'disabled': return theme.colors.text.disable; case 'primary': return Colors.black_01; case 'danger': return Colors.black_01; case 'tonal': return theme.colors.primary; case 'secondary': return theme.colors.text.default; case 'outline': return theme.colors.primary; default: return Colors.black_01; } }; const activeOpacity = type === 'disabled' ? 0.75 : 0.5; const buttonStyle = StyleSheet.flatten([getTypeStyle(), getSizeStyle()]); const iconSize = size === 'small' ? 16 : 24; return ( ); }; export { IconButton };