digidem / react-dimensions

[Looking for maintainers]
http://lab.digital-democracy.org/react-dimensions/
450 stars 77 forks source link

disableHeight & disableWidth #54

Open oliviertassinari opened 8 years ago

oliviertassinari commented 8 years ago

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.

oliviertassinari commented 8 years ago

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')
oliviertassinari commented 5 years ago

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

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