Skip to content

Commit d9b9fdc

Browse files
committed
feat: add testing sidebar panel
1 parent 909bcc8 commit d9b9fdc

File tree

3 files changed

+141
-1
lines changed

3 files changed

+141
-1
lines changed

stories/extensions/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { IExtension } from 'mo/model/extension';
22
import { ExtendDataSync } from './data-sync';
33

4-
export const customExtensions: IExtension[] = [ExtendDataSync];
4+
import { ExtendTestPane } from './test';
5+
6+
export const customExtensions: IExtension[] = [ExtendDataSync, ExtendTestPane];

stories/extensions/test/index.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import { activityBarService, IActivityBarItem, sidebarService } from 'mo';
3+
import { IExtension } from 'mo/model/extension';
4+
5+
import TestPane from './testPane';
6+
7+
export const ExtendTestPane: IExtension = {
8+
activate() {
9+
const testSidePane = {
10+
id: 'testPane',
11+
title: 'TEST',
12+
render() {
13+
return <TestPane />;
14+
},
15+
};
16+
17+
sidebarService.push(testSidePane);
18+
const newItem = {
19+
id: 'ActivityBarTestPane',
20+
iconName: 'codicon-beaker',
21+
name: '测试',
22+
};
23+
activityBarService.addBar(newItem);
24+
25+
activityBarService.onSelect((e, item: IActivityBarItem) => {
26+
if (item.id === newItem.id) {
27+
sidebarService.setState({
28+
current: testSidePane.id,
29+
});
30+
}
31+
});
32+
},
33+
};

stories/extensions/test/testPane.tsx

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import * as React from 'react';
2+
import {
3+
activityBarService,
4+
colorThemeService,
5+
editorService,
6+
panelService,
7+
} from 'mo';
8+
import { Button } from 'mo/components/button';
9+
import { Select, Option } from 'mo/components/select';
10+
import { IColorTheme } from 'mo/model/colorTheme';
11+
import { IEditorTab } from 'mo/model';
12+
13+
export default class TestPane extends React.Component {
14+
constructor(props) {
15+
super(props);
16+
}
17+
18+
onClick = (e, item) => {
19+
console.log('onClick:', e, item);
20+
};
21+
22+
onChangeTheme = (e, option) => {
23+
if (option && option.value) {
24+
console.log('onChangeTheme:', option.value);
25+
colorThemeService.applyTheme(option.value);
26+
}
27+
};
28+
29+
renderColorThemes() {
30+
const colorThemes = colorThemeService.getThemes();
31+
const defaultTheme = colorThemeService.colorTheme;
32+
const options = colorThemes.map((theme: IColorTheme) => {
33+
return (
34+
<Option key={theme.id} value={theme.id}>
35+
{theme.label}
36+
</Option>
37+
);
38+
});
39+
return (
40+
<Select
41+
defaultValue={defaultTheme.id}
42+
onSelect={this.onChangeTheme}
43+
>
44+
{options}
45+
</Select>
46+
);
47+
}
48+
49+
render() {
50+
const addABar = function () {
51+
const id = Math.random() * 10 + 1;
52+
activityBarService.addBar({
53+
id: id + '',
54+
name: 'folder' + id,
55+
iconName: 'codicon-edit',
56+
});
57+
};
58+
59+
const addPanel = function () {
60+
const id = Math.random() * 10 + 1;
61+
panelService.open({
62+
id: 'Pane' + id,
63+
name: 'Panel' + id,
64+
label: 'test',
65+
render: () => <h1>Test Pane</h1>,
66+
});
67+
};
68+
69+
const newEditor = function () {
70+
const key = Math.random() * 10 + 1;
71+
const tabData: IEditorTab = {
72+
id: `${key}`,
73+
name: `editor.js`,
74+
modified: false,
75+
data: {
76+
value: `hello javascript ${key}`,
77+
path: 'desktop/molecule/editor1',
78+
language: 'javascript',
79+
},
80+
breadcrumb: [{ id: `${key}`, name: 'editor.js' }],
81+
};
82+
console.log('open editor:', tabData);
83+
editorService.open(tabData);
84+
};
85+
86+
const openCommand = function () {};
87+
return (
88+
<div>
89+
<div style={{ margin: '50px 20px' }}>
90+
<Button onClick={addABar}>Add Bar</Button>
91+
<Button onClick={newEditor}>New Editor</Button>
92+
<Button onClick={openCommand}>Command Palette</Button>
93+
</div>
94+
<div style={{ margin: '50px 20px' }}>
95+
<h1>Select a ColorTheme:</h1>
96+
{this.renderColorThemes()}
97+
</div>
98+
<div style={{ margin: '50px 20px' }}>
99+
<h2>Add a new Panel:</h2>
100+
<Button onClick={addPanel}>Add Panel</Button>
101+
</div>
102+
</div>
103+
);
104+
}
105+
}

0 commit comments

Comments
 (0)