From d7252b6c31c58e47e9a2c574bb0f1bd97c1c78b5 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sun, 17 May 2026 14:42:29 +0800 Subject: [PATCH] feat(ui): Button success/warning variants + active translate + icon-xs Polish pass that an earlier edit lost: - Add `success` and `warning` button variants (semantic colour pairs consumers can reach for in confirm dialogs / status actions). - Outline gets a real card background + shadow so it pops on tinted surfaces (previously bg-transparent looked invisible on muted/40 rows). - Tighter motion: explicit transition list + `active:translate-y-px` so clicks feel mechanical. - New size `icon-xs` for inline action buttons that need to fit in a log-row toolbar without ballooning the row height. - Default radius bumped to `rounded-lg`; sm stays `rounded-md`. --- packages/ui/src/components/button.tsx | 34 ++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/packages/ui/src/components/button.tsx b/packages/ui/src/components/button.tsx index 42a436fe..25a16a0c 100644 --- a/packages/ui/src/components/button.tsx +++ b/packages/ui/src/components/button.tsx @@ -4,27 +4,39 @@ import { cva, type VariantProps } from 'class-variance-authority'; import { cn } from '../lib/cn'; export const buttonVariants = cva( - "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/40 focus-visible:border-ring cursor-pointer", + [ + "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium", + "transition-[color,background-color,border-color,box-shadow,transform] duration-150 ease-out", + "disabled:pointer-events-none disabled:opacity-50", + "[&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0", + "outline-none focus-visible:ring-[3px] focus-visible:ring-ring/40 focus-visible:border-ring", + "active:translate-y-px cursor-pointer", + ].join(' '), { variants: { variant: { default: 'bg-primary text-primary-foreground shadow-sm hover:bg-primary/90 active:bg-primary/95', - destructive: 'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90', - outline: 'border border-border bg-transparent 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', + destructive: + 'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90 active:bg-destructive/95', + outline: + 'border border-border bg-card text-foreground shadow-xs hover:bg-accent hover:text-accent-foreground hover:border-border/80', + secondary: 'bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80', + ghost: 'text-foreground hover:bg-accent hover:text-accent-foreground', + link: 'text-primary underline-offset-4 hover:underline shadow-none', + success: 'bg-success text-success-foreground shadow-sm hover:bg-success/90', + warning: 'bg-warning text-warning-foreground shadow-sm hover:bg-warning/90', }, size: { default: 'h-9 px-4 py-2', sm: 'h-8 rounded-md px-3 text-xs', - lg: 'h-10 rounded-md px-6', - icon: 'size-9', - 'icon-sm': 'size-8', + lg: 'h-10 rounded-lg px-6', + icon: 'size-9 rounded-lg', + 'icon-sm': 'size-8 rounded-md', + 'icon-xs': 'size-7 rounded-md', }, }, defaultVariants: { variant: 'default', size: 'default' }, - } + }, ); export interface ButtonProps @@ -37,6 +49,6 @@ export const Button = React.forwardRef( ({ className, variant, size, asChild = false, ...props }, ref) => { const Comp = asChild ? Slot : 'button'; return ; - } + }, ); Button.displayName = 'Button';