Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disableHeight & disableWidth #54

Open
oliviertassinari opened this issue Sep 28, 2016 · 2 comments
Open

disableHeight & disableWidth #54

oliviertassinari opened this issue Sep 28, 2016 · 2 comments

Comments

@oliviertassinari
Copy link

oliviertassinari commented Sep 28, 2016

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
Copy link
Author

oliviertassinari commented Sep 28, 2016

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
Copy link
Author

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants