refactor: restyle button with theme variants and sizes

This commit is contained in:
rajun 2026-10-27 16:28:47 +05:30
parent a7091c126a
commit 7ecead13d8

View File

@ -1,52 +1,45 @@
import * as React from 'react';
import type { ComponentProps } from 'react';
import { Slot } from '@radix-ui/react-slot';
import { cva, type VariantProps } from 'class-variance-authority';
import { cn } from '~/lib/utils';
const buttonVariants = cva(
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-xl text-sm font-semibold transition-all duration-200 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-700 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 active:scale-[0.98] cursor-pointer',
// A busy button (aria-busy) is disabled but keeps full colour while it works
'inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap text-sm transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 disabled:pointer-events-none disabled:opacity-40 aria-busy:disabled:opacity-100 [&_svg]:pointer-events-none [&_svg]:shrink-0',
{
variants: {
variant: {
default: 'bg-orange-500 text-black shadow-[0_0_24px_rgba(249,115,22,0.15)] hover:bg-orange-400 hover:shadow-[0_0_32px_rgba(249,115,22,0.3)]',
destructive: 'bg-red-500/10 text-red-500 border border-red-500/20 hover:bg-red-500 hover:text-white',
outline: 'border border-neutral-800 bg-[#121212] text-neutral-400 hover:bg-neutral-900 hover:text-white hover:border-orange-500/40',
secondary: 'bg-neutral-800 text-neutral-300 hover:bg-neutral-750 hover:text-white',
ghost: 'hover:bg-neutral-850 hover:text-white text-neutral-400',
link: 'text-orange-500 underline-offset-4 hover:underline',
default: 'bg-primary font-semibold text-primary-foreground shadow-[0_4px_14px] shadow-primary/25 hover:bg-primary-hover aria-busy:bg-accent-600',
success: 'bg-success-strong font-semibold text-primary-foreground shadow-[0_4px_14px] shadow-success-strong/25',
secondary: 'bg-surface-control font-medium text-text-primary ring-1 ring-inset ring-border-control hover:bg-surface-hover',
destructive: 'bg-surface-control font-medium text-danger ring-1 ring-inset ring-border-control hover:bg-surface-hover',
ghost: 'font-medium text-text-subtle hover:bg-surface-hover hover:text-text-primary',
link: 'h-auto px-0 font-medium text-primary hover:text-primary-hover',
'link-muted': 'text-text-secondary hover:text-primary',
},
size: {
default: 'h-10 px-5 py-2.5',
sm: 'h-8 rounded-lg px-3 text-xs',
lg: 'h-12 rounded-xl px-8 text-base',
icon: 'h-9 w-9 rounded-lg',
default: 'h-9 rounded-control px-4',
sm: 'h-8 rounded-item px-3 text-xs',
lg: 'h-11 rounded-control px-6',
xl: 'h-12.5 rounded-field px-6 text-base shadow-[0_10px_28px] inset-shadow-[0_1px_0] inset-shadow-primary-foreground/20',
// Text-only buttons that sit inline with labels
inline: 'h-auto px-0',
icon: 'h-[30px] w-[30px] rounded-item',
'icon-sm': 'h-[26px] w-[26px] rounded-option',
pill: 'h-[46px] rounded-full px-6 text-base shadow-[0_6px_16px] shadow-shadow/15',
},
},
defaultVariants: {
variant: 'default',
size: 'default',
defaultVariants: { variant: 'default', size: 'default' },
},
}
);
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
export interface ButtonProps extends ComponentProps<'button'>, VariantProps<typeof buttonVariants> {
asChild?: boolean;
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
export function Button({ className, variant, size, asChild = false, ...props }: ButtonProps) {
const Comp = asChild ? Slot : 'button';
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
);
}
);
Button.displayName = 'Button';
return <Comp className={cn(buttonVariants({ variant, size }), className)} {...props} />;
}
export { Button, buttonVariants };
export { buttonVariants };