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

100% Statements 32/32
95.45% Branches 21/22
100% Functions 5/5
100% Lines 32/32

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              1x           8x   8x 8x   3x   1x   1x   1x   1x     1x       8x 8x 1x   7x     8x 8x   1x   1x     6x       8x 8x   8x   3x                               1x                               1x                               1x                               1x                                 1x       8x 8x   8x                       1x                  
import React from 'react';
import { StyleSheet, View } from 'react-native';
import Svg, { Circle, Path } from 'react-native-svg';
import type { CheckBoxStatusProps } from '../CheckBoxStatus.types';
import { colors } from '@sb/styles/colors';
import { useTheme } from '../../../Themes/ThemeProvider';
 
const CheckBoxStatus: React.FC<CheckBoxStatusProps> = ({
  id,
  status,
  size = 'medium',
  strokeColor,
}) => {
  const { theme } = useTheme();
 
  const getBgColor = (checkStatus: CheckBoxStatusProps['status']): string => {
    switch (checkStatus) {
      case 'completed':
        return colors[theme].checkboxStatusComplete;
      case 'active':
        return colors[theme].checkboxStatusActive;
      case 'error':
        return colors[theme].checkboxStatusError;
      case 'pending':
        return colors[theme].checkboxStatusPending;
      case 'neutral':
        return colors[theme].checkboxStatusNeutral;
      case 'custom':
      default:
        return colors[theme].colorCyan;
    }
  };
 
  const getStrokeColor = (): string => {
    if (strokeColor) {
      return strokeColor;
    }
    return colors[theme].colorLoader_Text;
  };
 
  const getSizePx = (sizeValue: CheckBoxStatusProps['size'] = 'medium'): number => {
    switch (sizeValue) {
      case 'small':
        return 16;
      case 'large':
        return 32;
      case 'medium':
      default:
        return 24;
    }
  };
 
  const getStatusIcon = (checkStatus: CheckBoxStatusProps['status'], dimension: number) => {
    const iconStrokeColor = getStrokeColor();
 
    switch (checkStatus) {
      case 'completed':
        return (
          <Svg
            testID="status-icon"
            width={dimension}
            height={dimension}
            viewBox="0 0 24 24"
            stroke={iconStrokeColor}
            strokeWidth={2}
            fill="none"
            strokeLinecap="round"
            strokeLinejoin="round"
          >
            <Path d="M5 13l4 4L19 7" />
          </Svg>
        );
      case 'active':
        return (
          <Svg
            testID="status-icon"
            width={dimension}
            height={dimension}
            viewBox="0 0 24 24"
            stroke={iconStrokeColor}
            strokeWidth={2}
            fill="none"
            strokeLinecap="round"
            strokeLinejoin="round"
          >
            <Circle cx="12" cy="12" r="5" />
          </Svg>
        );
      case 'error':
        return (
          <Svg
            testID="status-icon"
            width={dimension}
            height={dimension}
            viewBox="0 0 24 24"
            stroke={iconStrokeColor}
            strokeWidth={2}
            fill="none"
            strokeLinecap="round"
            strokeLinejoin="round"
          >
            <Path d="M6 6l12 12M6 18l12-12" />
          </Svg>
        );
      case 'pending':
        return (
          <Svg
            testID="status-icon"
            width={dimension}
            height={dimension}
            viewBox="0 0 24 24"
            stroke={iconStrokeColor}
            strokeWidth={2}
            fill="none"
            strokeLinecap="round"
            strokeLinejoin="round"
          >
            <Path d="M9.46 9.36c0-1.64 1.42-2.96 3.17-2.96 1.75 0 3.17 1.32 3.17 2.96 0 1.12-.6 1.96-1.64 2.6-.8.52-1.3 1.08-1.3 2.04v.74M12 17.6h.01" />
          </Svg>
        );
      case 'neutral':
        return (
          <Svg
            testID="status-icon"
            width={dimension}
            height={dimension}
            viewBox="0 0 24 24"
            stroke={iconStrokeColor}
            strokeWidth={2}
            fill="none"
            strokeLinecap="round"
            strokeLinejoin="round"
          >
            <Path d="M5 12h14" />
          </Svg>
        );
      case 'custom':
      default:
        return null;
    }
  };
 
  const dimension = getSizePx(size);
  const bgColor = getBgColor(status);
 
  return (
    <View
      testID={id}
      accessibilityRole="image"
      accessibilityLabel={status}
      style={[styles.container, { width: dimension, height: dimension, backgroundColor: bgColor }]}
    >
      {getStatusIcon(status, dimension)}
    </View>
  );
};
 
const styles = StyleSheet.create({
  container: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
 
export default CheckBoxStatus;