import type { AnchorHTMLAttributes, ButtonHTMLAttributes, JSX } from "react";
export type RemiliaLoginVariant =
| "classic"
| "classic-navy"
| "classic-custom"
| "aqua-blue"
| "aqua-white"
| "aqua-custom"
| "material-light"
| "material-dark"
| "material-blue"
| "material-custom";
export type RemiliaLoginLabel = "log-in-with" | "continue-with" | "register-with" | "log-in";
export interface RemiliaLoginOptions {
variant?: RemiliaLoginVariant | undefined;
size?: "sm" | "md" | undefined;
label?: RemiliaLoginLabel | undefined;
isBlock?: boolean | undefined;
isIconOnly?: boolean | undefined;
isPill?: boolean | undefined;
isLogoCentered?: boolean | undefined;
isUppercase?: boolean | undefined;
isSpinOnHover?: boolean | undefined;
isExpandOnHover?: boolean | undefined;
isStill?: boolean | undefined;
}
interface LinkProps extends RemiliaLoginOptions, AnchorHTMLAttributes {
href: string;
}
interface ButtonProps extends RemiliaLoginOptions, ButtonHTMLAttributes {
href?: undefined;
}
export type RemiliaLoginButtonProps = LinkProps | ButtonProps;
interface RemiliaMarkProps {
className?: string | undefined;
}
interface LoginContentProps {
label: RemiliaLoginLabel;
}
const labels: Record = {
"log-in-with": "Log in with RemiliaNET",
"continue-with": "Continue with RemiliaNET",
"register-with": "Register with RemiliaNET",
"log-in": "Log in",
};
export function RemiliaMark({ className }: RemiliaMarkProps): JSX.Element {
return (
);
}
function isLink(props: RemiliaLoginButtonProps): props is LinkProps {
return typeof props.href === "string";
}
function splitOptions(
props: Props,
) {
const {
variant = "classic",
size = "md",
label = "log-in-with",
isBlock = false,
isIconOnly = false,
isPill = false,
isLogoCentered = false,
isUppercase = false,
isSpinOnHover = false,
isExpandOnHover = false,
isStill = false,
className,
...element
} = props;
const classes = [
"remilia-login",
variant !== "classic" && `remilia-login--${variant}`,
size !== "md" && `remilia-login--${size}`,
isBlock && "remilia-login--block",
isIconOnly && "remilia-login--icon",
isPill && "remilia-login--pill",
isLogoCentered && "remilia-login--logo-center",
isUppercase && "remilia-login--uppercase",
isSpinOnHover && "remilia-login--spin",
isExpandOnHover && "remilia-login--expand",
isStill && "remilia-login--still",
className,
].filter((name) => typeof name === "string" && name !== "");
return { className: classes.join(" "), label, element };
}
function LoginContent({ label }: LoginContentProps): JSX.Element {
return (
<>
{labels[label]}
{label === "log-in" && with RemiliaNET}
>
);
}
export function RemiliaLoginButton(props: RemiliaLoginButtonProps): JSX.Element {
if (isLink(props)) {
const { className, label, element } = splitOptions(props);
const isDisabled = element["aria-disabled"] === true || element["aria-disabled"] === "true";
return (
{
if (isDisabled) {
event.preventDefault();
event.stopPropagation();
return;
}
element.onClick?.(event);
}}
className={className}
>
);
}
const { className, label, element } = splitOptions(props);
return (
);
}