Gridview
Gridview is a collection of nested splitviews and is the foundation for the Dockview component. Gridview serves a purpose when you want only the nested splitviews with no tabs and no headers.
Introduction
GridviewReact Component
import { ReactGridview } from 'dockview';
className |
|
---|---|
components |
|
disableAutoResizing |
|
hideBorders |
|
onReady |
|
orientation |
|
proportionalLayout |
|
Gridview API
const MyComponent = (props: IGridviewPanelProps<{ title: string }>) => {
// props.containerApi...
return <div>{`My first panel has the title: ${props.params.title}`}</div>;
};
const onReady = (event: GridviewReadyEvent) => {
// event.api...
};
height | Height of the component.
|
---|---|
maximumHeight | Maximum height of the component.
|
maximumWidth | Maximum width of the component.
|
minimumHeight | Minimum height of the component.
|
minimumWidth | Minimum width of the component.
|
onDidActivePanelChange | Invoked when the active panel changes. May be undefined if no panel is active.
|
onDidAddPanel | Invoked when a panel is added. May be called multiple times when moving panels.
|
onDidLayoutChange | Invoked when any layout change occures, an aggregation of many events.
|
onDidLayoutFromJSON | Invoked after a layout is deserialzied using the fromJSON method.
|
onDidRemovePanel | Invoked when a panel is removed. May be called multiple times when moving panels.
|
orientation | Current orientation. Can be changed after initialization.
|
panels | All panel objects.
|
width | Width of the component.
|
addPanel | Add a panel and return the created object.
|
clear | Reset the component back to an empty and default state.
|
focus | Focus the component. Will try to focus an active panel if one exists.
|
fromJSON | Create a component from a serialized object.
|
getPanel | Get a panel object given a string id. May return undefined .
|
layout | Force resize the component to an exact width and height. Read about auto-resizing before using.
|
movePanel | Move a panel in a particular direction relative to another panel.
|
removePanel | Remove a panel given the panel object.
|
toJSON | Create a serialized object of the current component.
|
Gridview Panel API
const MyComponent = (props: IGridviewPanelProps<{ 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 |
|
Resizing
Panel Resizing
You can set the size of a panel using props.api.setSize(...)
.
// it's mandatory to provide either a height or a width, providing both is optional
props.api.setSize({
height: 100,
width: 200,
});
You can update any constraints on the panel. All parameters are optional.
props.api.setConstraints({
minimumHeight: 100,
maximumHeight: 1000
minimumWidth: 100,
maximumWidth: 1000
});
You can hide a panel by setting it's visibility to false
. Hidden panels retain their size
at the point of being hidden, if made visible again they will try to resize to the remembered size.
props.api.setVisible(false);
Panels
Add Panel
Using the gridview API you can access the addPanel
method which returns an instance of the created panel.
The minimum method signature is:
const panel = api.addPanel({
id: 'my_unique_panel_id',
component: 'my_component',
});
where id
is the unique id of the panel and component
is the implenentation which
will be used to render the panel. You will have registered this using the components
prop of the GridviewReactComponent
component.
You can pass bounding constraints to limit the size of the panel.
const panel = api.addPanel({
id: 'my_unique_panel_id',
component: 'my_component',
minimumHeight: 100,
maximumHeight: 1000,
minimumWidth: 100,
maximumWidth: 1000,
});
You can pass a snap
parameter which will hide the panel when an attempt is made to move it beyond a minimum width or height if one exists.
const panel = api.addPanel({
id: 'my_unique_panel_id',
component: 'my_component',
minimumHeight: 100,
snap: true,
});
You can pass a priority
parameter which will keep the panel a certain priority when being resized. This is useful when you know you want this
panel to always take the first available or last available space. The default is LayoutPriority.Normal
which defers space allocations to the libraries discression.
const panel = api.addPanel({
id: 'my_unique_panel_id',
component: 'my_component',
minimumHeight: 100,
priority: LayoutPriority.High,
});
You can pass properties to the panel using the params
key.
You can update these properties through the panels api
object and its updateParameters
method.
const panel = api.addPanel({
id: 'my_unique_panel_id',
component: 'my_component',
params: {
myCustomKey: 'my_custom_value',
},
});
panel.api.updateParameters({
myCustomKey: 'my_custom_value',
myOtherCustomKey: 'my_other_custom_key',
});
Note
updateParameters
does not accept partial parameter updates, you should call it with the entire set of parameters you want the panel to receive.
Finally addPanel
accepts a position
object which tells dockview where to place the panel.
- This object accepts a
referencePanel
which can be the associated id as a string or the panel object reference. - This object accepts a
direction
property which dictates where, relative to the provided reference the new panel will be placed.
If a
referencePanel
is not passed then thedirection
will be treated as absolute.
If no
direction
is provided the library will place the new panel in a pre-determined position.
const panel = api.addPanel({
id: 'panel_1',
component: 'default',
});
const panel2 = api.addPanel({
id: 'panel_2',
component: 'default',
position: {
referencePanel: panel1,
direction: 'right',
},
});
Note
updateParameters
does not accept partial parameter updates, you should call it with the entire set of parameters you want the panel to receive.
Theme
As well as importing the dockview
stylesheet you must provide a class-based theme somewhere in your application. For example.
// Providing a theme directly through the DockviewReact component props
<GridviewReact className="dockview-theme-dark" />
// Providing a theme somewhere in the DOM tree
<div className="dockview-theme-dark">
<div>
{/**... */}
<GridviewReact />
</div>
</div>
You can find more details on theming here.
Events
GridviewReact
exposes a number of events that the developer can listen to and below is a simple example with a log panel showing those events that occur.