All files / atoms/MatchProgress/mobile MatchProgress.native.tsx

100% Statements 6/6
95.45% Branches 21/22
100% Functions 1/1
100% Lines 6/6

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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202              1x                   7x 7x   7x           7x   7x                                                                                                                                                                                                                                                                                                                                                          
import { FC } from 'react';
import { cn } from '@sb/libs';
import { Text, View } from 'react-native';
import { calculateMatchData } from '../utils';
import { useThemeColors } from '@sb/hooks/Utilities/useThemeColors';
import { MatchProgressNativeProps, MatchProgressVariant } from '../MatchProgress.types';
 
export const MatchProgress: FC<MatchProgressNativeProps> = ({
  id,
  style,
  className,
  matchData,
  homeLabel = 'Home',
  drawLabel = 'Draw',
  awayLabel = 'Away',
  variant = 'default',
}) => {
  const { themedColors } = useThemeColors();
  const { homeWidth, drawWidth, awayWidth } = calculateMatchData(matchData);
 
  const BAR_HEIGHT_MAP: Record<MatchProgressVariant, number> = {
    compact: 6,
    default: 8,
    detailed: 12,
  };
 
  const barHeight = BAR_HEIGHT_MAP[variant];
 
  return (
    <View
      style={style}
      testID={id}
      accessibilityLabel={id ?? 'Match Progress'}
      className={cn('elevation-10 w-full shadow-xl', className)}
    >
      <View
        className="items-center py-2"
        style={{
          backgroundColor: themedColors.colorTertiary,
        }}
      >
        <Text
          style={{
            color: themedColors.colorText_Main,
          }}
          className="font-Bold text-lg uppercase tracking-wide"
        >
          Siegwahrscheinlichkeit
        </Text>
      </View>
 
      <View
        style={{
          backgroundColor: themedColors.colorElement_Nuance_Color,
        }}
        className="px-6 pb-5 pt-2"
      >
        <View
          className={cn('relative h-16', {
            'h-8': variant === 'compact',
          })}
        >
          <View className="absolute left-0 top-1">
            <Text
              style={{
                color: themedColors.colorAccent,
              }}
              numberOfLines={1}
              className="text-base font-semibold uppercase"
              accessibilityLabel={`Home Opponent: ${homeLabel}`}
            >
              {homeLabel}
            </Text>
            {variant === 'compact' || (
              <Text
                testID="home-percentage"
                style={{
                  color: themedColors.colorAccent,
                }}
                accessibilityLabel={`Home Winning Percentage: ${Math.round(homeWidth)}%`}
                className={cn('text-2xl font-extrabold tracking-wide', {
                  'text-3xl': variant === 'detailed',
                })}
              >
                {Math.round(homeWidth)}%
              </Text>
            )}
          </View>
 
          <View
            accessible={true}
            accessibilityLabel={`Match Draw Percentage: ${Math.round(drawWidth)}%`}
            className="absolute top-8"
            style={{
              left: `${homeWidth + drawWidth / 2}%`,
              transform: [
                {
                  translateX: drawWidth <= 20 ? -(drawWidth / 2 + 10) : -(drawWidth / 2),
                },
              ],
            }}
          >
            {variant === 'compact' || (
              <Text
                testID="draw-percentage"
                style={{
                  color: themedColors.colorStatus_Closed,
                }}
                className={cn('text-2xl font-extrabold tracking-wide', {
                  'text-3xl': variant === 'detailed',
                })}
              >
                {Math.round(drawWidth)}%
              </Text>
            )}
          </View>
 
          <View
            accessible={true}
            accessibilityLabel={`Away Winning Percentage: ${Math.round(awayWidth)}`}
            className="absolute right-0 top-1 flex items-end"
          >
            <Text
              style={{
                color: themedColors.colorTertiary,
              }}
              className="text-base font-semibold uppercase"
            >
              {awayLabel}
            </Text>
            {variant === 'compact' || (
              <Text
                testID="away-percentage"
                style={{
                  color: themedColors.colorTertiary,
                }}
                accessibilityLabel="Away percentage"
                className={cn('text-2xl font-extrabold tracking-wide', {
                  'text-3xl': variant === 'detailed',
                })}
              >
                {Math.round(awayWidth)}%
              </Text>
            )}
          </View>
        </View>
 
        <View className="relative mt-2 overflow-hidden" style={{ height: barHeight }}>
          <View
            accessibilityLabel="Home Win Percentage"
            style={{
              width: `${homeWidth}%`,
              backgroundColor: themedColors.colorAccent,
            }}
            className="bg-accent absolute bottom-0 left-0 top-0"
          />
          <View
            accessibilityLabel="Tie Percentage"
            className="absolute top-[50%]"
            style={{
              left: `${homeWidth}%`,
              width: `${drawWidth}%`,
              backgroundColor: themedColors.colorSecondary,
              transform: [{ translateY: variant === 'compact' ? -1 : -2.5 }],
              height: variant === 'compact' ? 2 : variant === 'detailed' ? 6 : 4,
            }}
          />
          <View
            accessibilityLabel="Away Win Percentage"
            className="absolute bottom-0 top-0"
            style={{
              width: `${awayWidth}%`,
              left: `${homeWidth + drawWidth}%`,
              backgroundColor: themedColors.colorTertiary,
            }}
          />
        </View>
 
        <View className="relative mt-1 h-4">
          <Text
            accessibilityLabel={`Draw Label: ${drawLabel}`}
            className={cn('font-Bold absolute text-sm uppercase', {
              'text-base': variant === 'detailed',
            })}
            style={{
              left: `${homeWidth + drawWidth / 2}%`,
              color: themedColors.colorStatus_Closed,
              transform: [
                {
                  translateX: drawWidth <= 20 ? -(drawWidth / 2 + 5) : -(drawWidth / 2 - 5),
                },
              ],
            }}
          >
            {drawLabel}
          </Text>
        </View>
      </View>
    </View>
  );
};