Skip to content

Commit 5b9fb0d

Browse files
committed
chore: docs
1 parent 861d13c commit 5b9fb0d

File tree

3 files changed

+85
-65
lines changed

3 files changed

+85
-65
lines changed

packages/docs/docs/core/panels/add.mdx

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ const panel: IDockviewPanel = api.addPanel({
5959

6060
## Rendering
6161

62-
Rendering is worthy of it's own page which can be found [here](/docs/core/panels/rendering).
62+
See [Panel Rendering](/docs/core/panels/rendering).
63+
64+
## Tab Title
65+
66+
See [Tab Title](/docs/core/tabs/title).
6367

6468
## Positioning the Panel
6569

packages/docs/docs/core/tabs/rendering.mdx

+68-57
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,88 @@ sidebar_position: 2
66
import { MultiFrameworkContainer } from '@site/src/components/ui/container';
77
import CustomHeadersDockview from '@site/sandboxes/customheader-dockview/src/app';
88

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>
1028

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>
1532

16-
The `DockviewDefaultTab` component accepts a `hideClose` prop if you wish only to hide the close button.
1733

18-
```tsx title="Attaching a custom context menu event handlers to a custom header"
19-
import { IDockviewPanelHeaderProps, DockviewDefaultTab } from 'dockview';
34+
## Default Tab Renderer
2035

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}/>
2846
```
47+
</FrameworkSpecific>
2948

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>
3252

33-
```tsx
34-
const tabComponents = {
35-
myCustomHeader: MyCustomHeader,
36-
};
53+
## Accessing Custom Panel Parameters
3754

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.
4057

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+
}
4866
```
67+
</FrameworkSpecific>
68+
69+
70+
## Extend the Default Tab Implementation
4971

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
5176

77+
78+
<FrameworkSpecific framework='React'>
5279
```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+
};
5489
```
90+
</FrameworkSpecific>
5591

5692
As a simple example the below attaches a custom event handler for the context menu on all tabs as a default tab renderer
5793

@@ -62,28 +98,3 @@ This still makes use of the `DockviewDefaultTab` since it's only a minor change.
6298
sandboxId="customheader-dockview"
6399
react={CustomHeadersDockview}
64100
/>
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-
```

packages/docs/docs/core/tabs/title.mdx

+12-7
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,32 @@ sidebar_position: 0
66
import { MultiFrameworkContainer } from '@site/src/components/ui/container';
77
import DockviewSetTitle from '@site/sandboxes/updatetitle-dockview/src/app';
88

9-
## Default Tab Title
109

11-
If you are using the default tab renderer you can set the title of a tab when creating it
10+
:::warning
11+
Registering and updating the title using these built-in variables only works for the default tab renderer.
12+
If you use a custom tab render you can optionally access these variables to render the title, or you can take
13+
your own approach to rendering a tab title.
14+
:::
15+
16+
This section describes how to set the panel title
17+
18+
The value of `title` will be shown in the panels associated tab.
19+
If no panel id is provided then the `id` will be shown in the tab.
1220

1321
```tsx
1422
api.addPanel({
1523
id: 'panel_1',
1624
component: 'my_component',
17-
title: 'my_custom_title', // <-- special param for title
25+
title: 'my_custom_title',
1826
});
1927
```
2028

21-
You can update the title through the panel api which can be accessed via `props.api` if you are inside the panel
22-
component or via `api.getPanel('panel1').api` if you are accessing from outside of the panel component.
29+
## Update Tab Title
2330

2431
```tsx
2532
api.setTitle('my_new_custom_title');
2633
```
2734

28-
> Note this only works when using the default tab implementation.
29-
3035
<MultiFrameworkContainer
3136
sandboxId="updatetitle-dockview"
3237
react={DockviewSetTitle}

0 commit comments

Comments
 (0)