From 77ec2fcd3f34480777bfd062ca5fce46eb91ab6c Mon Sep 17 00:00:00 2001 From: arihanv Date: Mon, 10 Jun 2024 17:36:20 -0500 Subject: [PATCH] update: finish button styling and variants --- src/styles.css | 26 ++++++++++++++++ src/ui/button.tsx | 76 ++++++++++++++++++++++++++++------------------- 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/src/styles.css b/src/styles.css index 6d74362..cd0e6c0 100644 --- a/src/styles.css +++ b/src/styles.css @@ -13,4 +13,30 @@ * { @apply font-geist; } + .button-hover { + box-shadow: 0px 0px 0px 2px rgba(5, 5, 5, 0.05); + } + + .button-loading-animate { + animation: loading-rotate 1s steps(1) infinite; + } + + @keyframes loading-rotate { + 0% { + transform: rotate(0deg); + } + 25% { + transform: rotate(90deg); + } + 50% { + transform: rotate(180deg); + } + 75% { + transform: rotate(270deg); + } + 100% { + transform: rotate(360deg); + } + } + } diff --git a/src/ui/button.tsx b/src/ui/button.tsx index 2111e51..c74240d 100644 --- a/src/ui/button.tsx +++ b/src/ui/button.tsx @@ -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, VariantProps { - asChild?: boolean + asChild?: boolean; } const Button = React.forwardRef( - ({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 ( <> - {variant == 'loading' ? '' : props.children} + {...props} + > + {variant === "loading" ? ( +
+
+ + + + +
+
+ ) : ( + props.children + )}
- ) - } -) -Button.displayName = 'Button' + ); + }, +); +Button.displayName = "Button"; -export {Button, buttonVariants} +export { Button, buttonVariants };