All files / molecules/Accordion/mobile/Components/Atoms ToggleIcon.tsx

100% Statements 8/8
93.75% Branches 15/16
100% Functions 2/2
100% Lines 8/8

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                    13x 13x   13x                     2x   2x             13x   13x 13x    
import { Ionicons } from '@expo/vector-icons';
import { StyleSheet, View } from 'react-native';
import { useAccordion } from '../Context/AccordionContext';
import { AccordionIconProps } from '../../../Accordion.types';
 
type ToggleIconProps = {
  id: string;
};
 
function ToggleIcon({ id }: ToggleIconProps) {
  const { isItemOpen, icon } = useAccordion();
  const hasCustomIcon = hasIcon(icon);
 
  return (
    <View style={styles.container}>
      {hasCustomIcon ? (
        <View className="flex-row">{isItemOpen(id) ? icon.activeIcon : icon.icon}</View>
      ) : (
        <Ionicons name={isItemOpen(id) ? 'chevron-up' : 'chevron-down'} size={24} color="white" />
      )}
    </View>
  );
}
 
ToggleIcon.displayName = 'ToggleIcon';
 
const styles = StyleSheet.create({
  container: {},
});
 
export { ToggleIcon };
 
function hasIcon(icon: AccordionIconProps) {
  const hasIcon: boolean = typeof icon.icon === 'undefined' || icon.icon === null ? false : true;
  const hasActiveIcon: boolean =
    typeof icon.activeIcon === 'undefined' || icon.activeIcon === null ? false : true;
  return hasIcon || hasActiveIcon;
}