Skip to content

Commit

Permalink
feat(descriptions): support emptyText
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Aug 24, 2023
1 parent af522ee commit d5ccc34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/descriptions/src/demos/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default () => {
return Promise.resolve({
success: true,
data: {
id: '这是一段文本columns',
date: '20200809',
money: '1212100',
money2: -12345.33,
Expand All @@ -18,6 +17,7 @@ export default () => {
},
});
}}
emptyText={'空'}
columns={[
{
title: '文本',
Expand Down
10 changes: 10 additions & 0 deletions packages/descriptions/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export type ProDescriptionsProps<
dataSource?: RecordType;
/** 受控数据源改变 */
onDataSourceChange?: (value: RecordType) => void;

/**
*为空时候的默认值
*/
emptyText?: React.ReactNode;
};

/**
Expand Down Expand Up @@ -155,6 +160,7 @@ export const FieldRender: React.FC<
action: ProCoreActionType<any>;
index: number;
editableUtils?: UseEditableMapUtilType;
emptyText?: React.ReactNode;
}
> = (props) => {
const {
Expand Down Expand Up @@ -182,6 +188,7 @@ export const FieldRender: React.FC<
valueEnum,
mode: mode || 'read',
proFieldProps: {
emptyText: props.emptyText,
render: render
? () =>
render?.(text, entity, index, action, {
Expand Down Expand Up @@ -302,6 +309,7 @@ const schemaToDescriptionsItem = (
entity: any,
action: ProCoreActionType<any>,
editableUtils?: UseEditableMapUtilType,
emptyText?: React.ReactNode,
) => {
const options: JSX.Element[] = [];
const isBigger58 = compareVersions(version, '5.8.0') >= 0;
Expand Down Expand Up @@ -388,6 +396,7 @@ const schemaToDescriptionsItem = (
valueType={valueType}
entity={entity}
index={index}
emptyText={emptyText}
action={action}
editableUtils={editableUtils}
/>
Expand Down Expand Up @@ -587,6 +596,7 @@ const ProDescriptions = <
action.dataSource || {},
actionRef?.current || action,
editable ? editableUtils : undefined,
props.emptyText,
);

/** 如果不是可编辑模式,没必要注入 ProForm */
Expand Down
3 changes: 2 additions & 1 deletion tests/descriptions/__snapshots__/demo.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ exports[`descriptions demos 📸 renders ./packages/descriptions/src/demos/colum
</div>
<div
class="ant-descriptions ant-pro-descriptions"
emptytext=""
>
<div
class="ant-descriptions-header"
Expand Down Expand Up @@ -889,7 +890,7 @@ exports[`descriptions demos 📸 renders ./packages/descriptions/src/demos/colum
class="ant-descriptions-item-content"
style="min-width: 0;"
>
这是一段文本columns
</span>
</div>
</td>
Expand Down

0 comments on commit d5ccc34

Please sign in to comment.