All files / molecules/Accordion/mobile Accordion.native.tsx

100% Statements 8/8
100% Branches 6/6
100% Functions 3/3
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                      46x           46x 95x 80x   15x     46x                       95x                             3x  
import { AccordionProvider } from './Components/Context/AccordionContext';
import type { AccordionNativeProps } from '../Accordion.types';
import AccordionLayout from './Components/Molecules/AccordionLayout';
import { ReactNode } from 'react';
 
export function Accordion({
  variant = 'primary',
  multiple = false,
  headerPosition = 'top',
  headerClassName,
  flush = false,
  items,
  icon,
  activeIcon,
  iconPosition,
  disabled,
  defaultOpenIndex,
  onChange,
}: AccordionNativeProps) {
  const iconState = {
    icon,
    activeIcon,
    iconPosition,
  };
 
  const fallbackLabel = (label: string | ReactNode) => {
    if (typeof label === 'string') {
      return label;
    }
    return 'Accordion';
  };
 
  return (
    <AccordionProvider
      iconState={iconState}
      multiple={multiple}
      variant={variant}
      headerPosition={headerPosition}
      flush={flush}
      disabled={disabled}
      defaultOpenIndex={defaultOpenIndex}
      onChange={onChange}
    >
      {items.map((item, idx) => (
        <AccordionLayout
          key={fallbackLabel(item.label) + idx}
          id={`item-${idx}`}
          headerClassName={headerClassName}
          contentClassName={item.className}
          headerLabel={item.label}
          headerContent={item.header}
          content={item.content}
          footer={item.footer}
        />
      ))}
    </AccordionProvider>
  );
}
 
Accordion.displayName = 'Accordion';