All files index.js

27.27% Statements 3/11
0% Branches 0/4
33.33% Functions 1/3
27.27% Lines 3/11
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        1x 4x         1x                                                            
import React from 'react'
import PropTypes from 'prop-types'
import { compose, defaultProps, withHandlers } from 'recompose'
 
const ScrollInto = ({children, scrollIntoView, style, className}) => (
  <div style={style} className={className} onClick={scrollIntoView}>
    {children}
  </div>
)
 
ScrollInto.propTypes = {
  selector: PropTypes.string.isRequired,
  smooth: PropTypes.bool,
  style: PropTypes.object,
  alignToTop: PropTypes.bool,
  className: PropTypes.string,
}
 
export default compose(
  defaultProps({
    smooth: true,
    style: {},
    alignToTop: false,
    className: ''
  }),
  withHandlers({
    scrollIntoView: ({selector, smooth, alignToTop}) => _ => {
      const behavior = smooth ? 'smooth' : 'instant'
      const options = {behavior}
      // scroll to top
      if (alignToTop) {
        options.block = 'start'
        options.inline = 'nearest'
      }
 
      const el = document.querySelector(selector)
      el.scrollIntoView(options)
    }
  })
)(ScrollInto)