All files / atom/checkbox/src config.js

100% Statements 47/47
95.91% Branches 47/49
100% Functions 7/7
100% Lines 42/42

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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80    1x 1x   1x           1x   1x 28x                     1x 103x 21x 82x 10x   72x     1x 75x 67x 62x 34x     1x 75x 69x 14x 55x 31x   24x     1x 75x 41x   34x 34x 27x 5x   22x     34x     1x 128x 64x   64x 64x 9x 9x   55x     32x  
import cx from 'classnames'
 
export const BASE_CLASS = 'sui-AtomCheckbox'
export const CLASS_ICON = 'sui-AtomCheckbox--Icon'
 
export const CHECKBOX_STATUS = {
  ERROR: 'error',
  SUCCESS: 'success',
  ALERT: 'alert'
}
 
export const CHECKBOX_SIZES = {SMALL: 'small', MEDIUM: 'medium'}
 
export const className = ({size, checked, disabled, indeterminate, className}) =>
  cx(
    CLASS_ICON,
    {
      [`${CLASS_ICON}--${size}`]: Object.values(CHECKBOX_SIZES).includes(size),
      'is-checked': checked,
      'is-disabled': disabled,
      'is-indeterminate': indeterminate
    },
    className
  )
 
export const pressedValue = ({checked, indeterminate}) => {
  if (checked) {
    return 'true'
  } else if (indeterminate) {
    return 'mixed'
  }
  return 'false'
}
 
export const getIsNative = ({checked, indeterminate}, {CheckedIcon, UncheckedIcon, IndeterminateIcon, Icon}) => {
  if (checked && !CheckedIcon && !Icon) return true
  else if (!checked && indeterminate && !IndeterminateIcon && !Icon) return true
  else if (!checked && !indeterminate && !UncheckedIcon && !Icon) return true
  return false
}
 
export const getReadOnly = ({readOnly, disabled, isNative}) => {
  if (disabled) return {}
  else if (readOnly && isNative) {
    return {readOnly: true}
  } else if (!isNative) {
    return {readOnly: true}
  }
  return {}
}
 
export const getIcon = ({isNative, checked, indeterminate}, {CheckedIcon, UncheckedIcon, IndeterminateIcon, Icon}) => {
  if (isNative) {
    return null
  }
  let ResultingIcon = Icon || CheckedIcon
  if (!checked) {
    if (indeterminate) {
      ResultingIcon = Icon || IndeterminateIcon
    } else {
      ResultingIcon = Icon || UncheckedIcon
    }
  }
  return ResultingIcon
}
 
export const updateStatus = (element, {isIndeterminate = false, isChecked = false}) => {
  if (!element) {
    return
  }
  const {indeterminate} = element
  if (isIndeterminate !== indeterminate) {
    element.indeterminate = isChecked ? false : isIndeterminate
    return
  }
  return undefined
}
 
export const isFunction = fn => typeof fn === 'function'