bake canonical build harness (deterministic /ship for forks) [dashboard]
This commit is contained in:
@@ -1,53 +1,51 @@
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const variantClasses: Record<string, string> = {
|
||||
default: "bg-indigo-600 text-white hover:bg-indigo-700",
|
||||
secondary: "bg-slate-100 text-slate-900 hover:bg-slate-200",
|
||||
outline: "border border-slate-300 bg-transparent hover:bg-slate-50 text-slate-900",
|
||||
ghost: "bg-transparent hover:bg-slate-100 text-slate-900",
|
||||
destructive: "bg-red-600 text-white hover:bg-red-700",
|
||||
link: "bg-transparent underline-offset-4 hover:underline text-indigo-600",
|
||||
};
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium ring-offset-background transition-all duration-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/90 hover:shadow-md",
|
||||
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
||||
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
||||
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
hero: "bg-primary text-primary-foreground hover:bg-primary/90 hover:shadow-lg hover:-translate-y-0.5 font-medium tracking-wide",
|
||||
heroOutline: "border-2 border-primary text-primary hover:bg-primary hover:text-primary-foreground font-medium tracking-wide",
|
||||
terracotta: "bg-secondary text-secondary-foreground hover:bg-secondary/90 hover:shadow-md",
|
||||
},
|
||||
size: {
|
||||
default: "h-10 px-4 py-2",
|
||||
sm: "h-9 rounded-md px-3",
|
||||
lg: "h-12 rounded-lg px-8 text-base",
|
||||
xl: "h-14 rounded-lg px-10 text-lg",
|
||||
icon: "h-10 w-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const sizeClasses: Record<string, string> = {
|
||||
default: "h-10 px-4 py-2 text-sm",
|
||||
sm: "h-8 px-3 text-xs",
|
||||
lg: "h-12 px-6 text-base",
|
||||
icon: "h-10 w-10 p-0",
|
||||
};
|
||||
|
||||
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: keyof typeof variantClasses;
|
||||
size?: keyof typeof sizeClasses;
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
}
|
||||
|
||||
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant = "default", size = "default", asChild, children, ...props }, ref) => {
|
||||
const classes = cn(
|
||||
"inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors disabled:opacity-50 disabled:pointer-events-none",
|
||||
variantClasses[variant] || variantClasses.default,
|
||||
sizeClasses[size] || sizeClasses.default,
|
||||
className
|
||||
);
|
||||
if (asChild && React.isValidElement(children)) {
|
||||
return React.cloneElement(children as React.ReactElement, {
|
||||
className: cn(classes, (children as React.ReactElement).props?.className),
|
||||
});
|
||||
}
|
||||
return <button ref={ref} className={classes} {...props}>{children}</button>;
|
||||
}
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
return <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />;
|
||||
},
|
||||
);
|
||||
Button.displayName = "Button";
|
||||
|
||||
export function buttonVariants(opts?: { variant?: string; size?: string; className?: string }) {
|
||||
return cn(
|
||||
"inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors",
|
||||
variantClasses[opts?.variant || "default"],
|
||||
sizeClasses[opts?.size || "default"],
|
||||
opts?.className
|
||||
);
|
||||
}
|
||||
|
||||
export default Button;
|
||||
export { Button, buttonVariants };
|
||||
|
||||
Reference in New Issue
Block a user