-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Add min/maxSize support for px values #47
Comments
I understand why that would be convenient in some cases but I don’t think it’s something I want to support- because it would require changing the public api in a non obvious way: This library doesn’t control its own outer dimensions, so it couldn’t prevent panels from expanding/contracting past a certain point as its own width/height changed. You should be able to accomplish this using |
Copying from #48 (comment) in case others see this issue. Here is an example of what I mean: const MIN_SIZE_IN_PIXELS = 100;
const [minSize, setMinSize] = useState(10);
useLayoutEffect(() => {
const panelGroup = document.querySelector('[data-panel-group-id="group"]');
const resizeHandles = document.querySelectorAll(
"[data-panel-resize-handle-id]"
);
const observer = new ResizeObserver(() => {
let height = panelGroup.offsetHeight;
resizeHandles.forEach((resizeHandle) => {
height -= resizeHandle.offsetHeight;
});
// Minimum size in pixels is a percentage of the PanelGroup's height,
// less the (fixed) height of the resize handles.
setMinSize((MIN_SIZE_IN_PIXELS / height) * 100);
});
observer.observe(panelGroup);
resizeHandles.forEach((resizeHandle) => {
observer.observe(resizeHandle);
});
return () => {
observer.disconnect();
};
}, []); |
Just thought of: if changing the api in a non obvious way is the issue, how hard would it be to support the css rules |
I think the problem with this is similar to the problem with external width/height props– either can change without So handling it fully would go from being something triggered only by pointer events to something that could be triggered by a lot of external things. I don't think I want to try to support that level of complexity 😄 |
I think I have a possible solution for the pixel-based constraints; see #176 ❤️ → ☕ givebrian.coffee |
Relates to issues #46, #47, #51, #78, #114, #128, #141 This PR adds a new prop (`units`) to `PanelGroup`. This prop defaults to "percentage" but can be set to "pixels" for static, pixel based layout constraints. This can be used to add enable pixel-based min/max and default size values, e.g.: ```tsx <PanelGroup direction="horizontal" units="pixels"> {/* Will be constrained to 100-200 pixels (assuming group is large enough to permit this) */} <Panel minSize={100} maxSize={200} /> <PanelResizeHandle /> <Panel /> <PanelResizeHandle /> <Panel /> </PanelGroup> ``` Imperative API methods are also able to work with either pixels or percentages now. They default to whatever units the group has been configured to use, but can be overridden with an additional, optional parameter, e.g. ```ts panelRef.resize(100, "pixels"); panelGroupRef.setLayout([25, 50, 25], "percentages"); // Works for getters too, e.g. const percentage = panelRef.getSize("percentages"); const pixels = panelRef.getSize("pixels"); const layout = panelGroupRef.getLayout("pixels"); ``` See the docs for more: [.../examples/pixel-based-layouts](https://react-resizable-panels-git-panelgroup-layout-val-2424f0-bvaughn.vercel.app/examples/pixel-based-layouts)
If your UI is designed to be reasonably sized within specific dimensions, having access to limit size with pixel values is essential.
Currently implementing with CSS values only works in 2-column/2-row setup,
Thanks for working on this component for all of us! <3
The text was updated successfully, but these errors were encountered: