Skip to content

Commit ce72fc1

Browse files
liujupingJackLian
authored andcommitted
feat(common-ui): add HelpTip
1 parent 18642ee commit ce72fc1

File tree

6 files changed

+87
-30
lines changed

6 files changed

+87
-30
lines changed

docs/docs/api/commonUI.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ CommonUI API 是一个专为低代码引擎设计的组件 UI 库,使用它开
1919
| direction | tip 的方向 | 'top' \| 'bottom' \| 'left' \| 'right' | |
2020

2121

22+
### HelpTip
23+
24+
带 help icon 的提示组件
25+
26+
| 参数 | 说明 | 类型 | 默认值 |
27+
|-----------|--------|-----------------------------------|--------|
28+
| help | 描述 | IPublicTypeHelpTipConfig | |
29+
| direction | 方向 | IPublicTypeTipConfig['direction'] | 'top' |
30+
| size | 方向 | IconProps['size'] | 'small'|
31+
2232
### Title
2333

2434
标题组件
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { IPublicTypeHelpTipConfig, IPublicTypeTipConfig } from '@alilc/lowcode-types';
2+
import { Tip } from './tip';
3+
import { Icon } from '@alifd/next';
4+
import { IconProps } from '@alifd/next/types/icon';
5+
6+
export function HelpTip({
7+
help,
8+
direction = 'top',
9+
size = 'small',
10+
}: {
11+
help: IPublicTypeHelpTipConfig;
12+
direction?: IPublicTypeTipConfig['direction'];
13+
size?: IconProps['size'];
14+
}) {
15+
if (typeof help === 'string') {
16+
return (
17+
<div>
18+
<Icon type="help" size={size} className="lc-help-tip" />
19+
<Tip direction={direction}>{help}</Tip>
20+
</div>
21+
);
22+
}
23+
24+
if (typeof help === 'object' && help.url) {
25+
return (
26+
<div>
27+
<a href={help.url} target="_blank" rel="noopener noreferrer">
28+
<Icon type="help" size={size} className="lc-help-tip" />
29+
</a>
30+
<Tip direction={direction}>{help.content}</Tip>
31+
</div>
32+
);
33+
}
34+
return (
35+
<div>
36+
<Icon type="help" size="small" className="lc-help-tip" />
37+
<Tip direction={direction}>{help.content}</Tip>
38+
</div>
39+
);
40+
}

packages/editor-core/src/widgets/tip/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ import './style.less';
22

33
export * from './tip';
44
export * from './tip-container';
5+
export * from './help-tips';

packages/editor-skeleton/src/components/widget-views/index.tsx

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Component, ReactElement } from 'react';
2-
import { Icon } from '@alifd/next';
32
import classNames from 'classnames';
4-
import { Title, observer, Tip } from '@alilc/lowcode-editor-core';
3+
import { Title, observer, HelpTip } from '@alilc/lowcode-editor-core';
54
import { DockProps } from '../../types';
65
import { PanelDock } from '../../widget/panel-dock';
76
import { composeTitle } from '../../widget/utils';
@@ -26,25 +25,6 @@ export function DockView({ title, icon, description, size, className, onClick }:
2625
);
2726
}
2827

29-
function HelpTip({ tip }: any) {
30-
if (tip && tip.url) {
31-
return (
32-
<div>
33-
<a href={tip.url} target="_blank" rel="noopener noreferrer">
34-
<Icon type="help" size="small" className="lc-help-tip" />
35-
</a>
36-
<Tip>{tip.content}</Tip>
37-
</div>
38-
);
39-
}
40-
return (
41-
<div>
42-
<Icon type="help" size="small" className="lc-help-tip" />
43-
<Tip>{tip.content}</Tip>
44-
</div>
45-
);
46-
}
47-
4828
@observer
4929
export class PanelDockView extends Component<DockProps & { dock: PanelDock }> {
5030
private lastActived = false;
@@ -328,7 +308,7 @@ class PanelTitle extends Component<{ panel: Panel; className?: string }> {
328308
data-name={panel.name}
329309
>
330310
<Title title={panel.title || panel.name} />
331-
{panel.help ? <HelpTip tip={panel.help} /> : null}
311+
{panel.help ? <HelpTip help={panel.help} /> : null}
332312
</div>
333313
);
334314
}

packages/shell/src/api/commonUI.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IPublicApiCommonUI, IPublicModelPluginContext, IPublicTypeContextMenuAction } from '@alilc/lowcode-types';
22
import {
3+
HelpTip,
34
IEditor,
45
Tip as InnerTip,
56
Title as InnerTitle,
@@ -46,6 +47,11 @@ export class CommonUI implements IPublicApiCommonUI {
4647
get Tip() {
4748
return InnerTip;
4849
}
50+
51+
get HelpTip() {
52+
return HelpTip;
53+
}
54+
4955
get Title() {
5056
return InnerTitle;
5157
}

packages/types/src/shell/api/commonUI.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { ReactElement } from 'react';
2-
import { IPublicTypeContextMenuAction, IPublicTypeTitleContent } from '../type';
1+
import React, { ReactElement } from 'react';
2+
import { IPublicTypeContextMenuAction, IPublicTypeHelpTipConfig, IPublicTypeTipConfig, IPublicTypeTitleContent } from '../type';
33
import { Balloon, Breadcrumb, Button, Card, Checkbox, DatePicker, Dialog, Dropdown, Form, Icon, Input, Loading, Message, Overlay, Pagination, Radio, Search, Select, SplitButton, Step, Switch, Tab, Table, Tree, TreeSelect, Upload, Divider } from '@alifd/next';
4+
import { IconProps } from '@alifd/next/types/icon';
45

56
export interface IPublicApiCommonUI {
67
Balloon: typeof Balloon;
@@ -33,22 +34,41 @@ export interface IPublicApiCommonUI {
3334

3435
/**
3536
* Title 组件
36-
* @experimental unstable API, pay extra caution when trying to use this
3737
*/
38-
get Tip(): React.ComponentClass<{}>;
38+
get Tip(): React.ComponentClass<IPublicTypeTipConfig>;
39+
40+
/**
41+
* HelpTip 组件
42+
*/
43+
get HelpTip(): React.VFC<{
44+
help: IPublicTypeHelpTipConfig;
45+
46+
/**
47+
* 方向
48+
* @default 'top'
49+
*/
50+
direction: IPublicTypeTipConfig['direction'];
51+
52+
/**
53+
* 大小
54+
* @default 'small'
55+
*/
56+
size: IconProps['size'];
57+
}>;
3958

4059
/**
4160
* Tip 组件
42-
* @experimental unstable API, pay extra caution when trying to use this
4361
*/
4462
get Title(): React.ComponentClass<{
4563
title: IPublicTypeTitleContent | undefined;
4664
match?: boolean;
4765
keywords?: string | null;
4866
}>;
4967

50-
get ContextMenu(): (props: {
68+
get ContextMenu(): ((props: {
5169
menus: IPublicTypeContextMenuAction[];
5270
children: React.ReactElement[] | React.ReactElement;
53-
}) => ReactElement;
54-
}
71+
}) => ReactElement) & {
72+
create(menus: IPublicTypeContextMenuAction[], event: MouseEvent | React.MouseEvent): void;
73+
};
74+
}

0 commit comments

Comments
 (0)