mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
Reworked the stylize tab to save vertical space and improve UX: - Style selection in its own page, easier to navigate through styles and pick them - Generate Movie button now always sticky at bottom of panel so it is not hidden under the fold - Added re-render preview button - Increased positive prompt field size and both positive and negative prompts can be resized. Video: https://cdn.discordapp.com/attachments/1221845845540995164/1243148163821338727/2024-05-23_17-13-50.mp4?ex=66506b72&is=664f19f2&hm=a22a8c8a63123c91f9037717c323032ea585ac95107ec226dda0e41f6f0c6816&  
90 lines
2.8 KiB
TypeScript
90 lines
2.8 KiB
TypeScript
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
import { twMerge } from "tailwind-merge";
|
|
import { ButtonHTMLAttributes } from "react";
|
|
import { faSpinnerThird } from "@fortawesome/pro-solid-svg-icons";
|
|
|
|
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
icon?: IconDefinition;
|
|
iconFlip?: boolean;
|
|
htmlFor?: string;
|
|
variant?: "primary" | "secondary" | "action";
|
|
loading?: boolean;
|
|
}
|
|
|
|
export const Button = ({
|
|
icon,
|
|
children,
|
|
className: propsClassName,
|
|
htmlFor,
|
|
variant: propsVariant = "primary",
|
|
disabled,
|
|
iconFlip = false,
|
|
loading,
|
|
...rest
|
|
}: ButtonProps) => {
|
|
function getVariantClassNames(variant: string) {
|
|
switch (variant) {
|
|
case "secondary": {
|
|
return "bg-brand-secondary hover:bg-brand-secondary-900 text-white focus-visible:outline-brand-secondary";
|
|
}
|
|
case "action": {
|
|
return " bg-action hover:bg-action-500 text-white focus-visible:outline-action";
|
|
}
|
|
case "primary":
|
|
default: {
|
|
return "bg-brand-primary hover:bg-brand-primary-400 text-white focus-visible:outline-brand-primary-600";
|
|
}
|
|
}
|
|
}
|
|
|
|
const disabledClass = twMerge(
|
|
disabled || loading ? "opacity-50 pointer-events-none" : "",
|
|
);
|
|
|
|
const className = twMerge(
|
|
"text-sm font-medium rounded-lg px-3 py-2 shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 transition-all duration-150 flex gap-2 items-center justify-center",
|
|
getVariantClassNames(propsVariant),
|
|
propsClassName,
|
|
disabledClass,
|
|
);
|
|
|
|
// const ButtonType = htmlFor ? "label" : "button";
|
|
if (htmlFor) {
|
|
return (
|
|
<label className={className} htmlFor={htmlFor} style={rest.style}>
|
|
{loading && !iconFlip ? (
|
|
<FontAwesomeIcon icon={faSpinnerThird} className="animate-spin" />
|
|
) : (
|
|
<>{icon && !iconFlip ? <FontAwesomeIcon icon={icon} /> : null}</>
|
|
)}
|
|
{children}
|
|
{loading && iconFlip ? (
|
|
<FontAwesomeIcon icon={faSpinnerThird} className="animate-spin" />
|
|
) : (
|
|
<>{icon && iconFlip ? <FontAwesomeIcon icon={icon} /> : null}</>
|
|
)}
|
|
</label>
|
|
);
|
|
}
|
|
return (
|
|
<button
|
|
className={className}
|
|
disabled={disabled || loading}
|
|
{...{ ...rest, htmlFor }}
|
|
>
|
|
{loading && !iconFlip ? (
|
|
<FontAwesomeIcon icon={faSpinnerThird} className="animate-spin" />
|
|
) : (
|
|
<>{icon && !iconFlip ? <FontAwesomeIcon icon={icon} /> : null}</>
|
|
)}
|
|
{children}
|
|
{loading && iconFlip ? (
|
|
<FontAwesomeIcon icon={faSpinnerThird} className="animate-spin" />
|
|
) : (
|
|
<>{icon && iconFlip ? <FontAwesomeIcon icon={icon} /> : null}</>
|
|
)}
|
|
</button>
|
|
);
|
|
};
|