Skip to content

Determine the largest 'count' a component can render given limited width

Notifications You must be signed in to change notification settings

ProductPlan/shrink-to-fit-width

Repository files navigation

You want to render some things but want to change how it displays based on available width. ShrinkToFitWidth will find the optimal way to utilize the available width:

Example gif

You provide a max width and a max count (how many things you would display given no width restriction). Then you show how to render your component for some particular count. It will try rendering your component with different values for count, but only paint the one that uses the most available width.

<ShrinkToFitWidth maxWidth={500} maxCount={numberOfThings}>
  {({ ref, count }) => (
    <YourComponent ref={ref} numToDisplay={count} />
  )}
</ShrinkToFitWidth>

If your component rerenders at a different width, the algorithm will automatically recompute the count. A change to the max width or the max count will also recompute the count.

To run tests:

yarn test

To open cypress and interact with the example and tests:

yarn run cypress open

About

Determine the largest 'count' a component can render given limited width

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published