ant-design/components/typography/Text.tsx
二货爱吃白萝卜 5cc338e177
refactor: All the warning set the warning type for future filter (#44613)
* feat: add warningContext

* refactor: part refactor

* chore: fix compile

* chore: part of it

* chore: part of it

* chore: part of it

* chore: fix lint

* chore: fix test

* chore: clean uo

* chore: hide warning def tmp

* chore: comment test

* chore: fix lint

* chore: refactor select icons

* chore: fix warning message

* test: update test

* chore: rm dead code
2023-09-11 17:28:04 +08:00

43 lines
1.2 KiB
TypeScript

import * as React from 'react';
import omit from 'rc-util/lib/omit';
import { devUseWarning } 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 EllipsisConfig, ['expandable', 'rows']);
}
return ellipsis;
}, [ellipsis]);
if (process.env.NODE_ENV !== 'production') {
const warning = devUseWarning();
warning(
typeof ellipsis !== 'object' ||
!ellipsis ||
(!('expandable' in ellipsis) && !('rows' in ellipsis)),
'Typography.Text',
'usage',
'`ellipsis` do not support `expandable` or `rows` props.',
);
}
return <Base ref={ref} {...restProps} ellipsis={mergedEllipsis} component="span" />;
};
export default React.forwardRef(Text);