2023-10-23 23:06:24 +02:00
|
|
|
import classNames from "classnames";
|
2023-02-19 18:36:53 +01:00
|
|
|
import { ReactNode } from "react";
|
2023-10-23 23:06:24 +02:00
|
|
|
import { useHistory } from "react-router-dom";
|
2023-02-19 18:36:53 +01:00
|
|
|
|
2023-04-24 17:41:54 +02:00
|
|
|
import { Icon, Icons } from "@/components/Icon";
|
|
|
|
|
2023-02-19 18:36:53 +01:00
|
|
|
interface Props {
|
|
|
|
icon?: Icons;
|
|
|
|
onClick?: () => void;
|
|
|
|
children?: ReactNode;
|
2023-10-23 23:06:24 +02:00
|
|
|
theme?: "white" | "purple" | "secondary";
|
|
|
|
padding?: string;
|
|
|
|
className?: string;
|
|
|
|
href?: string;
|
2023-02-19 18:36:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function Button(props: Props) {
|
2023-10-23 23:06:24 +02:00
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
let colorClasses = "bg-white hover:bg-gray-200 text-black";
|
|
|
|
if (props.theme === "purple")
|
|
|
|
colorClasses =
|
|
|
|
"bg-video-buttons-purple hover:bg-video-buttons-purpleHover text-white";
|
|
|
|
if (props.theme === "secondary")
|
|
|
|
colorClasses =
|
|
|
|
"bg-video-buttons-cancel hover:bg-video-buttons-cancelHover transition-colors duration-100 text-white";
|
|
|
|
|
|
|
|
const classes = classNames(
|
|
|
|
"cursor-pointer inline-flex items-center justify-center rounded-lg font-medium transition-[transform,background-color] duration-100 active:scale-105 md:px-8",
|
|
|
|
props.padding ?? "px-4 py-3",
|
|
|
|
props.className,
|
|
|
|
colorClasses
|
|
|
|
);
|
|
|
|
|
|
|
|
const content = (
|
|
|
|
<>
|
2023-02-19 18:36:53 +01:00
|
|
|
{props.icon ? (
|
2023-02-19 19:54:34 +01:00
|
|
|
<span className="mr-3 hidden md:inline-block">
|
2023-02-19 18:36:53 +01:00
|
|
|
<Icon icon={props.icon} />
|
|
|
|
</span>
|
|
|
|
) : null}
|
|
|
|
{props.children}
|
2023-10-23 23:06:24 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
function goTo(href: string) {
|
|
|
|
history.push(href);
|
|
|
|
}
|
|
|
|
|
2023-10-24 13:27:10 +02:00
|
|
|
if (props.href && props.href.startsWith("https://"))
|
|
|
|
return (
|
|
|
|
<a className={classes} href={props.href} target="_blank" rel="noreferrer">
|
|
|
|
{content}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
|
2023-10-23 23:06:24 +02:00
|
|
|
if (props.href)
|
|
|
|
return (
|
|
|
|
<a className={classes} onClick={() => goTo(props.href || "")}>
|
|
|
|
{content}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<button type="button" onClick={props.onClick} className={classes}>
|
|
|
|
{content}
|
2023-02-19 18:36:53 +01:00
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
2023-10-24 20:34:54 +02:00
|
|
|
|
|
|
|
interface ButtonPlainProps {
|
|
|
|
onClick?: () => void;
|
|
|
|
children?: ReactNode;
|
|
|
|
theme?: "white" | "purple" | "secondary";
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ButtonPlain(props: ButtonPlainProps) {
|
|
|
|
let colorClasses = "bg-white hover:bg-gray-200 text-black";
|
|
|
|
if (props.theme === "purple")
|
|
|
|
colorClasses =
|
|
|
|
"bg-video-buttons-purple hover:bg-video-buttons-purpleHover text-white";
|
|
|
|
if (props.theme === "secondary")
|
|
|
|
colorClasses =
|
|
|
|
"bg-video-buttons-cancel hover:bg-video-buttons-cancelHover transition-colors duration-100 text-white";
|
|
|
|
|
|
|
|
const classes = classNames(
|
|
|
|
"cursor-pointer inline-flex items-center justify-center rounded-lg font-medium transition-[transform,background-color] duration-100 active:scale-105 md:px-8",
|
|
|
|
"px-4 py-3",
|
|
|
|
props.className,
|
|
|
|
colorClasses
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<button type="button" onClick={props.onClick} className={classes}>
|
|
|
|
{props.children}
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|