devbookhq / splitter

React component for building split views like in VS Code
https://usedevbook.com
MIT License
435 stars 29 forks source link

Add `onDidResize` callback #3

Closed martonlanga closed 3 years ago

martonlanga commented 3 years ago

Would be nice to have this in order to store the user's preferences.

Api could look something like this:

interface SplitProps {
  direction: SplitDirection;
  minWidth?: number; // In pixels.
  minHeight?: number; // In pixels.
  initialSizes?: number[]; // In percentage.
+ onSizesChanged?: (sizes: number[]) => void; // Called when sizes change
  gutterClassName?: string;
  draggerClassName?: string;
  children?: React.ReactNode;
}
mlejva commented 3 years ago

This is prepared on the develop branch as onDidResize: (gutterIdx: number, allSizes: number[]) => void prop.

There is one bug preventing the release though that causes Splitter's children to reset their width. It's explained here.

Right now, I don't have time to look into this but if you fix the problematic code I'm more than happy to accept the PR.

mlejva commented 3 years ago

Implemented in the v1.0.4. Check out an example here.