forked from alibaba/lowcode-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
71 lines (62 loc) · 1.62 KB
/
index.tsx
File metadata and controls
71 lines (62 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { PureComponent } from 'react';
import { ILowCodePluginContext, common } from '@alilc/lowcode-engine';
import { PluginProps } from '@alilc/lowcode-types';
import { intl } from './locale';
import { IconZh } from './icons/zh';
import { IconEn } from './icons/en';
import './index.less';
const { editorCabin } = common;
const { globalLocale, Tip } = editorCabin;
class ZhEn extends PureComponent<PluginProps> {
static displayName = 'LowcodeZhEn';
state = {
locale: globalLocale.getLocale(),
};
private dispose = globalLocale.onChangeLocale((locale) => {
this.setState({
locale,
});
window.location.reload();
});
componentWillUnmount() {
this.dispose();
}
render() {
const isZh = this.state.locale === 'zh-CN';
return (
<div
className="lowcode-plugin-zh-en"
onClick={() => {
globalLocale.setLocale(isZh ? 'en-US' : 'zh-CN');
}}
>
{isZh ? <IconEn size={20} /> : <IconZh size={20} />}
<Tip direction="right">{intl('To Locale')}</Tip>
</div>
);
}
}
const plugin = (ctx: ILowCodePluginContext) => {
return {
// 插件名,注册环境下唯一
name: 'PluginZhEn',
// 依赖的插件(插件名数组)
dep: [],
// 插件的初始化函数,在引擎初始化之后会立刻调用
init() {
// 往引擎增加面板
ctx.skeleton.add({
area: 'leftArea',
type: 'Widget',
name: 'zhEn',
content: ZhEn,
contentProps: {},
props: {
align: 'bottom',
},
})
},
};
};
plugin.pluginName = 'PluginZhEn'
export default plugin