All files / molecule/field/src config.js

92.85% Statements 13/14
80% Branches 8/10
100% Functions 3/3
92.85% Lines 13/14

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        1x 1x 1x 1x 1x 1x 1x 1x     9x       9x     1x 9x           9x    
import {isElement} from 'react-is'
 
import AtomLabel from '@s-ui/react-atom-label'
 
export const BASE_CLASS = 'sui-MoleculeField'
export const CLASS_INLINE = `${BASE_CLASS}--inline`
export const CLASS_AUTO_HIDE = `${BASE_CLASS}--autohide`
export const CLASS_FULLWIDTH = `${BASE_CLASS}--fullWidth`
export const CLASS_INLINE_REVERSE = `${CLASS_INLINE}-reverse`
export const CLASS_NODE_LABEL_CONTAINER = `${BASE_CLASS}-nodeLabelContainer`
export const CLASS_INPUT_CONTAINER = `${BASE_CLASS}-inputContainer`
export const CLASS_LABEL_CONTAINER = `${BASE_CLASS}-labelContainer`
 
export function isDOMTypeElement(element) {
  return isElement(element) && typeof element.type === 'string'
}
 
export function isCompositeTypeElement(element) {
  return isElement(element) && typeof element.type === 'function'
}
 
export const getLabeled = element => {
  Iif (
    (isDOMTypeElement(element) && element.type === 'label') ||
    (isCompositeTypeElement(element) && element.type === AtomLabel)
  ) {
    return element
  }
  return <AtomLabel text={element} />
}