2022-10-22 01:17:06 +02:00
|
|
|
/*
|
2025-12-07 21:28:03 +01: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
|
|
|
|
2025-12-07 21:28:03 +01:00
|
|
|
import "./Link.css";
|
2022-10-01 00:42:50 +02:00
|
|
|
|
2025-12-07 21:28:03 +01: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;
|
2026-01-27 15:21:12 +01:00
|
|
|
useDefaultUnderlineStyles?: boolean;
|
2022-10-01 00:42:50 +02:00
|
|
|
}
|
|
|
|
|
|
2026-01-27 15:21:12 +01: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 (
|
2025-12-07 21:28:03 +01:00
|
|
|
<a
|
|
|
|
|
role="link"
|
2026-01-27 15:21:12 +01:00
|
|
|
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
|
|
|
|
|
)}
|
2025-12-07 21:28:03 +01:00
|
|
|
aria-disabled={disabled}
|
|
|
|
|
{...restProps}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
2022-10-01 00:42:50 +02:00
|
|
|
</a>
|
|
|
|
|
);
|
|
|
|
|
}
|