@@ -6,52 +6,88 @@ sidebar_position: 2
6
6
import { MultiFrameworkContainer } from ' @site/src/components/ui/container' ;
7
7
import CustomHeadersDockview from ' @site/sandboxes/customheader-dockview/src/app' ;
8
8
9
- ## Custom Tab Renderer
9
+ This section describes how to implement custom tab renderers
10
+
11
+ ## Register a Tab Component
12
+
13
+ <FrameworkSpecific framework = ' React' >
14
+ ``` jsx
15
+ < DockviewReact tabComponents= {{
16
+ tab_1 : (props : IDockviewPanelHeaderProps ) => {
17
+ const api: DockviewPanelApi = props .api ;
18
+ const containerApi: DockviewApi = props .containerApi ;
19
+
20
+ return < div> {/** logic */ }< / div>
21
+ },
22
+ tab_2 : (props : IDockviewPanelHeaderProps ) => {
23
+ return < div> {/** logic */ }< / div>
24
+ }
25
+ }}/ >
26
+ ```
27
+ </FrameworkSpecific >
10
28
11
- You can provide custom renderers for your tab headers for maximum customization.
12
- A default implementation of ` DockviewDefaultTab ` is provided should you only wish to attach minor
13
- changes and events that do not alter the default behaviour, for example to add a custom context menu event
14
- handler or to hide the close button.
29
+ <FrameworkSpecific framework = ' JavaScript' >
30
+ not implemented
31
+ </FrameworkSpecific >
15
32
16
- The ` DockviewDefaultTab ` component accepts a ` hideClose ` prop if you wish only to hide the close button.
17
33
18
- ``` tsx title="Attaching a custom context menu event handlers to a custom header"
19
- import { IDockviewPanelHeaderProps , DockviewDefaultTab } from ' dockview' ;
34
+ ## Default Tab Renderer
20
35
21
- const MyCustomheader = (props : IDockviewPanelHeaderProps ) => {
22
- const onContextMenu = (event : React .MouseEvent ) => {
23
- event .preventDefault ();
24
- alert (' context menu' );
25
- };
26
- return <DockviewDefaultTab onContextMenu = { onContextMenu } hideClose = { true } { ... props } />;
27
- };
36
+ <FrameworkSpecific framework = ' React' >
37
+ ``` jsx
38
+ const MyTab = (props : IDockviewPanelHeaderProps ) => {
39
+ const api: DockviewPanelApi = props .api ;
40
+ const containerApi: DockviewApi = props .containerApi ;
41
+
42
+ return < div> {/** logic */ }< / div>
43
+ }
44
+
45
+ return < DockviewReact defaultTabRenderer= {MyTab}/ >
28
46
```
47
+ </FrameworkSpecific >
29
48
30
- You are also free to define a custom renderer entirely from scratch and not make use of the ` DockviewDefaultTab ` component.
31
- To use a custom renderer you can must register a collection of tab components.
49
+ <FrameworkSpecific framework = ' JavaScript' >
50
+ not implemented
51
+ </FrameworkSpecific >
32
52
33
- ``` tsx
34
- const tabComponents = {
35
- myCustomHeader: MyCustomHeader ,
36
- };
53
+ ## Accessing Custom Panel Parameters
37
54
38
- return < DockviewReact tabComponents = { tabComponents } ... />;
39
- ```
55
+ You can provide a generic type that matches the structure of the epxected custom panels parameters
56
+ to provide type-hints for the panel parameters which can be accessed via the ` params ` option.
40
57
41
- ``` tsx
42
- api .addPanel ({
43
- id: ' panel_1' ,
44
- component: ' default' ,
45
- tabComponent: ' myCustomHeader' , // <-- your registered renderers
46
- title: ' Panel 1' ,
47
- });
58
+ <FrameworkSpecific framework = ' React' >
59
+ ``` jsx
60
+ type MyParameters = { my_value: number };
61
+
62
+ const MyTab = (props : IDockviewPanelHeaderProps < MyParameters > ) => {
63
+ const value: number = props .params .my_value ;
64
+ return < div> {/** logic */ }< / div>
65
+ }
48
66
```
67
+ </FrameworkSpecific >
68
+
69
+
70
+ ## Extend the Default Tab Implementation
49
71
50
- You can also override the default tab renderer which will be used when no ` tabComponent ` is provided to the ` addPanel ` function.
72
+ If you only want to make minor changes to the tab rendering you may be able to use the
73
+ default implementation as a base. This could include:
74
+ - Hiding the close button
75
+ - Attaching additional event listeners
51
76
77
+
78
+ <FrameworkSpecific framework = ' React' >
52
79
``` tsx
53
- <DockviewReact defaultTabComponent = { MyCustomHeader } ... />;
80
+ import { IDockviewPanelHeaderProps , DockviewDefaultTab } from ' dockview' ;
81
+
82
+ const MyCustomTab = (props : IDockviewPanelHeaderProps ) => {
83
+ const onContextMenu = (event : React .MouseEvent ) => {
84
+ event .preventDefault ();
85
+ alert (' context menu' );
86
+ };
87
+ return <DockviewDefaultTab onContextMenu = { onContextMenu } hideClose = { true } { ... props } />;
88
+ };
54
89
```
90
+ </FrameworkSpecific >
55
91
56
92
As a simple example the below attaches a custom event handler for the context menu on all tabs as a default tab renderer
57
93
@@ -62,28 +98,3 @@ This still makes use of the `DockviewDefaultTab` since it's only a minor change.
62
98
sandboxId = " customheader-dockview"
63
99
react = { CustomHeadersDockview }
64
100
/>
65
-
66
- ## Custom Tab Title
67
-
68
- If you are using a custom tab implementation you should pass variables through as a parameter and render them
69
- through your tab components implementation.
70
-
71
- ``` tsx title="Add a panel with custom parameters"
72
- api .addPanel ({
73
- id: ' panel_2' ,
74
- component: ' my_component' ,
75
- tabComponent: ' my_tab' ,
76
- params: {
77
- myTitle: ' Window 2' , // <-- passing a variable to use as a title
78
- },
79
- });
80
- ```
81
-
82
- ``` tsx title="Accessing custom parameters from a custom tab renderer"
83
- const tabComponents = {
84
- default : (props : IDockviewPanelHeaderProps <{ myTitle: string }>) => {
85
- const title = props .params .myTitle ; // <-- accessing my custom varaible
86
- return <div >{ /** tab implementation as chosen by developer */ } </div >;
87
- },
88
- };
89
- ```
0 commit comments