All files / components/ui/Button Button.tsx

84.61% Statements 11/13
71.42% Branches 5/7
100% Functions 2/2
84.61% Lines 11/13

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 331x 1x 1x   1x   1x 170x 170x 170x                   170x             170x         1x  
import {forwardRef} from 'react';
import styles from './Button.module.scss';
import cn from 'clsx';
import {ButtonProps} from '../../../types/types';
import {Link} from 'react-router-dom';
 
const Button = forwardRef<HTMLButtonElement, ButtonProps>(({link, size, id, type, children, color, classNames, ...props }, ref) => {
    const buttonClasses = cn(styles.button, type && styles[`button--${type}`], color && styles[`button--${color}`], classNames);
    const button = () => {
        Iif (link) {
            const href = props.href as string;
 
            return (
                <Link {...props} data-testid={id} to={href} className={buttonClasses}>
                    { children }
                </Link>
            );
        }
 
        return (
            <button {...props} ref={ref} id={id} data-testid={id} className={buttonClasses} data-size={size && size}>
                { children }
            </button>
        );
    };
 
    return (
        button()
    );
});
 
export default Button;