refactor: aplatir backend/cloud et frontend/cloud
Le niveau `cloud` etait redondant : il ne reste qu'une seule application. - backend/cloud/* -> backend/*, frontend/cloud/* -> frontend/* - workspaces npm : frontend et backend ; reference tsconfig ./backend - extends tsconfig.base corrige (../ au lieu de ../../) - docker-compose : APP_DIR backend/frontend, montage ./backend/migrations - deploy.yml : reconstruit aussi l'image migrate - chemins mis a jour dans les docs, le Makefile et docker/README.md
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import type { ButtonHTMLAttributes, ReactNode } from "react";
|
||||
import { cn } from "../lib/cn.js";
|
||||
import { Spinner } from "./Spinner.js";
|
||||
import type { SpinnerSize } from "./Spinner.js";
|
||||
|
||||
const variantClasses = {
|
||||
primary: "bg-primary text-primary-foreground hover:bg-primary-hover",
|
||||
secondary: "border border-border-strong bg-surface text-foreground hover:bg-surface-hover",
|
||||
ghost: "text-foreground hover:bg-surface-hover",
|
||||
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive-hover",
|
||||
} as const;
|
||||
|
||||
const sizeClasses = {
|
||||
sm: "h-8 gap-1.5 rounded-sm px-3 text-[0.6875rem]",
|
||||
md: "h-10 gap-2 rounded-md px-4 text-xs",
|
||||
lg: "h-12 gap-2.5 rounded-lg px-6 text-sm",
|
||||
} as const;
|
||||
|
||||
const spinnerBySize: Record<keyof typeof sizeClasses, SpinnerSize> = {
|
||||
sm: "xs",
|
||||
md: "sm",
|
||||
lg: "md",
|
||||
};
|
||||
|
||||
export type ButtonVariant = keyof typeof variantClasses;
|
||||
export type ButtonSize = keyof typeof sizeClasses;
|
||||
|
||||
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: ButtonVariant;
|
||||
size?: ButtonSize;
|
||||
isLoading?: boolean;
|
||||
showTextWhileLoading?: boolean;
|
||||
iconLeading?: ReactNode;
|
||||
iconTrailing?: ReactNode;
|
||||
fullWidth?: boolean;
|
||||
}
|
||||
|
||||
export const Button = ({
|
||||
variant = "primary",
|
||||
size = "md",
|
||||
isLoading = false,
|
||||
showTextWhileLoading = true,
|
||||
iconLeading,
|
||||
iconTrailing,
|
||||
fullWidth = false,
|
||||
disabled,
|
||||
type = "button",
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: ButtonProps) => (
|
||||
<button
|
||||
type={type}
|
||||
disabled={disabled === true || isLoading}
|
||||
aria-busy={isLoading}
|
||||
className={cn(
|
||||
"inline-flex select-none items-center justify-center whitespace-nowrap font-display font-semibold uppercase tracking-label",
|
||||
"focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
||||
"transition-[background-color,border-color,color,box-shadow,opacity]",
|
||||
"disabled:pointer-events-none disabled:opacity-50",
|
||||
variantClasses[variant],
|
||||
sizeClasses[size],
|
||||
fullWidth && "w-full",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{isLoading ? <Spinner size={spinnerBySize[size]} /> : iconLeading}
|
||||
{isLoading && !showTextWhileLoading ? null : children}
|
||||
{isLoading ? null : iconTrailing}
|
||||
</button>
|
||||
);
|
||||
Reference in New Issue
Block a user