2020-05-11 14:28:57 +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
|
|
|
|
extends BlockProps,
|
|
|
|
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'type'> {
|
|
|
|
ellipsis?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Link: React.ForwardRefRenderFunction<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.',
|
|
|
|
);
|
|
|
|
|
2022-01-18 14:13:41 +08:00
|
|
|
const baseRef = React.useRef<any>(null);
|
2020-05-11 14:28:57 +08:00
|
|
|
|
2022-01-18 14:13:41 +08:00
|
|
|
React.useImperativeHandle(ref, () => baseRef.current);
|
2020-05-11 14:28:57 +08:00
|
|
|
|
|
|
|
const mergedProps = {
|
|
|
|
...restProps,
|
|
|
|
rel: rel === undefined && restProps.target === '_blank' ? 'noopener noreferrer' : rel,
|
|
|
|
};
|
|
|
|
|
2020-09-07 17:37:49 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/26622
|
|
|
|
// @ts-ignore
|
|
|
|
delete mergedProps.navigate;
|
|
|
|
|
2020-05-11 14:28:57 +08:00
|
|
|
return <Base {...mergedProps} ref={baseRef} ellipsis={!!ellipsis} component="a" />;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default React.forwardRef(Link);
|