<sl-split-panel>
improvements
#1639
Replies: 11 comments
-
Snapping was designed to let the split panel snap at a handful of important points. What's the use case for having it snap at every 5%? That seems excessive and would likely be annoying for users. Can you show me an example of the API you'd like to see? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I just noticed tmux enforces a vertical step size of 1 line height, and a horizontal step size of 1 character. Its min sizes are the same, so there's another use case for discrete sizing if putting text in a split-panel. |
Beta Was this translation helpful? Give feedback.
-
This makes the API confusing, as users now have to wrestle with not one, but three attributes that all affect snapping. Since snap positions can be specified in pixels and/or percentages, it would probably be better to let users determine which points to snap to based on size, tolerance, and any other variables that are important to them.
Remember that split panels aren't designed to be a grid where only certain values are allowed. Users should be able to resize a split panel freely — snapping is just used to easily restore a convenient panel position (e.g. snapping to the center). If you really want to do this, maybe you can grab the size of the container and convert the desired percentages to pixels, then you'll be working completely in pixels for the snap points and the snap threshold. Of course, you'd have to recalculate those values if the component gets resized, but there's a component that can help with that. |
Beta Was this translation helpful? Give feedback.
-
Just 2, and they'd be mutually exclusive.
A third padding attribute would affect the range of valid points, rather than snapping behavior of those points. It would default to [0%, 100%]. There might be another solution. Instead of adding properties to handle every split-panel use case, why not expose a validation callback? That would give the developer full control of snapping behaviour:
Giving a user the power to freely resize a panel doesn't always lead to a better UX. For example, Konsole allows arbitrary resizing, but doesn't display partially hidden lines. That means content pops in/out of view when resizing the window. I prefer tmux's stepped resizing. |
Beta Was this translation helpful? Give feedback.
-
I'm interested in the idea of a callback. What if splitPanel.snap = (details) => {
const { positionInPixels, positionInPercentage } = details;
// custom logic here
return positionToSnapTo;
}; Not sure if this would work without diving back into the source, but it feels like this might be a way to keep the API simple while accommodating more advanced use cases. |
Beta Was this translation helpful? Give feedback.
-
That would solve my use case. If the details includes width and percentage, I can calculate new position in px from a percentage and snap to it. |
Beta Was this translation helpful? Give feedback.
-
Is this something I should write and make a pull request for? |
Beta Was this translation helpful? Give feedback.
-
You can if you want. I probably won't get to it anytime soon. I'd love to keep the logic as simple as possible, though. |
Beta Was this translation helpful? Give feedback.
-
Hey @claviska, I'd like to contribute an implementation for this. I've implemented the behaviour where you can specify a string or a function for |
Beta Was this translation helpful? Give feedback.
-
Following up on my post earlier this year, I've created a PR (#2340) for these features. It extends |
Beta Was this translation helpful? Give feedback.
-
I replaced an in-house split-panel with the Shoelace one. It works well, but could use some minor ergonomic improvements.
Discrete snapping requires specifying every snap point. When points are close together, the panel snaps to
position=100
unless lowering the snap threshhold to match. The threshold only accepts pixels, not percents, which may lead to edge cases with nested split-panels.A small enough threshold breaks snapping when restricting to a windowed range of snap points. For example, 5%-95% doesn't snap from outside the range due to the low snap threshold.
It also warns about its touch listener.
Maybe the API should have a 'discrete' mode with a step size?
Beta Was this translation helpful? Give feedback.
All reactions