Skip to content

Commit 2f42473

Browse files
authored
chore(types): improve Link types (#8081)
1 parent 1335536 commit 2f42473

File tree

4 files changed

+17
-33
lines changed

4 files changed

+17
-33
lines changed
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import BaseButton from '@node-core/ui-components/Common/BaseButton';
22
import type { ButtonProps } from '@node-core/ui-components/Common/BaseButton';
3-
import type { FC, ComponentProps } from 'react';
3+
import type { FC } from 'react';
44

55
import Link from '#site/components/Link';
66

7-
const Button: FC<
8-
Omit<ButtonProps, 'as'> & Omit<ComponentProps<typeof Link>, 'as' | 'size'>
9-
> = props => <BaseButton as={Link} {...props} />;
7+
const Button: FC<ButtonProps> = props => <BaseButton as={Link} {...props} />;
108

119
export default Button;

apps/site/components/Link.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
import type { FC, HTMLProps } from 'react';
1+
import type { FC, AnchorHTMLAttributes, ComponentProps } from 'react';
22

33
import { Link as LocalizedLink } from '#site/navigation.mjs';
44

5-
const Link: FC<HTMLProps<HTMLAnchorElement>> = ({
6-
children,
7-
href,
8-
...props
9-
}) => {
10-
if (!href || /^https?:/.test(href.toString())) {
11-
return (
12-
<a href={href} {...props}>
13-
{children}
14-
</a>
15-
);
5+
export type LinkProps =
6+
| ComponentProps<typeof LocalizedLink>
7+
| AnchorHTMLAttributes<HTMLAnchorElement>;
8+
9+
const Link: FC<LinkProps> = ({ href, ...props }) => {
10+
if (!href || /^https?:/.test(href as string)) {
11+
return <a href={href as string} {...props} />;
1612
}
1713

18-
return (
19-
<LocalizedLink href={href?.toString()} {...props}>
20-
{children}
21-
</LocalizedLink>
22-
);
14+
return <LocalizedLink href={href} {...props} />;
2315
};
2416

2517
export default Link;

apps/site/components/LinkWithArrow.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { ArrowUpRightIcon } from '@heroicons/react/24/solid';
22
import type { SlotProps } from '@radix-ui/react-slot';
33
import { Slot } from '@radix-ui/react-slot';
4-
import type { ComponentProps, FC, PropsWithChildren } from 'react';
4+
import type { FC, PropsWithChildren } from 'react';
55

66
import Link from '#site/components/Link';
7+
import type { LinkProps } from '#site/components/Link';
78

89
type LinkWithArrowProps =
9-
| ({ asChild?: false } & ComponentProps<typeof Link>)
10+
| ({ asChild?: false } & LinkProps)
1011
| ({ asChild: true } & SlotProps);
1112

1213
const LinkWithArrow: FC<PropsWithChildren<LinkWithArrowProps>> = ({
@@ -17,7 +18,7 @@ const LinkWithArrow: FC<PropsWithChildren<LinkWithArrowProps>> = ({
1718
const Comp = asChild ? Slot : Link;
1819

1920
return (
20-
<Comp {...props}>
21+
<Comp {...(props as SlotProps)}>
2122
<span>
2223
{children}
2324
<ArrowUpRightIcon className="ml-1 inline w-3 fill-neutral-600 dark:fill-white" />

apps/site/components/Releases/MinorReleasesTable/index.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,16 @@ export const MinorReleasesTable: FC<MinorReleasesTableProps> = ({
3636
<td>
3737
<div className={styles.links}>
3838
<Link
39-
kind="neutral"
4039
href={`https://nodejs.org/download/release/v${release.version}/`}
4140
>
4241
{t('components.minorReleasesTable.actions.release')}
4342
</Link>
4443
<Separator orientation="vertical" />
45-
<Link
46-
kind="neutral"
47-
href={`${BASE_CHANGELOG_URL}${release.version}`}
48-
>
44+
<Link href={`${BASE_CHANGELOG_URL}${release.version}`}>
4945
{t('components.minorReleasesTable.actions.changelog')}
5046
</Link>
5147
<Separator orientation="vertical" />
52-
<Link
53-
kind="neutral"
54-
href={getNodeApiUrl(`v${release.version}`)}
55-
>
48+
<Link href={getNodeApiUrl(`v${release.version}`)}>
5649
{t('components.minorReleasesTable.actions.docs')}
5750
</Link>
5851
</div>

0 commit comments

Comments
 (0)