Splitview
Introduction
A Splitview is a collection of resizable horizontally or vertically stacked panels.
import {
ISplitviewPanelProps,
Orientation,
SplitviewReact,
SplitviewReadyEvent,
} from 'dockview';
const components = {
default: (props: ISplitviewPanelProps<{ title: string }>) => {
return <div style={{ padding: '20px' }}>{props.params.title}</div>;
},
};
export const SimpleSplitview = () => {
const onReady = (event: SplitviewReadyEvent) => {
event.api.addPanel({
id: 'panel_1',
component: 'default',
params: {
title: 'Panel 1',
},
});
event.api.addPanel({
id: 'panel_2',
component: 'default',
params: {
title: 'Panel 2',
},
});
event.api.addPanel({
id: 'panel_3',
component: 'default',
params: {
title: 'Panel 3',
},
});
};
return (
<SplitviewReact
components={components}
onReady={onReady}
orientation={Orientation.HORIZONTAL}
className="dockview-theme-abyss"
/>
);
};
SplitviewReact Component
You can create a Splitview through the use of the ReactSplitview
component.
import { ReactSplitview } from 'dockview';
Using the onReady
prop you can access to the component api
and add panels either through deserialization or the individual addition of panels.
className |
|
---|---|
components |
|
disableAutoResizing |
|
hideBorders |
|
onReady |
|
orientation |
|
proportionalLayout |
|
Splitview API
The Splitview API is exposed both at the onReady
event and on each panel through props.containerApi
.
Through this API you can control general features of the component and access all added panels.
const MyComponent = (props: ISplitviewPanelProps<{ title: string }>) => {
// props.containerApi...
return <div>{`My first panel has the title: ${props.params.title}`}</div>;
};
const onReady = (event: SplitviewReadyEvent) => {
// event.api...
};
height | Height of the component.
|
---|---|
length | The current number of panels.
|
maximumSize | The maximum size the component can reach where size is measured in the direction of orientation provided.
|
minimumSize | The minimum size the component can reach where size is measured in the direction of orientation provided.
|
onDidAddView | Invoked when a view is added.
|
onDidLayoutChange | Invoked whenever any aspect of the layout changes.
If listening to this event it may be worth debouncing ouputs.
|
onDidLayoutFromJSON | Invoked after a layout is loaded through the fromJSON method.
|
onDidRemoveView | Invoked when a view is removed.
|
orientation | The current orientation of the component.
|
panels | The list of current panels.
|
width | Width of the component.
|
addPanel | Add a new panel and return the created instance.
|
clear | Remove all panels and clear the component.
|
focus | Focus the component.
|
fromJSON | Deserialize a layout to built a splitivew.
|
getPanel | Get the reference to a panel given it's string id.
|
layout | Layout the panel with a width and height.
|
movePanel | Move a panel given it's current and desired index.
|
removePanel | Removes an existing panel and optionally provide a Sizing method
for the subsequent resize.
|
toJSON | Serialize a layout
|
updateOptions | Update configuratable options.
|
Splitview Panel API
The Splitview panel API is exposed on each panel containing actions and variables specific to that panel.
const MyComponent = (props: ISplitviewPanelProps<{ title: string }>) => {
// props.api...
return <div>{`My first panel has the title: ${props.params.title}`}</div>;
};
height | The panel height in pixels
|
---|---|
id | The id of the panel that would have been assigned when the panel was created
|
isActive | Whether the panel is the actively selected panel
|
isFocused | Whether the panel holds the current focus
|
isVisible | Whether the panel is visible
|
onDidActiveChange |
|
onDidConstraintsChange |
|
onDidDimensionsChange |
|
onDidFocusChange |
|
onDidVisibilityChange |
|
width | The panel width in pixels
|
setActive |
|
setConstraints |
|
setSize |
|
setVisible |
|
updateParameters |
|
Advanced Features
Listed below are some functionalities avalaible through both the panel and component APIs. The live demo shows examples of these in real-time.
Visibility
A panels visibility can be controlled and monitored through the following code.
A panel with visibility set to false
will remain as a part of the components list of panels but will not be rendered.
const disposable = props.api.onDidVisibilityChange(({ isVisible }) => {
//
});
api.setVisible(true);
Active
Only one panel in the splitview
can be the active panel at any one time.
Setting a panel as active will set all the others as inactive.
A focused panel is always the active panel but an active panel is not always focused.
const disposable = props.api.onDidActiveChange(({ isActive }) => {
//
});
api.setActive();
Contraints
When adding a panel you can specify pixel size contraints
event.api.addPanel({
id: 'panel_3',
component: 'default',
minimumSize: 100,
maximumSize: 1000,
});
These contraints can be updated throughout the lifecycle of the splitview
using the panel API
props.api.onDidConstraintsChange(({ maximumSize, minimumSize }) => {
//
});
api.setConstraints({
maximumSize: 200,
minimumSize: 400,
});