All files / layout/grid/src index.js

85.71% Statements 6/7
57.14% Branches 4/7
50% Functions 1/2
100% Lines 6/6

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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185                                    1x                                                 5x                 5x                                                 1x   1x                                                                                                                                                                                     1x                            
import cx from 'classnames'
import PropTypes from 'prop-types'
 
import Injector from '@s-ui/react-primitive-injector'
import PolymorphicElement from '@s-ui/react-primitive-polymorphic-element'
 
import LayoutGridItem from './gridItem/index.js'
import {getGutterClassNames, transition} from './helpers.js'
import {
  ALIGN_CONTENT,
  ALIGN_ITEMS,
  BASE_CLASS,
  BREAKPOINTS,
  CELL_NUMBERS,
  GUTTER_VALUES,
  JUSTIFY_CONTENT
} from './settings.js'
 
const LayoutGrid = ({
  alignContent,
  alignItems,
  as = 'div',
  children,
  justifyContent,
  gutter,
  className,
  colSpan,
  l,
  lOffset,
  m,
  mOffset,
  s,
  sOffset,
  xl,
  xlOffset,
  xs,
  xsOffset,
  xxl,
  xxlOffset,
  xxs,
  xxsOffset,
  ...props
}) => {
  const classNames = cx(
    `${BASE_CLASS}`,
    Object.values(ALIGN_CONTENT).includes(alignContent) && `${BASE_CLASS}--ac-${alignContent}`,
    Object.values(ALIGN_ITEMS).includes(alignItems) && `${BASE_CLASS}--ai-${alignItems}`,
    Object.values(JUSTIFY_CONTENT).includes(justifyContent) && `${BASE_CLASS}--jc-${justifyContent}`,
    getGutterClassNames(gutter),
    className
  )
 
  return (
    <PolymorphicElement as={as} className={classNames} {...props}>
      <Injector
        colSpan={colSpan}
        l={l}
        lOffset={lOffset}
        m={m}
        mOffset={mOffset}
        s={s}
        sOffset={sOffset}
        xl={xl}
        xlOffset={xlOffset}
        xs={xs}
        xsOffset={xsOffset}
        xxl={xxl}
        xxlOffset={xxlOffset}
        xxs={xxs}
        xxsOffset={xxsOffset}
      >
        {children}
      </Injector>
    </PolymorphicElement>
  )
}
 
LayoutGrid.displayName = 'LayoutGrid'
 
LayoutGrid.propTypes = {
  as: PropTypes.elementType,
  /**
   * The content of the component.
   */
  children: PropTypes.node,
  /**
   * Sets the grid-line-self alignment. It's applied for all screen sizes.
   */
  alignContent: PropTypes.oneOf(Object.values(ALIGN_CONTENT)),
  /**
   * Sets the align-self value on all direct children as a group. It's applied for all screen sizes.
   */
  alignItems: PropTypes.oneOf(Object.values(ALIGN_ITEMS)),
  /**
   * Allows you to add extra styles and avoid extra DOM elements to style purposes.
   */
  className: PropTypes.string,
  /**
   * Distribute space between and around content items. It's applied for all screen sizes.
   */
  justifyContent: PropTypes.oneOf(Object.values(JUSTIFY_CONTENT)),
  /***
   * Spacing between cells.
   */
  gutter: PropTypes.oneOfType([
    PropTypes.oneOf(Object.values(GUTTER_VALUES)),
    PropTypes.objectOf(PropTypes.oneOf(Object.values(GUTTER_VALUES)))
  ]),
  /***
   * Defines the number of columns an item should span
   */
  colSpan: PropTypes.oneOfType([PropTypes.oneOf(CELL_NUMBERS), PropTypes.objectOf(PropTypes.oneOf(CELL_NUMBERS))]),
  /**
   * Number of cells the component has to fill. It's applied for the `l` breakpoint and wider screens.
   */
  l: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells offset to move component. It's applied for the `l` breakpoint and wider screens.
   */
  lOffset: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells the component has to fill. It's applied for the `m` breakpoint and wider screens.
   */
  m: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells offset to move component. It's applied for the `m` breakpoint and wider screens.
   */
  mOffset: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells the component has to fill. It's applied for the `s` breakpoint and wider screens.
   */
  s: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells offset to move component. It's applied for the `s` breakpoint and wider screens.
   */
  sOffset: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells the component has to fill. It's applied for the `xl` breakpoint and wider screens.
   */
  xl: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells offset to move component. It's applied for the `xl` breakpoint and wider screens.
   */
  xlOffset: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells the component has to fill. It's applied for the `xs` breakpoint and wider screens.
   */
  xs: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells offset to move component. It's applied for the `xs` breakpoint and wider screens.
   */
  xsOffset: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells the component has to fill. It's applied for the `xxl` breakpoint and wider screens.
   */
  xxl: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells offset to move component. It's applied for the `xxl` breakpoint and wider screens.
   */
  xxlOffset: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells the component has to fill. It's applied for the `xxs` breakpoint and wider screens.
   */
  xxs: PropTypes.oneOf(CELL_NUMBERS),
  /**
   * Number of cells offset to move component. It's applied for the `xxs` breakpoint and wider screens.
   */
  xxsOffset: PropTypes.oneOf(CELL_NUMBERS)
}
 
const DeprecatedLayoutGrid = props => <LayoutGrid {...transition(props)} />
 
export default LayoutGrid
 
export {
  DeprecatedLayoutGrid,
  LayoutGridItem,
  ALIGN_CONTENT as LayoutGridAlignContent,
  ALIGN_ITEMS as LayoutGridAlignItems,
  JUSTIFY_CONTENT as LayoutGridJustifyContent,
  GUTTER_VALUES as LayoutGridGutterValues,
  CELL_NUMBERS as LayoutGridCellNumbers,
  BREAKPOINTS as LayoutGridBreakpoints
}