Button
Bouton avec variantes et tailles. buttonVariants() s'applique aussi à un lien.
Installe aussi : utils
npx @apps/nexi-ui add buttonimport type { ComponentProps } from "react";
import { cn, variants, type VariantProps } from "@/lib/utils";
export const buttonVariants = variants({
base: cn(
"inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium",
"transition-colors select-none cursor-pointer",
"outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
"disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50",
"[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
),
variants: {
variant: {
primary: "bg-primary text-primary-foreground hover:bg-primary/90",
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
outline: "border border-input bg-background hover:bg-muted",
ghost: "hover:bg-muted",
danger: "bg-danger text-danger-foreground hover:bg-danger/90",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
sm: "h-8 px-3 text-xs",
md: "h-9 px-4",
lg: "h-10 px-6",
icon: "size-9",
},
},
defaults: { variant: "primary", size: "md" },
});
export type ButtonProps = ComponentProps<"button"> & VariantProps<typeof buttonVariants>;
/**
* Bouton. Pour un lien qui ressemble à un bouton :
* `<Link href="/" className={buttonVariants({ variant: "outline" })}>…</Link>`.
*/
export function Button({ variant, size, className, type = "button", ...props }: ButtonProps) {
return (
<button
type={type}
data-slot="button"
className={buttonVariants({ variant, size, className })}
{...props}
/>
);
}