Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions site/components/table/index.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/descriptions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ProSkeleton from '../skeleton';
import type {
ProCoreActionType,
ProEllipsis,
ProFieldValueType,
ProSchema,
ProSchemaComponentTypes,
Expand Down Expand Up @@ -64,7 +65,7 @@
hide?: boolean;
plain?: boolean;
copyable?: boolean;
ellipsis?: boolean | { showTitle?: boolean };
ellipsis?: ProEllipsis;
mode?: ProFieldFCMode;
children?: React.ReactNode;
/**
Expand Down Expand Up @@ -327,14 +328,14 @@
};
}
const {
valueEnum,

Check warning on line 331 in src/descriptions/index.tsx

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

'valueEnum' is assigned a value but never used
render,

Check warning on line 332 in src/descriptions/index.tsx

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

'render' is assigned a value but never used
renderText,
mode,
plain,

Check warning on line 335 in src/descriptions/index.tsx

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

'plain' is assigned a value but never used
dataIndex,
request,

Check warning on line 337 in src/descriptions/index.tsx

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

'request' is assigned a value but never used
params,

Check warning on line 338 in src/descriptions/index.tsx

View workflow job for this annotation

GitHub Actions / build (20.x, ubuntu-latest)

'params' is assigned a value but never used
editable,
...restItem
} = item as ProDescriptionsItemProps;
Expand Down
3 changes: 2 additions & 1 deletion src/table/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
} from '../form';
import type {
ProCoreActionType,
ProEllipsis,
ProSchema,
ProSchemaComponentTypes,
ProTableEditableFnType,
Expand Down Expand Up @@ -118,7 +119,7 @@ export type ProColumnType<T = unknown, ValueType = 'text'> = ProSchema<
initialValue?: any;

/** @name 是否缩略 */
ellipsis?: ColumnType<T>['ellipsis'];
ellipsis?: ProEllipsis;
/** @name 是否拷贝 */
copyable?: boolean;

Expand Down
3 changes: 2 additions & 1 deletion src/utils/components/LabelIconTip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
} from 'antd/lib/form/FormItemLabel';
import { clsx } from 'clsx';
import React, { useContext } from 'react';
import type { ProEllipsis } from '../../genCopyable';
import { useStyle } from './style';

/**
Expand All @@ -17,7 +18,7 @@ export const LabelIconTip: React.FC<{
label: React.ReactNode;
subTitle?: React.ReactNode;
tooltip?: string | LabelTooltipType;
ellipsis?: boolean | { showTitle?: boolean };
ellipsis?: ProEllipsis;
}> = React.memo((props) => {
const { label, tooltip, ellipsis, subTitle } = props;
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
Expand Down
47 changes: 34 additions & 13 deletions src/utils/genCopyable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import type { TooltipProps } from 'antd';
import { Typography } from 'antd';
import isObject from 'lodash-es/isObject';
import React from 'react';

export type ProEllipsisTooltip = {
showTitle?: boolean;
tooltip?: TooltipProps;
};

export type ProEllipsis = { ellipsis?: ProEllipsisTooltip } | boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

ProEllipsis 的类型定义似乎不正确。当前的定义 { ellipsis?: ProEllipsisTooltip } | boolean 会导致一个奇怪的 API 结构,例如 ellipsis={{ ellipsis: { tooltip: ... } }},这可能不是你的本意,并且会让使用者感到困惑。

getEllipsis 函数的实现来看,item.ellipsis 被期望为 ProEllipsisTooltip | boolean 类型。因此,ProEllipsis 类型应该直接是 ProEllipsisTooltipboolean 的联合类型。

Suggested change
export type ProEllipsis = { ellipsis?: ProEllipsisTooltip } | boolean;
export type ProEllipsis = ProEllipsisTooltip | boolean;


const isNeedTranText = (item: any): boolean => {
if (item?.valueType?.toString().startsWith('date')) {
return true;
Expand All @@ -11,11 +20,10 @@ const isNeedTranText = (item: any): boolean => {
return false;
};

const getEllipsis = (item: any) => {
const getEllipsis = (item: any): ProEllipsisTooltip | boolean => {
if (item.ellipsis?.showTitle === false) {
return false;
}

return item.ellipsis;
};

Expand All @@ -26,19 +34,32 @@ const normalizeCopyText = (text: unknown) => {
};

const genEllipsis = (dom: React.ReactNode, item: any, text: string) => {
const ellipsis = getEllipsis(item);
if (!ellipsis || !text) {
return false;
}
/** 有些 valueType 需要设置copy的为string */
const needTranText = isNeedTranText(item);
return getEllipsis(item) && text
? {
tooltip:
// 支持一下 tooltip 的关闭
item?.tooltip !== false && needTranText ? (
<div className="pro-table-tooltip-text">{dom}</div>
) : (
text
),
}
: false;

// 支持一下 tooltip 的关闭
if (needTranText && item?.tooltip !== false) {
return {
tooltip: <div className="pro-table-tooltip-text">{dom}</div>,
};
}

// 如果 ellipsis 是对象且包含 tooltip 属性,合并 tooltip 的属性
if (isObject(ellipsis) && isObject(ellipsis.tooltip)) {
return {
tooltip: {
title: text,
...ellipsis.tooltip,
},
};
}
return {
tooltip: text,
};
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { objectToMap, proFieldParsingText } from './proFieldParsingText';
import { runFunction } from './runFunction';
import stringify from './stringify';
import { transformKeySubmitValue } from './transformKeySubmitValue';
import type { ProEllipsis } from './genCopyable';
import type {
RowEditableConfig,
RowEditableType,
Expand Down Expand Up @@ -134,6 +135,7 @@ export {
useStyle,
};
export type {
ProEllipsis,
ProFormInstanceType,
ProRequestData,
RowEditableConfig,
Expand Down
Loading