Skip to content

Commit

Permalink
fix(Icon): support input required type
Browse files Browse the repository at this point in the history
  • Loading branch information
anlyyao committed Sep 2, 2024
1 parent 825a748 commit 14b3ff3
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 78 deletions.
Binary file modified db/TDesign.db
Binary file not shown.
31 changes: 31 additions & 0 deletions packages/products/tdesign-miniprogram/src/icon/props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable */

/**
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* */

import { TdIconProps } from './type';
const props: TdIconProps = {
/** 图标颜色 */
color: {
type: String,
value: '',
},
/** 图标名称或图片链接 */
name: {
type: String,
value: '',
required: true,
},
/** 自定义图标前缀 */
prefix: {
type: String,
value: '',
},
/** 图标大小, 如 `20`, `20px`, `48rpx`, 默认单位是 `px` */
size: {
type: null,
},
};

export default props;
40 changes: 40 additions & 0 deletions packages/products/tdesign-miniprogram/src/icon/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable */

/**
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* */

export interface TdIconProps {
/**
* 图标颜色
* @default ''
*/
color?: {
type: StringConstructor;
value?: string;
};
/**
* 图标名称或图片链接
* @default ''
*/
name: {
type: StringConstructor;
value?: string;
required?: boolean;
};
/**
* 自定义图标前缀
* @default ''
*/
prefix?: {
type: StringConstructor;
value?: string;
};
/**
* 图标大小, 如 `20`, `20px`, `48rpx`, 默认单位是 `px`
*/
size?: {
type: null;
value?: string | number;
};
}
74 changes: 0 additions & 74 deletions packages/scripts/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -58362,43 +58362,6 @@
"String"
]
},
{
"id": 1706,
"platform_framework": [
"64"
],
"component": "Icon",
"field_category": 1,
"field_name": "customStyle",
"field_type": [
"1"
],
"field_default_value": "",
"field_enum": "",
"field_desc_zh": "自定义组件样式",
"field_desc_en": null,
"field_required": 0,
"event_input": "",
"create_time": "2021-09-21 08:22:33",
"update_time": "2021-09-21 08:22:33",
"event_output": null,
"custom_field_type": null,
"syntactic_sugar": null,
"readonly": 1,
"html_attribute": 0,
"trigger_elements": "",
"deprecated": 0,
"version": "",
"test_description": null,
"support_default_value": 0,
"field_category_text": "Props",
"platform_framework_text": [
"Miniprogram"
],
"field_type_text": [
"String"
]
},
{
"id": 1688,
"platform_framework": [
Expand Down Expand Up @@ -58512,43 +58475,6 @@
"Number"
]
},
{
"id": 3044,
"platform_framework": [
"64"
],
"component": "Icon",
"field_category": 1,
"field_name": "style",
"field_type": [
"1"
],
"field_default_value": "",
"field_enum": "",
"field_desc_zh": "自定义组件样式",
"field_desc_en": null,
"field_required": 0,
"event_input": "",
"create_time": "2022-10-31 11:19:10",
"update_time": "2022-10-31 11:19:10",
"event_output": null,
"custom_field_type": null,
"syntactic_sugar": null,
"readonly": 1,
"html_attribute": 0,
"trigger_elements": "",
"deprecated": 0,
"version": "",
"test_description": null,
"support_default_value": 0,
"field_category_text": "Props",
"platform_framework_text": [
"Miniprogram"
],
"field_type_text": [
"String"
]
},
{
"id": 3366,
"platform_framework": [
Expand Down
4 changes: 2 additions & 2 deletions packages/scripts/config/files-combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const COMPONENT_API_MD_MAP = {
includes: ['Vue(PC)', 'VueNext(PC)', 'React(PC)', 'Angular(PC)'],
},
],
Icon: ['IconSVG', 'Iconfont'],
Icon: ['Icon', 'IconSVG', 'Iconfont'],
Select: ['Select', 'Option', 'OptionGroup', 'TScroll'],
Tag: ['Tag', 'CheckTag', 'CheckTagGroup'],
Collapse: ['Collapse', 'CollapsePanel'],
Expand Down Expand Up @@ -369,7 +369,7 @@ const TYPES_COMBINE_MAP = {
list: TABLE_LIST,
},
Icon: {
list: ['Iconfont', 'IconSVG'],
list: ['Icon', 'Iconfont', 'IconSVG'],
},
Anchor: {
list: ['AnchorTarget', 'AnchorItem'],
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ function getTypeScriptDesc(componentMap, framework) {
const rType =
framework === 'Miniprogram' &&
!COMPONENTS_MAP[api.component].type
? getMiniprogramType(api.field_type_text, type)
? getMiniprogramType(api.field_type_text, type, api.field_required)
: type;
const apiContext = [
formatComment(comment, plugin),
Expand Down
6 changes: 5 additions & 1 deletion packages/scripts/types/miniprogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const shell = require('shelljs');
const { camelCase } = require('lodash');

// 小程序的 props 类型定义特殊
function getMiniprogramType(type, tsType) {
function getMiniprogramType(type, tsType, required) {
const MP_PROP_TYPES = {
string: 'StringConstructor',
number: 'NumberConstructor',
Expand All @@ -18,9 +18,13 @@ function getMiniprogramType(type, tsType) {
}
});
const valueStr = ['function', 'Function'].includes(tsType) ? 'null' : tsType;

const isRequired = required ? `required?: boolean;` : '';

return `{
${`type: ${types.length > 1 ? 'null' : types[0]};`}
value?: ${valueStr};
${isRequired}
}`;
}

Expand Down

0 comments on commit 14b3ff3

Please sign in to comment.