2022-05-04 17:09:48 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2022 Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-08-02 00:46:16 +02:00
|
|
|
import React, { HTMLAttributes } from "react";
|
2021-12-13 16:16:25 -08:00
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
import classNames from "classnames";
|
2022-08-02 00:46:16 +02:00
|
|
|
import * as H from "history";
|
2022-06-11 23:21:20 +02:00
|
|
|
|
2022-07-02 21:20:53 +02:00
|
|
|
import {
|
|
|
|
|
variantToClassName,
|
|
|
|
|
sizeToClassName,
|
|
|
|
|
ButtonVariant,
|
|
|
|
|
ButtonSize,
|
|
|
|
|
} from "./Button";
|
2022-08-02 00:46:16 +02:00
|
|
|
|
|
|
|
|
interface Props extends HTMLAttributes<HTMLAnchorElement> {
|
|
|
|
|
children: JSX.Element | string;
|
|
|
|
|
to: H.LocationDescriptor | ((location: H.Location) => H.LocationDescriptor);
|
2022-07-30 10:06:28 +02:00
|
|
|
size?: ButtonSize;
|
2022-08-02 00:46:16 +02:00
|
|
|
variant?: ButtonVariant;
|
|
|
|
|
className?: string;
|
2022-06-11 23:21:20 +02:00
|
|
|
}
|
2021-12-13 16:16:25 -08:00
|
|
|
|
2022-06-11 23:21:20 +02:00
|
|
|
export function LinkButton({
|
|
|
|
|
children,
|
2022-08-02 00:46:16 +02:00
|
|
|
to,
|
|
|
|
|
size,
|
|
|
|
|
variant,
|
|
|
|
|
className,
|
2022-06-11 23:21:20 +02:00
|
|
|
...rest
|
|
|
|
|
}: Props) {
|
2021-12-13 16:16:25 -08:00
|
|
|
return (
|
2021-12-14 16:12:58 -08:00
|
|
|
<Link
|
|
|
|
|
className={classNames(
|
|
|
|
|
variantToClassName[variant || "secondary"],
|
|
|
|
|
sizeToClassName[size],
|
|
|
|
|
className
|
|
|
|
|
)}
|
2022-08-02 00:46:16 +02:00
|
|
|
to={to}
|
2021-12-14 16:12:58 -08:00
|
|
|
{...rest}
|
|
|
|
|
>
|
2021-12-13 16:16:25 -08:00
|
|
|
{children}
|
|
|
|
|
</Link>
|
|
|
|
|
);
|
|
|
|
|
}
|