2021-01-14 14:42:01 +08:00
|
|
|
import omit from 'rc-util/lib/omit';
|
2022-06-22 14:57:09 +08:00
|
|
|
import * as React from 'react';
|
2022-05-10 15:43:29 +08:00
|
|
|
import warning 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') {
|
2021-01-14 14:32:42 +08:00
|
|
|
return omit(ellipsis as any, ['expandable', 'rows']);
|
2021-01-12 16:46:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ellipsis;
|
|
|
|
}, [ellipsis]);
|
|
|
|
|
2022-05-10 15:43:29 +08:00
|
|
|
warning(
|
2021-01-12 16:46:59 +08:00
|
|
|
typeof ellipsis !== 'object' ||
|
|
|
|
!ellipsis ||
|
|
|
|
(!('expandable' in ellipsis) && !('rows' in ellipsis)),
|
2019-02-27 19:57:48 +08:00
|
|
|
'Typography.Text',
|
2021-01-12 16:46:59 +08:00
|
|
|
'`ellipsis` do not support `expandable` or `rows` props.',
|
2019-02-19 11:42:05 +08:00
|
|
|
);
|
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);
|