drcmda / mauerwerk

⚒ A react-spring driven masonry-like grid with enter/exit and shared element transitions
MIT License
836 stars 55 forks source link

Controlled component #3

Open janbaykara opened 6 years ago

janbaykara commented 6 years ago

Is there a way to set the 'open' element by key as a prop, so Grid can be used as a controlled, stateless component? You could use this to, say, synchronise the open state with a router system.

<Grid
   {...props}
   openKey={1}
/>
drcmda commented 6 years ago

@janbaykara That would be easy to add. Do you think driving it by index (0..n) and undefined (all close) should be enough? Also, should children then receive the toggle function? I suppose no ...

janbaykara commented 6 years ago

@drcmda Driving it by index could work, sure, especially given that we're just providing arrays and key accessors ourselves. toggle in controlled mode wouldn't have an effect on the openIndex in any case, I suppose.

Could supply a console warning when calling toggle and openIndex is not undefined, but we'd need to reconcile situations where toggle is called when openIndex is undefined, and then the openIndex prop is set to a value - which you'd expect to override the internal state.

didiyakovleva commented 5 years ago

@drcmda Hey, what is the status of this? I am trying to synchronise the open state with a router and navigate to the grid with the cell expanded with key parsed from the url. Is it possible to trigger specific cell to be opened without click event? Thanks

drcmda commented 5 years ago

Could i interest you in making a PR? I'd guide you through the react-spring update as well.