Equicord/src/components/Link.tsx

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-10-22 01:17:06 +02:00
/*
* Vencord, a Discord client mod
* Copyright (c) 2025 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
2022-10-22 01:17:06 +02:00
import "./Link.css";
2022-10-01 00:42:50 +02:00
import { classes } from "@utils/misc";
import type { AnchorHTMLAttributes, PropsWithChildren } from "react";
export interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
2022-10-01 00:42:50 +02:00
disabled?: boolean;
useDefaultUnderlineStyles?: boolean;
2022-10-01 00:42:50 +02:00
}
export function Link({
disabled,
useDefaultUnderlineStyles = true,
href,
rel,
target,
className,
children,
...restProps
}: PropsWithChildren<LinkProps>) {
const isInternal = href && /^(?:discord:\/)?\/[a-zA-Z0-9_-]/.test(href);
const needsSafeAttrs = href && !isInternal;
2022-10-01 00:42:50 +02:00
return (
<a
role="link"
href={href}
target={target ?? (needsSafeAttrs ? "_blank" : undefined)}
rel={rel ?? (needsSafeAttrs ? "noreferrer noopener" : undefined)}
className={classes(
"vc-link",
useDefaultUnderlineStyles && "vc-link-underline-on-hover",
disabled && "vc-link-disabled",
className
)}
aria-disabled={disabled}
{...restProps}
>
{children}
2022-10-01 00:42:50 +02:00
</a>
);
}