digidem / react-dimensions

[Looking for maintainers]

Home Page:http://lab.digital-democracy.org/react-dimensions/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

disableHeight & disableWidth

oliviertassinari opened this issue · comments

Would be great to provide the same API than https://github.com/bvaughn/react-virtualized/blob/master/docs/AutoSizer.md#prop-types (Same implementation / different interface)

One of my use cases is doing the size measurement on a single direction.

FWIW, here is how I have reimplemented the same interface:

import React from 'react'
import recompose from 'recompose'
import AutoSize from 'react-virtualized/dist/commonjs/AutoSizer'

export default recompose.createHelper((options = {}) => (Component) => {
  const Dimensions = props => (
    <AutoSize {...options}>
      {(newProps) => {
        if (newProps.width === 0 && newProps.height === 0) {
          return null
        }

        const componentProps = { ...props }

        if (!options.disableHeight) {
          componentProps.containerHeight = newProps.height
        }

        if (!options.disableWidth) {
          componentProps.containerWidth = newProps.width
        }

        return <Component {...componentProps} />
      }}
    </AutoSize>
  )

  return Dimensions
}, 'dimensions')

@digidem Happy to see we go in the same direction:

capture d ecran 2018-12-16 a 11 41 31