@gfazioli/mantine-split-pane
A Mantine component that manages split panes allows users to divide and resize content areas within a layout efficiently
Installation
After installation import package styles at the root of your application:
You can import styles within a layer @layer mantine-split-pane
by importing @gfazioli/mantine-split-pane/styles.layer.css
file.
Usage
The main component for creating a Split pane is Split
, which accepts two or more children, Split.Pane
.
Below a very basic example with the main props:
Pane 1
Pane 2
By setting properties on the main component
Split
, these will be applied to all childSplit.Pane
components. However, you can also set specific properties for eachSplit.Pane
component, as shown below.
Pane
The Split.Pane
component is a child component of Split
and allows setting some props for panel management.
Pane 1
Pane 2
Multiple Panes
You can add as many panes as you want, and you can also set the minWidth
and maxWidth
props for each pane alogn with other props.
Pane 1
Pane 2
Pane 3
initialWidth={280} maxWidth={300}
Pane 4
Note well
Obviously, you cannot set the
minWidth
andmaxWidth
from theSplit
component, as these props are specific to each individualSplit.Pane
. As well as you cannot set theorientation
of theSplit.Pane
component, as this is specific to theSplit
component.
The below code won't work:
The below code won't work:
Inline
By default, each Split
is displayed using flex
, but in case you want to display the panels inline, you can use the inline
prop.
P 1
P 2
P 1
P 2
Initial and mix/max sizes
As mentioned above, you can set the initial size of the panes using the initialWidth
and initialHeight
props.
Obviously, the initialWidth
will be used for vertical panes, and the initialHeight
for horizontal panes.
Min and Max sizes
You can set the minimum and maximum size of the panes using the minWidth
and maxWidth
props.
Obviously, the minWidth
and maxWidth
will be used for vertical panes, and the minHeight
and maxHeight
for horizontal panes.
Pane 1
Pane 2
Reset with Double Click
You can reset the size of the panes by double-clicking on the separator.
Resize and then
Double Click →
Pane 2
Custom Double Click
You can also manage double click to swap two different dimensions in rotation. In the example below, double click changes the dimension by alternating the values of the initialWidth
property.
Swap
Double Click →
Pane 2
Pane grow
The grow
property is only accessible for Split.Pane
and enables the panel size to expand and occupy the available space. It is especially handy for establishing a dynamic layout or, as illustrated below, for crafting a layout with two centered panels.
P 1
P 2
Nested Split
Of course, you can also nest Split
components to create more complex layouts.
Pane 1
Pane 2
Pane 3
Nested Split with different props
Now you can appreciate the flexibility of the Split
component, which allows you to create complex layouts with different props for each Split
component.
Pane 1
Pane 2
Pane 3
Events
The Split.Pane component emits some events that you can use to manage the layout of your application.
You may want to use the onResizeStart
, onResize
, and onResizeEnd
events to manage the layout of your application.
Pane 1
Pane 2
Start: false
End:
Resizing:
Store the layout
You can store the layout of the panes and restore it later using the browser localStorage
or any other storage system.
Try to change the layout and refresh the page to see the layout restored.
Pane 1
Pane 2
Accessibility
You may also use the Keyboard to navigate through the panes. Use the Tab
key to navigate through the resizer and the Arrow keys to resize the panes. You may use ◀︎ ▶︎ for horizontal panes and ▼ ▲ for vertical panes.
By default, the Arrow
keys will resize the panes by 8
pixel, but you can change this value using the step
prop.
Keeping the SHIFT key pressed while using the Arrow
keys will resize the panes by 64
pixel, but you can change this value using the shiftStep
prop.
Pane 1
Pane 2
Pane 1
Pane 2
Note well
The
step
andshiftStep
props are accessible both for theSplit
andSplit.Pane
components. Obviously, thestep
andshiftStep
props of theSplit.Pane
component will override thestep
andshiftStep
props of theSplit
component.In the above example, the resizer between the Pane 1 and Pane 2 will resize the panes by
32
pixel, and the resizer between the Pane 2 and Pane 3 will resize the panes by16
pixel. TheSHIFT
key will resize the panes by256
pixel between the Pane 1 and Pane 2 and by128
pixel between the Pane 2 and Pane 3.