Skip to content

Instantly share code, notes, and snippets.

@jacobparis
Last active December 14, 2024 14:43
Show Gist options
  • Save jacobparis/b4b8466f5e988103e33f576ea91993ff to your computer and use it in GitHub Desktop.
Save jacobparis/b4b8466f5e988103e33f576ea91993ff to your computer and use it in GitHub Desktop.
replace default button variant with primary
@@ -1,7 +1,7 @@
import { Slot } from '@radix-ui/react-slot';
-import { cva, type VariantProps } from 'class-variance-authority';
+import { cva, type VariantProps } from 'class-variance-authority';
import * as React from 'react';
-import { cn } from '#app/utils/misc.ts';
+import { cn } from '#app/utils/misc.js';
const buttonVariants = cva(
- 'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50',
+ 'inline-flex cursor-default font-mono items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors 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]:shrink-0',
{
variants: {
variant: {
- default: 'bg-primary text-primary-foreground shadow hover:bg-primary/90',
- destructive: 'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90',
- outline:
- 'border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground',
- secondary:
- 'bg-secondary text-secondary-foreground shadow-sm hover:brightness-95 transition-all',
+ primary: 'bg-primary text-primary-foreground hover:bg-primary/90',
+ 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',
},
@@ -12,15 +12,13 @@
default: 'h-9 px-3 py-2',
- line: 'h-8 px-3 w-full justify-start',
- sm: 'h-8 px-3 text-xs',
- lg: 'h-10 px-8',
- icon: 'h-9 w-9',
+ sm: 'h-6 rounded-md px-2',
+ lg: 'h-11 rounded-md px-8',
+ icon: 'h-8 w-8',
},
},
defaultVariants: {
- variant: 'default',
size: 'default',
},
},
);
export type ButtonProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'type'> &
@@ -32,10 +30,9 @@
const Button = ({ className, variant, size, asChild = false, ...props }: ButtonProps) => {
const Comp = asChild ? Slot : 'button';
return <Comp className={cn(buttonVariants({ variant, size, className }))} {...props} />;
};
-
+
Button.displayName = 'Button';
export { Button, buttonVariants };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment