mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 11:10:01 +08:00
1719748a29
* chore: eslint add consistent-type-imports * fix avatar * Update Item.tsx
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import * as React from 'react';
|
|
import omit from 'rc-util/lib/omit';
|
|
import devWarning from '../_util/devWarning';
|
|
import type { BlockProps, EllipsisConfig } from './Base';
|
|
import Base from './Base';
|
|
|
|
export interface TextProps extends BlockProps {
|
|
ellipsis?: boolean | Omit<EllipsisConfig, 'expandable' | 'rows' | 'onExpand'>;
|
|
onClick?: (e?: React.MouseEvent<HTMLDivElement>) => void;
|
|
}
|
|
|
|
const Text: React.ForwardRefRenderFunction<HTMLSpanElement, TextProps> = (
|
|
{ ellipsis, ...restProps },
|
|
ref,
|
|
) => {
|
|
const mergedEllipsis = React.useMemo(() => {
|
|
if (ellipsis && typeof ellipsis === 'object') {
|
|
return omit(ellipsis as any, ['expandable', 'rows']);
|
|
}
|
|
|
|
return ellipsis;
|
|
}, [ellipsis]);
|
|
|
|
devWarning(
|
|
typeof ellipsis !== 'object' ||
|
|
!ellipsis ||
|
|
(!('expandable' in ellipsis) && !('rows' in ellipsis)),
|
|
'Typography.Text',
|
|
'`ellipsis` do not support `expandable` or `rows` props.',
|
|
);
|
|
|
|
return <Base ref={ref} {...restProps} ellipsis={mergedEllipsis} component="span" />;
|
|
};
|
|
|
|
export default React.forwardRef(Text);
|