ant-design/components/typography/Link.tsx
Zheeeng 29a15e2a5d
refactor: refines types and fix to use prop direction over context direction (#37716)
* 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
2022-10-18 11:45:43 +08:00

35 lines
992 B
TypeScript

import * as React from 'react';
import warning from '../_util/warning';
import type { BlockProps } from './Base';
import Base from './Base';
export interface LinkProps
extends BlockProps<'a'>,
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'type' | keyof BlockProps<'a'>> {
ellipsis?: boolean;
}
const Link = React.forwardRef<HTMLElement, LinkProps>(({ ellipsis, rel, ...restProps }, ref) => {
warning(
typeof ellipsis !== 'object',
'Typography.Link',
'`ellipsis` only supports boolean value.',
);
const baseRef = React.useRef<any>(null);
React.useImperativeHandle(ref, () => baseRef.current);
const mergedProps = {
...restProps,
rel: rel === undefined && restProps.target === '_blank' ? 'noopener noreferrer' : rel,
};
// @ts-expect-error: https://github.com/ant-design/ant-design/issues/26622
delete mergedProps.navigate;
return <Base {...mergedProps} ref={baseRef} ellipsis={!!ellipsis} component="a" />;
});
export default Link;