Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | 1x 1x 6x 6x 6x 2x 2x 6x 6x 6x 6x 6x | import React from 'react';
import { Pressable, Text, View } from 'react-native';
import { MatchTypes } from '@sb/types';
import { cn } from '@sb/libs';
import { useTheme } from '../../../Themes/ThemeProvider';
import {
AmericanFootball,
BasketballEmpty,
HandballEmpty,
Sport,
StarFill,
TennisEmpty,
UEFA,
} from '@sb/ui/components/atoms/Icons/mobile/Icons.native';
import { colors } from '@sb/styles/colors';
import { CountryFlag } from '@sb/ui/components/atoms/CountryFlag/mobile/CountryFlag.native';
export interface SportsCategoryItemProps {
category: MatchTypes;
isSelected?: boolean;
onSelect?: (category: MatchTypes | undefined) => void;
className?: string;
labelClassName?: string;
isFavorite?: boolean;
countryCode?: string;
leagueName?: string;
}
type IconComponent = typeof Sport;
const sportsIconComponentMap: Partial<Record<MatchTypes, IconComponent>> = {
Fußball: Sport,
Basketball: BasketballEmpty,
'American Football': AmericanFootball,
Tennis: TennisEmpty,
Handball: HandballEmpty,
Volleyball: Sport,
TableTennis: Sport,
IceHockey: Sport,
};
export const SportsCategoryItem: React.FC<SportsCategoryItemProps> = ({
category,
isSelected = false,
onSelect,
className,
labelClassName,
isFavorite = false,
countryCode,
leagueName,
}) => {
const { theme } = useTheme();
const themeColors = colors[theme];
const handlePress = () => {
const newVal = isSelected ? undefined : category;
onSelect?.(newVal);
};
const isCountryFlag = countryCode === 'eu';
return (
<Pressable
onPress={handlePress}
className={cn('mx-2 items-center pt-2', className)}
accessibilityLabel={`Select category ${category}${isFavorite ? ' favourite' : ''}${countryCode ? ` ${countryCode}` : ''}`}
testID={`sports-category-item-${category}`}
>
<View className="relative items-center justify-center" style={{ width: 44, height: 44 }}>
{/* Base sport icon */}
{(() => {
const IconComp = sportsIconComponentMap[category] ?? Sport;
Iif (!sportsIconComponentMap[category] && process.env.NODE_ENV !== 'production') {
console.warn(
`SportsCategoryItem: No icon mapped for category "${category}" – falling back to <Sport />.`
);
}
return (
<IconComp
color={isSelected ? themeColors.colorAccent : themeColors.colorIcon_Fill_Light}
height={24}
width={24}
/>
);
})()}
{/* Flag overlays lower-right of base icon */}
{countryCode ? (
<View className="absolute" style={{ bottom: 8, right: 0 }}>
{/* Background rectangle */}
<View
className="bg-secondary h-[22px] w-[26px]"
style={{ bottom: -6, right: -3 }}
></View>
{/* Foreground flag */}
<View style={{ position: 'absolute', top: 3, right: -1 }}>
{isCountryFlag ? (
<UEFA width={23} height={25} />
) : (
<CountryFlag countryCode={countryCode} size={22} />
)}
</View>
</View>
) : null}
{/* Favourite star overlays upper-right */}
{isFavorite ? (
<View className="absolute" style={{ top: 6, right: -10 }}>
{/* Background larger red star */}
<View style={{ position: 'absolute', top: 2, right: 2, transform: [{ scale: 1.2 }] }}>
<StarFill color={themeColors.colorSecondary} />
</View>
{/* Foreground accent star */}
<View style={{ position: 'absolute', top: 1, right: 2 }}>
<StarFill color={themeColors.colorAccent} />
</View>
</View>
) : null}
</View>
{category && !leagueName ? (
<Text
className={cn(
'mt-1 text-center text-[14px] font-normal',
isSelected ? 'text-accent font-Bold' : 'text-text-main font-normal',
labelClassName
)}
>
{category}
</Text>
) : (
<Text
className={cn(
'mt-1 text-center text-[14px] font-normal',
isSelected ? 'text-accent font-Bold' : 'text-text-main font-normal'
)}
>
{leagueName}
</Text>
)}
</Pressable>
);
};
export default SportsCategoryItem;
|