From 58b4cb82966198b007708e3d561fa68c0fee9379 Mon Sep 17 00:00:00 2001 From: Mariana Sartorato Date: Mon, 1 Jul 2024 20:47:25 -0300 Subject: [PATCH] feat(#38): add button component from radix/shadcn --- dashboard/package.json | 3 +- dashboard/pnpm-lock.yaml | 9 +++-- dashboard/src/components/ui/button.tsx | 56 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 dashboard/src/components/ui/button.tsx diff --git a/dashboard/package.json b/dashboard/package.json index 2a7fefa..4d381c3 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -23,9 +23,10 @@ "@radix-ui/react-label": "^2.1.0", "@radix-ui/react-navigation-menu": "^1.2.0", "@radix-ui/react-separator": "^1.1.0", + "@radix-ui/react-slot": "^1.1.0", "@tanstack/react-query": "^5.45.1", - "@vitejs/plugin-react": "^4.3.1", "@tanstack/react-table": "^8.17.3", + "@vitejs/plugin-react": "^4.3.1", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", "flat": "^6.0.1", diff --git a/dashboard/pnpm-lock.yaml b/dashboard/pnpm-lock.yaml index 5c07192..4a99b4e 100644 --- a/dashboard/pnpm-lock.yaml +++ b/dashboard/pnpm-lock.yaml @@ -32,15 +32,18 @@ importers: '@radix-ui/react-separator': specifier: ^1.1.0 version: 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-slot': + specifier: ^1.1.0 + version: 1.1.0(@types/react@18.3.3)(react@18.3.1) '@tanstack/react-query': specifier: ^5.45.1 version: 5.45.1(react@18.3.1) - '@vitejs/plugin-react': - specifier: ^4.3.1 - version: 4.3.1(vite@5.3.1(@types/node@20.14.8)) '@tanstack/react-table': specifier: ^8.17.3 version: 8.17.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@vitejs/plugin-react': + specifier: ^4.3.1 + version: 4.3.1(vite@5.3.1(@types/node@20.14.8)) class-variance-authority: specifier: ^0.7.0 version: 0.7.0 diff --git a/dashboard/src/components/ui/button.tsx b/dashboard/src/components/ui/button.tsx new file mode 100644 index 0000000..7a957e3 --- /dev/null +++ b/dashboard/src/components/ui/button.tsx @@ -0,0 +1,56 @@ +import * as React from "react" +import { Slot } from "@radix-ui/react-slot" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const buttonVariants = cva( + "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-950 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 dark:ring-offset-slate-950 dark:focus-visible:ring-slate-300", + { + variants: { + variant: { + default: "bg-slate-900 text-slate-50 hover:bg-slate-900/90 dark:bg-slate-50 dark:text-slate-900 dark:hover:bg-slate-50/90", + destructive: + "bg-red-500 text-slate-50 hover:bg-red-500/90 dark:bg-red-900 dark:text-slate-50 dark:hover:bg-red-900/90", + outline: + "border border-slate-200 bg-white hover:bg-slate-100 hover:text-slate-900 dark:border-slate-800 dark:bg-slate-950 dark:hover:bg-slate-800 dark:hover:text-slate-50", + secondary: + "bg-slate-100 text-slate-900 hover:bg-slate-100/80 dark:bg-slate-800 dark:text-slate-50 dark:hover:bg-slate-800/80", + ghost: "hover:bg-slate-100 hover:text-slate-900 dark:hover:bg-slate-800 dark:hover:text-slate-50", + link: "text-slate-900 underline-offset-4 hover:underline dark:text-slate-50", + }, + size: { + default: "h-10 px-4 py-2", + sm: "h-9 rounded-md px-3", + lg: "h-11 rounded-md px-8", + icon: "h-10 w-10", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, + } +) + +export interface ButtonProps + extends React.ButtonHTMLAttributes, + VariantProps { + asChild?: boolean +} + +const Button = React.forwardRef( + ({ className, variant, size, asChild = false, ...props }, ref) => { + const Comp = asChild ? Slot : "button" + return ( + + ) + } +) +Button.displayName = "Button" + +export { Button, buttonVariants }