mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-03 00:09:39 +08:00
29a15e2a5d
* refactor: use enum instead of multiple constants and refines types * fix: siganture and direction prop passing * Update Editable.tsx * refine types * test: update snap * style: prefer literal constants over enum * fix: refine types for typography * fix: restore ellipsis const * fix: restore ellipsis const * fix: restore textare importing
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import omit from 'rc-util/lib/omit';
|
|
import * as React from 'react';
|
|
import warning from '../_util/warning';
|
|
import type { BlockProps, EllipsisConfig } from './Base';
|
|
import Base from './Base';
|
|
|
|
export interface TextProps
|
|
extends BlockProps<'span'>,
|
|
Omit<React.HTMLAttributes<HTMLSpanElement>, 'type' | keyof BlockProps<'span'>> {
|
|
ellipsis?: boolean | Omit<EllipsisConfig, 'expandable' | 'rows' | 'onExpand'>;
|
|
}
|
|
|
|
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]);
|
|
|
|
warning(
|
|
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);
|