forked from rajun/ar-test
refactor: restyle button with theme variants and sizes
This commit is contained in:
parent
a7091c126a
commit
7ecead13d8
@ -1,52 +1,45 @@
|
|||||||
import * as React from 'react';
|
import type { ComponentProps } from 'react';
|
||||||
import { Slot } from '@radix-ui/react-slot';
|
import { Slot } from '@radix-ui/react-slot';
|
||||||
import { cva, type VariantProps } from 'class-variance-authority';
|
import { cva, type VariantProps } from 'class-variance-authority';
|
||||||
import { cn } from '~/lib/utils';
|
import { cn } from '~/lib/utils';
|
||||||
|
|
||||||
const buttonVariants = cva(
|
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: {
|
variants: {
|
||||||
variant: {
|
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)]',
|
default: 'bg-primary font-semibold text-primary-foreground shadow-[0_4px_14px] shadow-primary/25 hover:bg-primary-hover aria-busy:bg-accent-600',
|
||||||
destructive: 'bg-red-500/10 text-red-500 border border-red-500/20 hover:bg-red-500 hover:text-white',
|
success: 'bg-success-strong font-semibold text-primary-foreground shadow-[0_4px_14px] shadow-success-strong/25',
|
||||||
outline: 'border border-neutral-800 bg-[#121212] text-neutral-400 hover:bg-neutral-900 hover:text-white hover:border-orange-500/40',
|
secondary: 'bg-surface-control font-medium text-text-primary ring-1 ring-inset ring-border-control hover:bg-surface-hover',
|
||||||
secondary: 'bg-neutral-800 text-neutral-300 hover:bg-neutral-750 hover:text-white',
|
destructive: 'bg-surface-control font-medium text-danger ring-1 ring-inset ring-border-control hover:bg-surface-hover',
|
||||||
ghost: 'hover:bg-neutral-850 hover:text-white text-neutral-400',
|
ghost: 'font-medium text-text-subtle hover:bg-surface-hover hover:text-text-primary',
|
||||||
link: 'text-orange-500 underline-offset-4 hover:underline',
|
link: 'h-auto px-0 font-medium text-primary hover:text-primary-hover',
|
||||||
|
'link-muted': 'text-text-secondary hover:text-primary',
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
default: 'h-10 px-5 py-2.5',
|
default: 'h-9 rounded-control px-4',
|
||||||
sm: 'h-8 rounded-lg px-3 text-xs',
|
sm: 'h-8 rounded-item px-3 text-xs',
|
||||||
lg: 'h-12 rounded-xl px-8 text-base',
|
lg: 'h-11 rounded-control px-6',
|
||||||
icon: 'h-9 w-9 rounded-lg',
|
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: {
|
defaultVariants: { variant: 'default', size: 'default' },
|
||||||
variant: 'default',
|
|
||||||
size: 'default',
|
|
||||||
},
|
},
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
export interface ButtonProps
|
export interface ButtonProps extends ComponentProps<'button'>, VariantProps<typeof buttonVariants> {
|
||||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
||||||
VariantProps<typeof buttonVariants> {
|
|
||||||
asChild?: boolean;
|
asChild?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
export function Button({ className, variant, size, asChild = false, ...props }: ButtonProps) {
|
||||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
||||||
const Comp = asChild ? Slot : 'button';
|
const Comp = asChild ? Slot : 'button';
|
||||||
return (
|
return <Comp className={cn(buttonVariants({ variant, size }), className)} {...props} />;
|
||||||
<Comp
|
|
||||||
className={cn(buttonVariants({ variant, size, className }))}
|
|
||||||
ref={ref}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
Button.displayName = 'Button';
|
|
||||||
|
|
||||||
export { Button, buttonVariants };
|
export { buttonVariants };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user