Skip to content

Commit 3dd2019

Browse files
committed
feat: support right extra content
1 parent 82f7b19 commit 3dd2019

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

packages/core/src/core/diff-viewer/common.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,15 @@ export interface IOverrideAppRendererProps extends IOverrideAppRendererConfig {
105105
Landing?: React.ComponentType<LandingProps>;
106106
}
107107

108+
export interface IExtraContent {
109+
component?: React.ComponentType<any>;
110+
initialProps?: any;
111+
}
112+
108113
export const IDiffViewerProps = Symbol('IDiffViewerProps');
109114
export interface IDiffViewerProps extends Partial<IOverrideAppRendererProps> {
110115
onRef: (handle: IDiffViewerHandle) => void;
111116

112117
onWillApplyTheme?: (theme: ITheme) => Record<string, string | undefined>;
113-
tabBarRightExtraContent?: React.ReactNode;
118+
tabBarRightExtraContent?: IExtraContent;
114119
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Autowired } from '@opensumi/di';
2+
import { ComponentContribution, ComponentRegistry } from '@opensumi/ide-core-browser';
3+
import { Domain } from '@opensumi/ide-core-common';
4+
import { TabbarRightExtraContentId } from '@opensumi/ide-editor';
5+
import { IDiffViewerProps } from '../common';
6+
7+
@Domain(ComponentContribution)
8+
export class DiffViewerComponentContribution implements ComponentContribution {
9+
@Autowired(IDiffViewerProps)
10+
protected diffViewerProps: IDiffViewerProps;
11+
12+
registerComponent(registry: ComponentRegistry) {
13+
if (this.diffViewerProps.tabBarRightExtraContent) {
14+
registry.register(TabbarRightExtraContentId, {
15+
id: TabbarRightExtraContentId,
16+
component: this.diffViewerProps.tabBarRightExtraContent.component,
17+
initialProps: this.diffViewerProps.tabBarRightExtraContent.initialProps,
18+
});
19+
}
20+
}
21+
}

packages/core/src/core/diff-viewer/module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { BrowserModule } from '@opensumi/ide-core-browser';
22

33
import { Injectable } from '../../modules/opensumi__common-di';
44
import { DiffViewerContribution } from './internal/base';
5+
import { DiffViewerComponentContribution } from './internal/component.provider';
56
import { DiffViewerThemeProvider } from './internal/theme.provider';
67

78
@Injectable()
89
export class DiffViewerModule extends BrowserModule {
910
providers = [
1011
DiffViewerContribution,
1112
DiffViewerThemeProvider,
13+
DiffViewerComponentContribution,
1214
];
1315
}

packages/startup/src/diff-viewer/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ const App = () => {
3737

3838
const memo = useMemo(() => (
3939
<DiffViewerRenderer
40+
tabBarRightExtraContent={{
41+
component: () => <div>heelo</div>,
42+
}}
43+
onWillApplyTheme={() => {
44+
return {
45+
'editorGroupHeader.tabsBackground': '#fff',
46+
};
47+
}}
4048
onRef={(handle) => {
4149
handleRef.current = handle;
4250
console.log('=====', handle);
@@ -47,7 +55,7 @@ const App = () => {
4755
handle.onDidTabChange((e) => {
4856
console.log('onDidTabChange', e.newPath);
4957
setEventInfo(e);
50-
})
58+
});
5159
data.forEach(v => {
5260
handleRef.current!.openDiffInTab(
5361
v.path,

0 commit comments

Comments
 (0)