Skip to content

Commit 9f7441c

Browse files
authored
fix: add deprecated and data group to ComponentPropType (#116)
* fix: add deprecated and data group to ComponentPropType * fix: render choiceSetter with icon
1 parent 9fd9673 commit 9f7441c

File tree

6 files changed

+90
-22
lines changed

6 files changed

+90
-22
lines changed

apps/playground/src/pages/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const sandboxQuery = new DndQuery({
4646

4747
// 4. 图标库初始化(物料面板和组件树使用了 iconfont 里的图标)
4848
createFromIconfontCN({
49-
scriptUrl: '//at.alicdn.com/t/c/font_2891794_lzc7rtwuzf.js',
49+
scriptUrl: '//at.alicdn.com/t/c/font_2891794_cou9i7556tl.js',
5050
});
5151

5252
/**

apps/storybook/src/setting-form.stories.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
import React from 'react';
22
import { FormModel, SettingForm, register } from '@music163/tango-setting-form';
33
import { ComponentPrototypeType } from '@music163/tango-helpers';
4-
import { BorderSetter } from '@music163/tango-designer/src/setters/style-setter';
4+
import { BorderSetter, DisplaySetter } from '@music163/tango-designer/src/setters/style-setter';
55
import { Box } from 'coral-system';
66
import { JsonView } from '@music163/tango-ui';
77
import { toJS } from 'mobx';
88
import { observer } from 'mobx-react-lite';
99
import { Card } from 'antd';
10+
import { createFromIconfontCN } from '@ant-design/icons';
1011

12+
// 这里按需注入,因为部分 setter 依赖 Designer 的上下文
1113
register({
1214
name: 'borderSetter',
1315
component: BorderSetter,
1416
});
1517

18+
register({
19+
name: 'displaySetter',
20+
component: DisplaySetter,
21+
});
22+
23+
createFromIconfontCN({
24+
scriptUrl: '//at.alicdn.com/t/c/font_2891794_cou9i7556tl.js',
25+
});
26+
1627
export default {
1728
title: 'SettingForm',
1829
};
@@ -31,6 +42,14 @@ const prototype: ComponentPrototypeType = {
3142
name: 'text',
3243
title: 'textSetter',
3344
setter: 'textSetter',
45+
tip: '这是一个文本属性',
46+
docs: 'https://music-one.fn.netease.com/docs/button',
47+
deprecated: '使用 text2 替代',
48+
},
49+
{
50+
name: 'display',
51+
title: 'displaySetter',
52+
setter: 'displaySetter',
3453
},
3554
{
3655
name: 'border',

packages/designer/src/setters/choice-setter.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React from 'react';
1+
import React, { useCallback } from 'react';
22
import { Radio, RadioProps, Tooltip } from 'antd';
33
import type { OptionType } from '@music163/tango-helpers';
44
import { FormItemComponentProps } from '@music163/tango-setting-form';
5+
import { IconFont } from '@music163/tango-ui';
56

67
interface ChoiceSetterProps {
7-
mode?: 'text' | 'icon';
88
options?: OptionType[];
99
}
1010

@@ -13,6 +13,18 @@ export function ChoiceSetter({
1313
onChange,
1414
...props
1515
}: FormItemComponentProps<string> & ChoiceSetterProps) {
16+
const renderIcon = useCallback((icon: string) => {
17+
if (!icon) {
18+
return null;
19+
}
20+
21+
if (icon.startsWith('icon-')) {
22+
return <IconFont type={icon} />;
23+
}
24+
25+
return null;
26+
}, []);
27+
1628
return (
1729
<Radio.Group
1830
optionType="button"
@@ -24,6 +36,7 @@ export function ChoiceSetter({
2436
>
2537
{options.map((item) => (
2638
<RadioButton tip={item.tip} key={item.value} value={item.value}>
39+
{renderIcon(item.icon)}
2740
{item.label}
2841
</RadioButton>
2942
))}

packages/helpers/src/types/prototype.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ export type ComponentPropType<T = any> = {
2424
* 属性的分组
2525
* - basic 常用属性
2626
* - event 事件属性
27+
* - data 数据属性
2728
* - style 样式属性
2829
* - advanced 高级属性
2930
*/
30-
group?: 'basic' | 'event' | 'style' | 'advanced';
31+
group?: 'basic' | 'event' | 'style' | 'data' | 'advanced';
3132
/**
3233
* 帮助文档链接地址
3334
* @example https://foo.bar/help
@@ -91,6 +92,10 @@ export type ComponentPropType<T = any> = {
9192
* 动态设置表单项是否展示
9293
*/
9394
getVisible?: (form: any) => boolean;
95+
/**
96+
* 标记属性是否已废弃
97+
*/
98+
deprecated?: boolean | string;
9499
};
95100

96101
/**

packages/setting-form/src/form-item.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export function createFormItem(options: IFormItemCreateOptions) {
8686
disableVariableSetter: disableVariableSetterProp = options.disableVariableSetter,
8787
getVisible: getVisibleProp,
8888
getSetterProps: getSetterPropsProp,
89+
deprecated,
8990
extra,
9091
footer,
9192
noStyle,
@@ -160,6 +161,7 @@ export function createFormItem(options: IFormItemCreateOptions) {
160161
note={showItemSubtitle ? name : null}
161162
tip={tip}
162163
docs={docs}
164+
deprecated={deprecated}
163165
error={field.error}
164166
extra={
165167
<Box>

packages/setting-form/src/form-ui.tsx

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React, { useState } from 'react';
2-
import { css, Box, HTMLCoralProps, Text } from 'coral-system';
2+
import { css, Box, HTMLCoralProps, Link } from 'coral-system';
33
import { Checkbox, Tooltip } from 'antd';
44
import { CollapsePanel } from '@music163/tango-ui';
55
import { isNil, isString } from '@music163/tango-helpers';
6+
import { WarningOutlined } from '@ant-design/icons';
67

78
export interface FormControlProps extends Omit<FormLabelProps, 'type'> {
89
visible: boolean;
@@ -19,6 +20,7 @@ export function FormControl({
1920
tip,
2021
docs,
2122
extra,
23+
deprecated,
2224
footer,
2325
error,
2426
children,
@@ -27,7 +29,7 @@ export function FormControl({
2729
return (
2830
<Box className="FormControl" display={visible ? 'block' : 'none'} {...rest}>
2931
<Box display="flex" justifyContent="space-between" alignItems="center" mb="s">
30-
<FormLabel label={label} note={note} tip={tip} docs={docs} />
32+
<FormLabel label={label} note={note} tip={tip} docs={docs} deprecated={deprecated} />
3133
{extra}
3234
</Box>
3335
<Box>{children}</Box>
@@ -138,12 +140,12 @@ const labelStyle = css`
138140
`;
139141

140142
const tipStyle = css`
141-
a:link {
142-
color: #fff;
143+
a {
144+
text-decoration: underline;
143145
}
144146
145-
a:hover {
146-
color: var(--tango-colors-brand);
147+
a:link {
148+
color: #fff;
147149
}
148150
`;
149151

@@ -169,19 +171,45 @@ interface FormLabelProps extends HTMLCoralProps<'div'> {
169171
* 文档地址
170172
*/
171173
docs?: string;
174+
/**
175+
* 是否显示废弃标记
176+
*/
177+
// eslint-disable-next-line react/no-unused-prop-types
178+
deprecated?: boolean | string;
172179
}
173180

174-
function FormLabel({ type = 'normal', label, note, tip, docs, ...rest }: FormLabelProps) {
175-
const help = docs ? (
176-
<Box css={tipStyle}>
177-
<Text mr="m">{tip}</Text>
178-
<a href={docs} target="_blank" rel="noreferrer">
179-
帮助文档
180-
</a>
181-
</Box>
182-
) : (
183-
tip
184-
);
181+
function FormLabel({
182+
type = 'normal',
183+
label,
184+
note,
185+
tip,
186+
docs,
187+
deprecated,
188+
...rest
189+
}: FormLabelProps) {
190+
let help: React.ReactNode;
191+
if (deprecated || docs) {
192+
help = (
193+
<Box>
194+
<Box css={tipStyle}>
195+
{tip}
196+
{docs ? (
197+
<Link href={docs} isExternal ml="m">
198+
查看属性文档
199+
</Link>
200+
) : null}
201+
</Box>
202+
{deprecated ? (
203+
<Box color="#faad14">
204+
<WarningOutlined /> 废弃提示:
205+
{isString(deprecated) ? deprecated : '该属性已废弃,请谨慎使用。'}
206+
</Box>
207+
) : null}
208+
</Box>
209+
);
210+
} else {
211+
help = tip;
212+
}
185213

186214
const labelColor = {
187215
normal: 'text.body',
@@ -197,6 +225,7 @@ function FormLabel({ type = 'normal', label, note, tip, docs, ...rest }: FormLab
197225
css={labelStyle}
198226
title={isString(label) ? label : undefined}
199227
>
228+
{deprecated ? <WarningOutlined style={{ color: '#faad14', marginRight: 4 }} /> : null}
200229
{label}
201230
</Box>
202231
);

0 commit comments

Comments
 (0)