-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Set min height and width in px #33
Comments
Hi @Nico-Mayer! It will be very cool, but you need to implement correctly and carefully, and there are things that needed to be done before in my opinion. The coding should not be too hard, but need to make sure to handle all the cases in the code very carefully. |
BTW now I think that there should be two ways to specify the min/max/snap - by pixels or/and by percentages, simultaneously! I suggest to have them accept some types: export enum MultiSizePolicy {
MAX_OF,
MIN_OF
}
export interface MultiSize {
policy?: MultiSizePolicy,
px: number | undefined,
precentages: number | undefined
}
export type SizeSpecifier = number | string | MultiSize; The values of
The functions Unresolved Case: SSR on case
|
More about it: To support the pixels, there should be a function There is not a proper 'size recalculation' in this library, the one we have basically forgets about the size the end-user changed by moving the panes. This is why this feature is possible, but hard to achieve properly. |
Hi @Nico-Mayer, could you provide more details about the need to support pixel sizing rather than % sizing? In my apps, I usually need pixel sizing for static panes of the apps - this can be easily achieved with CSS. However, so far, I couldn't find a valid use case to support pixel sizing. |
The need is for responsivness. You can replace the navigation example with some "toolbox" like you have in GIMP on the side. |
Here is my thinking. FOR: I recall trying to implement a similar functionality not so long ago with @Tal500, we gave up. AGAINST: Summary: I see the functionality as a nice to have, not a must-have. Yet, I have no objection to accept a PR as long as it supports all existing use cases. |
So I've been thinking about this feature and how to best implement it.
Note the "auto" addition. Which would translate to: If it is a string: |
Also, reading the great specs above, I don't see a valid (real life) use case for the MultiSizePolicy policy. |
After some thinking, this feature is possible to implement, just need to be very careful and implement it slowly, I believe after the a11y feature (we might release both of these features in a fancy "v0.8" version) I believe that many flavors should be supported. For handling them as objects, I believe we shell introduce a special structure: interface DimensionVector {
prec?: number;
px?: number;
} This means we allow the dimension to be either on prec, px, or both. Of course, for handling this logic, the user advice to use library-exported helper functions, which we can picture as: export const dimensions: ({prec?: number, px?: number}) => DimensionVector;
export const prec: (amount: number) => DimensionVector;
export const px: (amount: number) => DimensionVector;
export const sum: (...dims: DimensionVector[]) => DimensionVector; So the user can initialize the sizes something like(a wild example): <script>
import { dimensions, prec, px, sum } from 'svelte-splitpanes';
</script>
<Splitpanes>
<Pane size={dimensions({prec: 10, px: 3})}></Pane>
<Pane size={prec(20)}></Pane>
<Pane size={px(15)}></Pane>
<Pane size={sum(prec(11), px(4))}></Pane>
</Splitpanes> If it's not looking good for beginners in your opinion, we can support a simple string expressions of something like |
I should also mention that the user should call a function like In modern browsers, there are some 'Observers' object we can use to track container size changes, but on older one, we can reply only on window resize event. The window resize event doesn't capture in-page size changing from dynamic content changes inside the page itself, so we must rely on the end-user to call this Observation I made just now: Imagine their is a sidebar in the page and the user is in modern browser, that have a smooth CSS transition when it's getting opened. When the client opens the sidebar, the splitpane will automatically stretch/shrink PX unit to %, but the updated will be for every JS frame, not every CSS frame. This might will be looked like a "lag" on size handling in Splitpane for the client, during the sidebar transition CSS animation. A possible solution to the observation: Have the user must call |
all good with report_container_resize(), trying to come up with the pseudo code |
Adding my support for this feature. For me the use case is, I have a small header for each panel. It would be great if the minimum size for the panels were the same as the header size, so maximising one panel would mean only the headers of the others show. It would also be great if the headers were also the splitter hitbox, but that's a separate request. Edit: by the way, thank you for putting together this package, such a great addition to the Svelte ecosystem. |
@Tal500 I do not understand the need for vectors such as '1px + 5%' or sum(prec(11), px(4)). What is the use case? this makes the logic more complex, see edge cases below. I am thinking HTML/CSS, and it doesn't have this capability. Let's try simple.. then we can make it feature perfect. <Splitpanes>
<Pane size="10px">header</Pane>
<Pane size="20%"></Pane>
<Pane size="auto">context</Pane>
<Pane size="15px">footer</Pane>
</Splitpanes> Besides, sticking to html/css conventions makes the learning curve easy. Edge cases I can think of:
<Splitpanes>
<Pane size="10px">header</Pane>
<Pane size="100px"></Pane>
<Pane size="10000px">context</Pane>
<Pane size="15px">footer</Pane>
</Splitpanes>
<Splitpanes>
<Pane size="25%">header</Pane>
<Pane size="100%">EXCEPTION</Pane>
<Pane size="25%">context</Pane>
<Pane size="25%">footer</Pane>
</Splitpanes>
<Splitpanes>
<Pane size="47%">EXCEPTION</Pane>
<Pane size="50%"></Pane>
<Pane size="auto">context</Pane>
<Pane size="10px">footer</Pane>
</Splitpanes> Actually, the more I think about exceptions, the more I realize... aren't we reimplementing HTML? |
I checked how Hoppscotch does it https://hoppscotch.io/. Hoppscotch is a REST client based on vue-splipanes. <div class="flex w-screen h-screen">
<Splitpanes class="no-splitter" :dbl-click-splitter="false" horizontal>
<Pane v-if="!zenMode" style="height: auto">
<AppHeader />
</Pane>
<Pane :class="spacerClass" class="flex flex-1 !overflow-auto md:mb-0">
<Splitpanes
class="no-splitter"
:dbl-click-splitter="false"
:horizontal="!mdAndLarger"
>
<Pane
style="width: auto; height: auto"
class="!overflow-auto hidden md:flex md:flex-col"
>
<AppSidenav />
</Pane>
<Pane class="flex flex-1 !overflow-auto">
<Splitpanes
class="no-splitter"
:dbl-click-splitter="false"
horizontal
>
<Pane class="flex flex-1 !overflow-auto">
<main class="flex flex-1 w-full" role="main">
<RouterView v-slot="{ Component }" class="flex flex-1">
<Transition name="fade" mode="out-in" appear>
<component :is="Component" />
</Transition>
</RouterView>
</main>
</Pane>
</Splitpanes>
</Pane>
</Splitpanes>
</Pane>
<Pane v-if="mdAndLarger" style="height: auto">
<AppFooter />
</Pane>
<Pane
v-else
style="height: auto"
class="!overflow-auto flex flex-col fixed inset-x-0 bottom-0 z-10"
>
<AppSidenav />
</Pane>
</Splitpanes>
</div> .no-splitter .splitpanes__splitter {
@apply relative;
@apply bg-primaryLight;
}
.no-splitter.splitpanes--vertical > .splitpanes__splitter {
@apply w-0.5;
@apply pointer-events-none;
}
.no-splitter.splitpanes--horizontal > .splitpanes__splitter {
@apply h-0.5;
@apply pointer-events-none;
} I must point that I use the same technique - https://orefalo.github.io/svelte-splitpanes/examples/styling/splitters-modern |
I can't see everything you sent for now, but in the meantime for understanding why I'm thinking this way, and why it's possible in HTML, see the CSS It is supported even by IE11, and way beyond in even earlier versions, by my last check on caniuseit. |
But you are not getting my functional concern... say, you have an toolbox with icon 10px by 10px.. the constraint would be '10px', fine i can see that (even if the above solution is much better) say, you want a splitter a 5% of the screen, constraint would be '5%', fine too. please find me a use case for '10px + 5%'... it makes no sense to me. |
I didn't suggest it to be a use case, I just want a uniform self transparent API, since I'm very sure that internally this is how this library should store the size. With this internal implementation detail that is taken as an axiom, I can see two reasons now:
|
@orefalo, in addition, for a user who would like a two way binding for the pane size(e.g. programmatic resizing), how do you suggest he should bind to the size value? By strings conversion it seems to be a waste. How can you keep the API clean in this use case? |
@orefalo, the last comment of mine about binding made me realize, maybe instead of some weird object as size, we need to have the additional postfixes of This way, we can make the
This way, the user can either use the string version, or specify numbers in The separation makes things more intuitive, and help the possible two-way binding to be simpler. |
Your last comment is getting closer to what could be a proper implementation. yet I believe you worry too much about optimizations, at the cost of spec simplicity. So let's step back for a second. What are the use cases for a splitter?
3 & 4 -> can be done in pure css. The rational here is that splitpane with not replace the richness of a div+css. it might be more convenient, but it's a trap. We already define the structure earlier in this thread - note the "auto", which we will likely need based on my assessment.
Are we getting any closer to each other? ;-) PS: I am very concerned about using calc and would rather stay away from it for compatibility reasons (unless there is a trick/optimization I don't see). |
The optimization is only the side effect, the real design issue is the limitation to strings, but there are more I'll try to say soon.
First, I do agree that 3&4 should be out of the scope of this library. About the design: I am not a great designer, but I am convinced that the optional px+% option for the advance user, will result in a great satisfaction for different screen sizes. Imagine a regular dynamic 2 panes with a splitter between them. The left pane is a side bar (list of files, or other toolbar) and the right one is the "main" one. The designer might want that the toolbar will have a base size of 20px(meaning, that the initial size will be not less then 20px on any device), and the fluid size(i.e. fraction spare size) will be 2%, so the rendered size of the left pane will be Additionally, I am planning to use the CSS
Yes, but you forgot one thing that I mentioned in the previous last comment of mine - two way binding (e.g. the "prog resize" example)!
See caniuseit of the CSS |
FYI for anyone else who comes across this— I was able to make it work in my use case with just a component like <script lang="ts">
import { Pane } from 'svelte-splitpanes';
let screenHeight: number | undefined;
let drawerHeaderHeight: number | undefined;
$: minSize =
drawerHeaderHeight != undefined && screenHeight != undefined
? (drawerHeaderHeight / screenHeight) * 100
: 1;
</script>
<svelte:window bind:innerHeight={screenHeight} />
<Pane size={20} snapSize={10} maxSize={90} {minSize}>
<div bind:clientHeight={drawerHeaderHeight} class="flex">
<div>tab1</div>
<div>tab2</div>
<div>tab3</div>
</div>
<div>pane contents</div>
</Pane> |
Just as a quick workaround: <Pane class="min-w-300"></Pane>
<style>
.min-w-300 { min-width: 300px }
</style> This helped me for now. |
Hey, I think it would be cool to set the min height and width in px, could be useful in some cases where u want to use a custom element as the splitter :)
The text was updated successfully, but these errors were encountered: