46 lines
2.6 KiB
TypeScript
46 lines
2.6 KiB
TypeScript
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(
|
|
// 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-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-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' },
|
|
},
|
|
);
|
|
|
|
export interface ButtonProps extends ComponentProps<'button'>, VariantProps<typeof buttonVariants> {
|
|
asChild?: boolean;
|
|
}
|
|
|
|
export function Button({ className, variant, size, asChild = false, ...props }: ButtonProps) {
|
|
const Comp = asChild ? Slot : 'button';
|
|
return <Comp className={cn(buttonVariants({ variant, size }), className)} {...props} />;
|
|
}
|
|
|
|
export { buttonVariants };
|