Equicord/src/components/Link.tsx
prism b7f6e23fff
update and add components (#691)
* update: switch

* add: notice

* update: link

* add: badge

* update heading

* update: basetext

* update: card

* fix: heading

* components-dev: fix

* lint

* update: margins
2026-01-27 09:21:12 -05:00

48 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, PropsWithChildren } from "react";
export interface LinkProps extends AnchorHTMLAttributes<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>
);
}