sendou.ink/app/components/Button.tsx
Kalle 9312fad90f
Tournament organization page (#1811)
* Initial

* Calendar initial

* Extract EventCalendar

* Events list initial

* Winners

* SQL fixes

* List events by series

* Leaderboards

* Series leaderboard

* Own entry peek

* Edit page skeleton

* RHF initial test

* RHF stuff

* Form etc. progress

* Fix tournament series description

* Fix tabs layout

* Fix socials insert

* Check for not removing admin

* Adding series

* TODOs

* Allow updating org with no series

* FormFieldset

* Allow series without events

* TextAreaFormfield accepting array syntax

* Input form array field

* ToggleFormField

* SelectFormField

* UserSearchFormField

* Fetch badgeOptions

* Badge editing

* Progress

* Use native preventScrollReset

* Rename func

* Fix sticky scroll

* Fix translation

* i18n errors

* handle,meta in edit

* Add ref to user search

* TODOs

* Done
2024-07-25 23:06:29 +03:00

134 lines
2.5 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?: "miniscule" | "tiny" | "big";
loading?: boolean;
loadingText?: string;
icon?: JSX.Element;
testId?: string;
_ref?: React.LegacyRef<HTMLButtonElement> | React.ForwardedRef<unknown>;
}
export function Button(props: ButtonProps) {
const {
variant,
loading,
children,
loadingText,
size,
className,
icon,
type = "button",
testId,
_ref,
...rest
} = props;
return (
<button
className={clsx(
variant,
{
"disabled-opaque": props.disabled,
loading,
tiny: size === "tiny",
big: size === "big",
miniscule: size === "miniscule",
},
className,
)}
disabled={props.disabled || loading}
type={type}
data-testid={testId}
ref={props._ref as React.LegacyRef<HTMLButtonElement>}
{...rest}
>
{icon &&
React.cloneElement(icon, {
className: clsx("button-icon", { lonely: !children }),
})}
{loading && loadingText ? loadingText : children}
</button>
);
}
type LinkButtonProps = Pick<
ButtonProps,
"variant" | "children" | "className" | "size" | "testId" | "icon"
> &
Pick<LinkProps, "to" | "prefetch" | "preventScrollReset"> & {
"data-cy"?: string;
} & {
isExternal?: boolean;
};
export function LinkButton({
variant,
children,
size,
className,
to,
prefetch,
isExternal,
testId,
icon,
preventScrollReset,
}: LinkButtonProps) {
if (isExternal) {
return (
<a
className={clsx(
"button",
variant,
{ tiny: size === "tiny", big: size === "big" },
className,
)}
href={to as string}
data-testid={testId}
target="_blank"
rel="noreferrer"
>
{icon &&
React.cloneElement(icon, {
className: clsx("button-icon", {
lonely: !children,
}),
})}
{children}
</a>
);
}
return (
<Link
className={clsx(
"button",
variant,
{ tiny: size === "tiny", big: size === "big" },
className,
)}
to={to}
data-testid={testId}
prefetch={prefetch}
preventScrollReset={preventScrollReset}
>
{icon &&
React.cloneElement(icon, {
className: clsx("button-icon", { lonely: !children }),
})}
{children}
</Link>
);
}