All files / src/components/Pill index.tsx

57.14% Statements 4/7
50% Branches 5/10
66.66% Functions 2/3
57.14% Lines 4/7

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                              1x   1x                             1x 1x                          
import { IconButton } from '@mui/material';
import React from 'react';
import Icon from '../Icon/Icon';
import './styles.scss';
 
type PillProps<IdType> = {
  id: IdType;
  label?: string;
  value: string;
  onClick?: (id: IdType) => void;
  onRemove?: (id: IdType) => void;
  className?: string;
};
 
export default function Pill<IdType>(props: PillProps<IdType>): JSX.Element {
  const { id, label, value, onClick, onRemove, className } = props;
 
  return (
    <div
      className={`pill ${className ?? ''}`}
      onClick={(ev) => {
        ev.stopPropagation();
        if (onClick) {
          onClick(id);
        }
      }}
    >
      {label && <p className='label'>{label}:</p>}
      <p className={`value${label ? '' : ' value--no-label'}`}>{value}</p>
      {onRemove ? (
        <IconButton
          onClick={(ev) => {
            ev.stopPropagation();
            onRemove(id);
          }}
          className='iconContainer'
          aria-label='remove'
        >
          <Icon name='close' className='icon' />
        </IconButton>
      ) : (
        <div className='spacer' />
      )}
    </div>
  );
}