-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updates button variants and adds slot
- Loading branch information
1 parent
59f74d1
commit fc62b23
Showing
2 changed files
with
72 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,39 @@ | ||
import { Slot } from '@radix-ui/react-slot'; | ||
import { ComponentPropsWithoutRef } from 'react'; | ||
import { VariantProps, tv } from 'tailwind-variants'; | ||
|
||
const button = tv({ | ||
base: 'py-1 px-2 rounded-md transition-all ease-in-out border border-transparent font-medium text-sm disabled:text-gray400 disabled:border-dashed disabled:border-gray400 disabled:bg-transparent disabled:cursor-not-allowed', | ||
base: 'inline-flex gap-2 px-4 py-2 rounded-lg transition-all ease-in-out border border-transparent font-medium transform active:scale-95 disabled:text-gray400 disabled:border-dashed disabled:border-gray400 disabled:bg-transparent disabled:cursor-not-allowed', | ||
variants: { | ||
variant: { | ||
primary: 'bg-wl700 text-white hover:bg-wl900', | ||
primary: 'bg-gray900 text-gray100 hover:bg-gray600', | ||
secondary: | ||
'dark:border-white dark:text-white dark:hover:bg-white dark:hover:text-wl700 border-gray900 text-gray900 hover:bg-gray900 hover:text-wl300', | ||
tertiary: | ||
'text-gray900 hover:text-gray400 dark:text-white dark:hover:text-gray100 disabled:border-transparent', | ||
'dark:border-white dark:text-white dark:hover:bg-white dark:hover:text-wl700 border-gray900 text-gray900 hover:bg-gray900 hover:text-gray100', | ||
highlight: 'bg-wl700 text-white hover:bg-wl900', | ||
link: 'underline-offset-4 hover:underline', | ||
}, | ||
size: { | ||
sm: 'text-sm', | ||
md: 'text-md', | ||
lg: 'text-lg', | ||
icon: 'p-2 text-white', | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: 'primary', | ||
size: 'md', | ||
}, | ||
}); | ||
|
||
type ButtonProps = ComponentPropsWithoutRef<'button'> & VariantProps<typeof button>; | ||
interface ButtonProps extends ComponentPropsWithoutRef<'button'>, VariantProps<typeof button> { | ||
asChild?: boolean; | ||
} | ||
|
||
export function Button({ children, variant, ...props }: ButtonProps) { | ||
export function Button({ children, variant, size, asChild = false, ...props }: ButtonProps) { | ||
const Comp = asChild ? Slot : 'button'; | ||
return ( | ||
<button className={button({ variant })} {...props}> | ||
<Comp className={button({ variant, size })} {...props}> | ||
{children} | ||
</button> | ||
</Comp> | ||
); | ||
} |