Skip to content

Commit 070b4b4

Browse files
authored
Merge pull request #1352 from alibaba/feat-generator-setting
feat(generator): 新增pop交互,用于介绍组件。
2 parents 7fe9875 + 3a8d571 commit 070b4b4

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

tools/schema-generator/src/components/Sidebar/Element.jsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
2+
import { Popover } from 'antd';
23
import { useDrag } from 'react-dnd';
34
import { useTranslation } from 'react-i18next';
45
import { addItem } from '../../utils';
56
import { useGlobal, useStore } from '../../utils/hooks';
67
import './Element.less';
78

8-
const Element = ({ text, name, schema, icon, fixedName }) => {
9+
const Element = ({ text, name, schema, icon, fixedName, popover }) => {
910
const setGlobal = useGlobal();
1011
const {
1112
selected,
@@ -52,6 +53,7 @@ const Element = ({ text, name, schema, icon, fixedName }) => {
5253
const widgetProps = {
5354
text,
5455
icon,
56+
popover,
5557
onClick: handleElementClick,
5658
};
5759

@@ -69,12 +71,22 @@ const Element = ({ text, name, schema, icon, fixedName }) => {
6971
export default Element;
7072

7173
// 目前没有用icon,但是可以补上
72-
const WidgetUI = ({ onClick, text, icon }) => {
74+
const WidgetUI = ({ onClick, text, icon, popover }) => {
7375
const { t } = useTranslation(["components"]);
74-
return (
75-
<li className="left-item" onClick={onClick}>
76-
{icon}
77-
{t(text)}
78-
</li>
79-
);
76+
if (popover?.content) {
77+
return <Popover title={popover?.title || ''} content={popover?.content} mouseLeaveDelay={0}>
78+
<li className="left-item" onClick={onClick}>
79+
{icon}
80+
{t(text)}
81+
</li>
82+
</Popover>
83+
} else {
84+
return (
85+
<li className="left-item" onClick={onClick}>
86+
{icon}
87+
{t(text)}
88+
</li>
89+
);
90+
}
91+
8092
};

tools/schema-generator/src/settings/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export const elements = [
109109
{
110110
text: '输入框',
111111
name: 'input',
112+
popover: {
113+
content: '可以输入内容'
114+
},
112115
schema: {
113116
title: '输入框',
114117
type: 'string',
@@ -161,6 +164,10 @@ export const elements = [
161164
},
162165
{
163166
text: '大输入框',
167+
popover: {
168+
title: '介绍',
169+
content: '可以输入多行内容'
170+
},
164171
name: 'textarea',
165172
schema: {
166173
title: '编辑框',
@@ -203,6 +210,10 @@ export const elements = [
203210
{
204211
text: '日期选择',
205212
name: 'date',
213+
popover: {
214+
title: '略缩图',
215+
content: <img width={348} height={43} src="https://img.alicdn.com/imgextra/i4/O1CN01gPzKrs1eNTHPhuSIG_!!6000000003859-0-tps-348-43.jpg" />
216+
},
206217
schema: {
207218
title: '日期选择',
208219
type: 'string',

0 commit comments

Comments
 (0)