2019-02-19 11:42:05 +08:00
|
|
|
import * as React from 'react';
|
2021-01-12 16:46:59 +08:00
|
|
|
import omit from 'omit.js';
|
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') {
|
|
|
|
return omit(ellipsis, ['expandable', 'rows']);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|