chakra-ui / ark

Ark UI is a headless UI library with over 45+ components designed to build scalable Design Systems that works for a wide range of JS frameworks.
https://ark-ui.com
MIT License
3.8k stars 109 forks source link

Splitter does not admit pixels as size #3070

Open EmyDallonses opened 1 day ago

EmyDallonses commented 1 day ago

Description

I'm trying to create a resizable sidebar using Splitter, and I need this sidebar to have a minimum size of 40px, so it will always have the same size when it's collapsed. I tried to resolve it calculating the percentage of the screen width when setting default sizes, like this:

const splitter = useSplitter({ defaultSize: [ { id: "sidebar", size: 20, minSize: (40 / width) * 100, maxSize: 25, } ], Constant width is the screen width and it changes every time the window resizes, but defaultSize won't update even if width is changing because it only runs once when the component mounts. I need to refresh the page for it to recalculate. I'm wondering if it's possible to also admit pixels as size.

Link to Reproduction (or Detailed Explanation)

https://codesandbox.io/p/devbox/zen-tess-jv2sdg?file=%2Fsrc%2FApp.tsx%3A19%2C20

Steps to Reproduce

  1. Create a Splitter component with two panels.
  2. Listen to window resize and save window width value in react state width.
  3. Set the default sizes like this: const splitter = useSplitter({ defaultSize: [ { id: "sidebar", size: 20, minSize: (40 / width) * 100, maxSize: 25, }, { id: "page", }, ],
  4. Collapse the sidebar to it's minimum size.
  5. Resize the window.

Ark UI Version

4.2.0

Framework

Browser

Google Chrome

Additional Information

No response