chore: update readme

This commit is contained in:
mathuo 2022-03-14 20:08:59 +00:00
parent 6642bcb430
commit e21ca56092
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
2 changed files with 41 additions and 6 deletions

View File

@ -69,12 +69,29 @@ You should also attach a dockview theme to an element containing your components
Demonstrated below is a high level example of a `DockviewReact` component. You can follow a similar pattern for `GridviewReact`, `SplitviewReact` and `PaneviewReact` components too, see examples for more.
```tsx
import { DockviewReact, DockviewReadyEvent, PanelCollection.IDockviewPanelProps } from 'dockview';
import {
DockviewReact,
DockviewReadyEvent,
PanelCollection,
IDockviewPanelProps,
IDockviewPanelHeaderProps,
} from 'dockview';
const components: PanelCollection<IDockviewPanelProps> = {
default: (props: IDockviewPanelProps<{someProps: string}>) => {
return <div>{props.params.someProps}</div>
}
default: (props: IDockviewPanelProps<{ someProps: string }>) => {
return <div>{props.params.someProps}</div>;
},
};
const headers: PanelCollection<IDockviewPanelHeaderProps> = {
customTab: (props: IDockviewPanelHeaderProps) => {
return (
<div>
<span>{props.api.title}</span>
<span onClick={() => props.api.close()}>{'[x]'}</span>
</div>
);
},
};
const Component = () => {
@ -96,7 +113,13 @@ const Component = () => {
});
};
return <DockviewReact components={components} onReady={onReady} />;
return (
<DockviewReact
components={components}
tabComponents={headers}
onReady={onReady}
/>
);
};
```

View File

@ -77,6 +77,17 @@ const components: PanelCollection<IDockviewPanelProps> = {
}
};
const headers: PanelCollection<IDockviewPanelHeaderProps> = {
customHeader: (props) => {
return (
<div>
<span>{props.api.title}</span>
<span onClick={() => props.api.close()}>{'[x]'}</span>
</div>
);
},
};
const Component = () => {
const onReady = (event: DockviewReadyEvent) => {
event.api.addPanel({
@ -89,6 +100,7 @@ const Component = () => {
event.api.addPanel({
id: 'panel2',
component: 'default',
tabComponent: 'customHeader', // optional custom header
params: {
someProps: 'World',
},
@ -96,7 +108,7 @@ const Component = () => {
});
};
return <DockviewReact components={components} onReady={onReady} />;
return <DockviewReact components={components} tabComponents={headers} onReady={onReady} />;
};
```