2019-02-19 11:42:05 +08:00
|
|
|
import * as React from 'react';
|
2021-01-14 14:42:01 +08:00
|
|
|
import omit from 'rc-util/lib/omit';
|
2020-05-14 15:57:04 +08:00
|
|
|
import devWarning from '../_util/devWarning';
|
2021-01-12 16:46:59 +08:00
|
|
|
import Base, { BlockProps, EllipsisConfig } from './Base';
|
2019-02-19 11:42:05 +08:00
|
|
|
|
2019-06-07 12:30:47 +08:00
|
|
|
export interface TextProps extends BlockProps {
|
2021-01-12 16:46:59 +08:00
|
|
|
ellipsis?: boolean | Omit<EllipsisConfig, 'expandable' | 'rows' | 'onExpand'>;
|
2019-02-19 11:42:05 +08:00
|
|
|
}
|
|
|
|
|
2020-03-28 11:56:57 +08:00
|
|
|
const Text: React.FC<TextProps> = ({ ellipsis, ...restProps }) => {
|
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]);
|
|
|
|
|
2020-05-14 15:57:04 +08:00
|
|
|
devWarning(
|
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
|
|
|
|
|
|
|
return <Base {...restProps} ellipsis={mergedEllipsis} component="span" />;
|
2019-02-19 11:42:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Text;
|