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

100% Statements 17/17
68.42% Branches 26/38
100% Functions 4/4
100% Lines 17/17

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                              10x   10x           10x           10x           10x           10x           10x 9x   9x                         9x                                         10x 28x   9x   9x   10x       10x                 28x                                                                            
import { cn } from '@sb/libs/utils';
import { colors } from '@sb/styles/colors';
import { Fragment, ReactNode } from 'react';
import { Platform, Text, View } from 'react-native';
import { useThemeColors } from '@sb/hooks/Utilities/useThemeColors';
import { ChainedStatusNativeProps, Status } from '../ChainedStatus.types';
 
export function ChainedStatus({
  id,
  items,
  size = 'default',
  variant = 'square',
  direction = 'right',
  connectorColor = colors.light.colorStatus_Warning,
}: ChainedStatusNativeProps) {
  const { themedColors } = useThemeColors();
 
  const SIZE_MAP = {
    small: 'size-8',
    default: 'size-10',
    large: 'size-12',
  };
 
  const WIDTH_MAP = {
    small: 'w-3',
    default: 'w-5',
    large: 'w-7',
  };
 
  const HEIGHT_MAP = {
    small: 'h-0.5',
    default: 'h-1',
    large: 'h-1',
  };
 
  const FONT_SIZE_MAP = {
    small: 'text-base',
    default: 'text-lg',
    large: 'text-xl',
  };
 
  const CHEVRON_MAP = {
    small: 'text-3xl',
    default: 'text-4xl',
    large: 'text-4xl',
  };
 
  const RenderChevron = (): ReactNode => {
    const isLeft = direction === 'left';
 
    const ChevronClasses = cn(`absolute font-semibold`, CHEVRON_MAP[size], {
      'font-Bold': Platform.OS === 'android',
      '-top-2 text-6xl right-2':
        Platform.OS === 'android' && size === 'large' && direction === 'right',
      '-top-2 text-6xl': Platform.OS === 'android' && size === 'large' && direction === 'left',
      '-top-1.5 text-5xl right-1.5':
        Platform.OS === 'android' && size === 'default' && direction === 'right',
      '-top-1.5 text-5xl': Platform.OS === 'android' && size === 'default' && direction === 'left',
      '-top-2 text-4xl right-1':
        Platform.OS === 'android' && size === 'small' && direction === 'right',
      '-top-2 text-4xl': Platform.OS === 'android' && size === 'small' && direction === 'left',
    });
 
    return (
      <View
        className={cn('flex flex-col justify-center', SIZE_MAP[size], {
          'top-0.5': Platform.OS === 'ios' && size !== 'small' && !isLeft,
          'left-1.5 items-end': isLeft,
          'right-1 items-start': !isLeft,
        })}
      >
        <Text
          className={ChevronClasses}
          style={{
            color: connectorColor,
          }}
          accessibilityLabel={isLeft ? 'ChevronLeft' : 'ChevronRight'}
        >
          {isLeft ? '←' : '→'}
        </Text>
      </View>
    );
  };
 
  const getBackgroundColor = (status: Status): string => {
    switch (status) {
      case 'N':
        return themedColors.colorStatus_Error;
      case 'U':
        return themedColors.colorStatus_Warning;
      case 'S':
        return themedColors.colorStatus_Success;
    }
  };
 
  return (
    <View
      testID={id}
      accessibilityRole="list"
      accessibilityLabel={`${id} Chained status`}
      className="relative flex flex-row items-center justify-center"
    >
      {direction === 'left' && <RenderChevron />}
      {items.map((item, index) => (
        <Fragment key={index}>
          <View
            style={{
              backgroundColor: getBackgroundColor(item.status),
            }}
            accessibilityLabel={`Chained Item Status ${item.label}: ${item.status}`}
            className={cn(
              `flex items-center justify-center rounded-sm`,
              {
                'rounded-full': variant === 'circle',
              },
              SIZE_MAP[size]
            )}
          >
            <Text
              style={{
                color: themedColors.colorText_Main,
              }}
              className={cn('font-Bold', FONT_SIZE_MAP[size])}
            >
              {item.label}
            </Text>
          </View>
          {index < items.length - 1 && (
            <View
              testID={`connector-${index}`}
              style={{
                backgroundColor: connectorColor,
              }}
              className={cn(WIDTH_MAP[size], HEIGHT_MAP[size])}
            />
          )}
        </Fragment>
      ))}
      {direction === 'right' && <RenderChevron />}
    </View>
  );
}