-
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.
update: finish button styling and variants
- Loading branch information
Showing
2 changed files
with
71 additions
and
31 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,54 +1,68 @@ | ||
import {Slot} from '@radix-ui/react-slot' | ||
import {cva, type VariantProps} from 'class-variance-authority' | ||
import clsx from 'clsx' | ||
import * as React from 'react' | ||
import { Slot } from "@radix-ui/react-slot"; | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
import clsx from "clsx"; | ||
import * as React from "react"; | ||
|
||
const buttonVariants = cva( | ||
'inline-flex items-center border-[1px] justify-center dark:border-[#050505] border-[#050505] leading-[120%] dark:text-[#fcfcfc] text-[#050505] dark:bg-[#050505] bg-[#fcfcfc] focus:ring-2 focus:ring-offset-2 focus:ring-zinc-800 disabled:opacity-80 disabled:pointer-events-none', | ||
"inline-flex items-center shrink-0 border-[1px] gap-[10px] justify-center hover:button-hover dark:border-[#050505] border-[#050505] leading-[130%] dark:text-[#fcfcfc] text-[#050505] dark:bg-[#050505] bg-[#fcfcfc] focus:ring-2 focus:ring-offset-2 focus:ring-zinc-800 disabled:opacity-70 disabled:pointer-events-none", | ||
{ | ||
variants: { | ||
variant: { | ||
default: '', | ||
destructive: '', | ||
outline: '', | ||
secondary: '', | ||
ghost: '', | ||
loading: 'dark:border-[#050505] border-[#050505]' | ||
default: "", | ||
loading: "dark:border-[#050505] border-[#050505]", | ||
}, | ||
size: { | ||
sm: 'rounded-[2px] py-[3px] px-[6px] text-[12px]', | ||
md: 'rounded-[3px] py-[4px] px-[8px] text-[16px]', | ||
lg: 'rounded-[4px] py-[6px] px-[14px] text-[18px]' | ||
} | ||
sm: "rounded-[2px] py-[3px] px-[6px] text-[10px] h-[20px]", | ||
md: "rounded-[3px] py-[4px] px-[8px] text-[16px] h-[28px]", | ||
lg: "rounded-[4px] py-[6px] px-[14px] text-[18px] h-[36px]", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: 'default', | ||
size: 'md' | ||
} | ||
} | ||
) | ||
variant: "default", | ||
size: "md", | ||
}, | ||
}, | ||
); | ||
|
||
export interface ButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
VariantProps<typeof buttonVariants> { | ||
asChild?: boolean | ||
asChild?: boolean; | ||
} | ||
|
||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
({className, variant, size, asChild = false, ...props}, ref) => { | ||
const Comp = asChild ? Slot : 'button' | ||
({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "button"; | ||
return ( | ||
<> | ||
<Comp | ||
className={clsx(buttonVariants({variant, size, className}))} | ||
className={clsx(buttonVariants({ variant, size, className }))} | ||
ref={ref} | ||
{...props}> | ||
{variant == 'loading' ? '' : props.children} | ||
{...props} | ||
> | ||
{variant === "loading" ? ( | ||
<div | ||
className={clsx("button-loading-animate", { | ||
"size-2 mx-4": size === "sm", | ||
"size-3 mx-5": size === "md", | ||
"size-4 mx-6": size === "lg", | ||
})} | ||
> | ||
<div className="grid grid-cols-2 gap-[20%] size-full"> | ||
<span className="h-full w-full bg-gray-300 rounded-[0.5px]" /> | ||
<span className="h-full w-full bg-gray-400 rounded-[0.5px]" /> | ||
<span className="h-full w-full bg-gray-500 rounded-[0.5px]" /> | ||
<span className="h-full w-full bg-gray-600 rounded-[0.5px]" /> | ||
</div> | ||
</div> | ||
) : ( | ||
props.children | ||
)} | ||
</Comp> | ||
</> | ||
) | ||
} | ||
) | ||
Button.displayName = 'Button' | ||
); | ||
}, | ||
); | ||
Button.displayName = "Button"; | ||
|
||
export {Button, buttonVariants} | ||
export { Button, buttonVariants }; |