2022-05-04 17:09:48 +01:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-05-04 17:09:48 +01:00
|
|
|
|
2025-02-18 17:59:58 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-06 10:22:13 +02:00
|
|
|
Please see LICENSE in the repository root for full details.
|
2022-05-04 17:09:48 +01:00
|
|
|
*/
|
|
|
|
|
|
2025-06-23 22:48:37 -04:00
|
|
|
import { type ComponentProps, type FC } from "react";
|
2024-08-28 08:44:39 -04:00
|
|
|
import { Button } from "@vector-im/compound-web";
|
2022-06-11 23:21:20 +02:00
|
|
|
|
2025-01-06 18:00:20 +01:00
|
|
|
import type { LinkProps } from "react-router-dom";
|
2024-08-28 08:44:39 -04:00
|
|
|
import { useLink } from "./Link";
|
2022-08-02 00:46:16 +02:00
|
|
|
|
2025-06-23 22:48:37 -04:00
|
|
|
type Props = Omit<ComponentProps<typeof Button<"a">>, "as" | "href"> & {
|
|
|
|
|
to: LinkProps["to"];
|
|
|
|
|
state?: unknown;
|
|
|
|
|
};
|
2021-12-13 16:16:25 -08:00
|
|
|
|
2024-08-28 08:44:39 -04:00
|
|
|
/**
|
|
|
|
|
* A version of Compound's button component that acts as a link and integrates
|
|
|
|
|
* with our router setup.
|
|
|
|
|
*/
|
2025-06-23 22:48:37 -04:00
|
|
|
export const LinkButton: FC<Props> = ({ ref, to, state, ...props }) => {
|
|
|
|
|
const [path, onClick] = useLink(to, state);
|
|
|
|
|
return <Button as="a" ref={ref} {...props} href={path} onClick={onClick} />;
|
|
|
|
|
};
|