Equicord/src/components/Link.tsx
nexpid df890ac455
SongSpotlight: Show off songs on your profile (#853)
* feat(SongSpotlight): port from vencord PR

* feat(SongSpotlight): some slight code improvements

* fix(components): match Link's props with vencord

* fix(SongSpotlight): ditch React.memo & csp
2026-03-02 11:06:18 -05:00

49 lines
1.3 KiB
TypeScript

/*
* Vencord, a Discord client mod
* Copyright (c) 2025 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import "./Link.css";
import { classes } from "@utils/misc";
import type { AnchorHTMLAttributes, DetailedHTMLProps, PropsWithChildren } from "react";
export interface LinkProps extends DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement> {
disabled?: boolean;
useDefaultUnderlineStyles?: boolean;
}
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;
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}
</a>
);
}