2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2023-09-11 17:28:04 +08:00
|
|
|
import omit from 'rc-util/lib/omit';
|
|
|
|
|
|
|
|
import { devUseWarning } from '../_util/warning';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { BlockProps, EllipsisConfig } from './Base';
|
|
|
|
import Base from './Base';
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2022-10-18 11:45:43 +08:00
|
|
|
export interface TextProps
|
|
|
|
extends BlockProps<'span'>,
|
|
|
|
Omit<React.HTMLAttributes<HTMLSpanElement>, 'type' | keyof BlockProps<'span'>> {
|
2021-01-12 16:46:59 +08:00
|
|
|
ellipsis?: boolean | Omit<EllipsisConfig, 'expandable' | 'rows' | 'onExpand'>;
|
2019-02-19 11:42:05 +08:00
|
|
|
}
|
|
|
|
|
2022-04-05 13:02:32 +08:00
|
|
|
const Text: React.ForwardRefRenderFunction<HTMLSpanElement, TextProps> = (
|
|
|
|
{ ellipsis, ...restProps },
|
|
|
|
ref,
|
|
|
|
) => {
|
2021-01-12 16:46:59 +08:00
|
|
|
const mergedEllipsis = React.useMemo(() => {
|
|
|
|
if (ellipsis && typeof ellipsis === 'object') {
|
2023-07-27 10:18:47 +08:00
|
|
|
return omit(ellipsis as EllipsisConfig, ['expandable', 'rows']);
|
2021-01-12 16:46:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ellipsis;
|
|
|
|
}, [ellipsis]);
|
|
|
|
|
2023-09-11 17:28:04 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
const warning = devUseWarning();
|
|
|
|
|
|
|
|
warning(
|
|
|
|
typeof ellipsis !== 'object' ||
|
|
|
|
!ellipsis ||
|
|
|
|
(!('expandable' in ellipsis) && !('rows' in ellipsis)),
|
|
|
|
'Typography.Text',
|
|
|
|
'usage',
|
|
|
|
'`ellipsis` do not support `expandable` or `rows` props.',
|
|
|
|
);
|
|
|
|
}
|
2021-01-12 16:46:59 +08:00
|
|
|
|
2022-04-05 13:02:32 +08:00
|
|
|
return <Base ref={ref} {...restProps} ellipsis={mergedEllipsis} component="span" />;
|
2019-02-19 11:42:05 +08:00
|
|
|
};
|
|
|
|
|
2022-04-05 13:02:32 +08:00
|
|
|
export default React.forwardRef(Text);
|