All files / atom/panel/src ImagePanel.js

100% Statements 4/4
100% Branches 3/3
100% Functions 1/1
100% Lines 4/4

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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101                                1x                                           8x                                                       1x   1x                                                                
import {forwardRef} from 'react'
import PropTypes from 'prop-types'
 
import PolymorphicElement from '@s-ui/react-primitive-polymorphic-element'
 
import {
  BORDER_RADIUS,
  ELEVATION,
  HORIZONTAL_ALIGNMENTS,
  VERTICAL_ALIGNMENTS,
  DEFAULT_VERTICAL_ALIGNMENT,
  DEFAULT_HORIZONTAL_ALIGNMENT,
  getImageClassNames,
  getImageStyles
} from './settings.js'
 
const ImagePanel = forwardRef(
  (
    {
      as = 'div',
      id,
      src,
      verticalAlign = DEFAULT_VERTICAL_ALIGNMENT,
      horizontalAlign = DEFAULT_HORIZONTAL_ALIGNMENT,
      resized,
      overlayColor,
      overlayAlpha,
      color,
      rounded,
      elevation,
      isFullWidth,
      isFullHeight,
      children,
      className,
      ...props
    },
    forwardedRef
  ) => {
    return (
      <PolymorphicElement
        ref={forwardedRef}
        as={as}
        id={id}
        className={getImageClassNames({
          verticalAlign,
          horizontalAlign,
          resized,
          overlayColor,
          overlayAlpha,
          color,
          rounded,
          elevation,
          isFullWidth,
          isFullHeight,
          className,
          ...props
        })}
        style={getImageStyles({src, ...props})}
        {...props}
      >
        {children}
      </PolymorphicElement>
    )
  }
)
 
ImagePanel.displayName = 'ImagePanel'
 
ImagePanel.propTypes = {
  as: PropTypes.elementType,
  id: PropTypes.string,
  /**
   * Background image
   */
  src: PropTypes.string,
  children: PropTypes.node,
  isFullWidth: PropTypes.bool,
  isFullHeight: PropTypes.bool,
  /**
   * Background color while loading the image
   */
  color: PropTypes.string,
  resized: PropTypes.bool,
  /**
   * Background position x
   */
  horizontalAlign: PropTypes.oneOf(Object.values(HORIZONTAL_ALIGNMENTS)),
  overlayAlpha: PropTypes.string,
  overlayColor: PropTypes.string,
  /**
   * Background position y
   */
  verticalAlign: PropTypes.oneOf(Object.values(VERTICAL_ALIGNMENTS)),
  rounded: PropTypes.oneOf(Object.values(BORDER_RADIUS)),
  elevation: PropTypes.oneOf(Object.values(ELEVATION)),
  className: PropTypes.string
}
 
export default ImagePanel
export {HORIZONTAL_ALIGNMENTS, VERTICAL_ALIGNMENTS}