All files / Button/css cssJSLogic.js

100% Statements 8/8
92.85% Branches 13/14
100% Functions 1/1
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      28x   28x   28x 28x   28x                       28x             28x               28x            
import { compileClassNames } from '@zohodesk/utils';
 
export default function cssJSLogic({ props, style }) {
  let { customClass, needAppearance, isBold, rounded, size, children, palette, status } = props;
 
  let { customButton = '', customStatus = '', customStatusSize = '' } = customClass;
 
  let paletteLower = palette.toLowerCase();
  let statusLower = status.toLowerCase();
 
  let buttonClass = compileClassNames({
    [customButton]: !!customButton,
    [style.bold]: isBold,
    [style.default]: !needAppearance,
    [style[paletteLower]]: needAppearance,
    [style.rounded]: needAppearance && rounded,
    [style[size.toLowerCase()]]: needAppearance && !children,
    [style[`${size}Btn`]]: needAppearance && children,
    [style[`${size}Btn${paletteLower}`]]: needAppearance && children && rounded,
    [style.loader]: !!needAppearance && statusLower !== 'none'
  });
 
  let loaderParentClass = compileClassNames({
    [customStatusSize]: !!customStatusSize,
    [style.loading]: statusLower === 'loading',
    [style[`${size}loading`]]: statusLower === 'loading',
    [style.success]: statusLower != 'loading'
  });
 
  let loaderChildClass = compileClassNames({
    [customStatus]: !!customStatus,
    [style.loadingelement]: statusLower === 'loading',
    [style[`${paletteLower}element`]]: statusLower === 'loading',
    [style.successelement]: statusLower != 'loading',
    [style[`${paletteLower}success`]]: statusLower != 'loading'
  });
 
  return {
    buttonClass,
    loaderParentClass,
    loaderChildClass
  };
}