sendou.ink/app/components/Button.tsx
Kalle 6feb269193
Full tournament feature WIP (#1196)
* Layout initial

* Add FillRosterSection component

* Move tournaments to feature folder

* Refactor Button props

* SubmitButton

* Register action

* Identifier -> Id

* Invite link via nanoid

* Team info submit

* Enter tiebreaker map list UI

* Invite members to tournament team initial

* Show banner if joined a team not captain of

* Add back teams page

* Change team roster size color when good

* Delete tournament team member
2022-12-21 23:24:59 +02:00

117 lines
2.2 KiB
TypeScript

import { Link } from "@remix-run/react";
import type { LinkProps } from "@remix-run/react";
import clsx from "clsx";
import * as React from "react";
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?:
| "success"
| "outlined"
| "outlined-success"
| "destructive"
| "minimal"
| "minimal-success"
| "minimal-destructive";
size?: "tiny" | "big";
loading?: boolean;
loadingText?: string;
icon?: JSX.Element;
testId?: string;
}
export function Button(props: ButtonProps) {
const {
variant,
loading,
children,
loadingText,
size,
className,
icon,
type = "button",
testId,
...rest
} = props;
return (
<button
className={clsx(
variant,
{
"disabled-opaque": props.disabled,
loading,
tiny: size === "tiny",
big: size === "big",
},
className
)}
disabled={props.disabled || loading}
type={type}
data-testid={testId}
{...rest}
>
{icon &&
React.cloneElement(icon, {
className: clsx("button-icon", { lonely: !children }),
})}
{loading && loadingText ? loadingText : children}
</button>
);
}
type LinkButtonProps = Pick<
ButtonProps,
"variant" | "children" | "className" | "size"
> &
Pick<LinkProps, "to" | "prefetch" | "state"> & { "data-cy"?: string } & {
isExternal?: boolean;
};
export function LinkButton({
variant,
children,
size,
className,
to,
prefetch,
isExternal,
state,
"data-cy": testId,
}: LinkButtonProps) {
if (isExternal) {
return (
<a
className={clsx(
"button",
variant,
{ tiny: size === "tiny", big: size === "big" },
className
)}
href={to as string}
data-cy={testId}
target="_blank"
rel="noreferrer"
>
{children}
</a>
);
}
return (
<Link
className={clsx(
"button",
variant,
{ tiny: size === "tiny", big: size === "big" },
className
)}
to={to}
data-cy={testId}
prefetch={prefetch}
state={state}
>
{children}
</Link>
);
}