2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2022-05-10 15:43:29 +08:00
|
|
|
import warning from '../_util/warning';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { BlockProps } from './Base';
|
|
|
|
import Base from './Base';
|
2020-05-11 14:28:57 +08:00
|
|
|
|
|
|
|
export interface LinkProps
|
2022-10-18 11:45:43 +08:00
|
|
|
extends BlockProps<'a'>,
|
|
|
|
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'type' | keyof BlockProps<'a'>> {
|
2020-05-11 14:28:57 +08:00
|
|
|
ellipsis?: boolean;
|
|
|
|
}
|
|
|
|
|
2022-10-18 11:45:43 +08:00
|
|
|
const Link = React.forwardRef<HTMLElement, LinkProps>(({ ellipsis, rel, ...restProps }, ref) => {
|
2022-05-10 15:43:29 +08:00
|
|
|
warning(
|
2020-05-11 14:28:57 +08:00
|
|
|
typeof ellipsis !== 'object',
|
|
|
|
'Typography.Link',
|
|
|
|
'`ellipsis` only supports boolean value.',
|
|
|
|
);
|
|
|
|
|
|
|
|
const mergedProps = {
|
|
|
|
...restProps,
|
|
|
|
rel: rel === undefined && restProps.target === '_blank' ? 'noopener noreferrer' : rel,
|
|
|
|
};
|
|
|
|
|
2022-10-18 11:45:43 +08:00
|
|
|
// @ts-expect-error: https://github.com/ant-design/ant-design/issues/26622
|
2020-09-07 17:37:49 +08:00
|
|
|
delete mergedProps.navigate;
|
|
|
|
|
2022-10-23 16:05:31 +08:00
|
|
|
return <Base {...mergedProps} ref={ref} ellipsis={!!ellipsis} component="a" />;
|
2022-10-18 11:45:43 +08:00
|
|
|
});
|
2020-05-11 14:28:57 +08:00
|
|
|
|
2022-10-18 11:45:43 +08:00
|
|
|
export default Link;
|