From 1f2cd3234047c6af66c7b494d939bc103f8e924f Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 4 Jun 2024 09:12:28 -0300 Subject: [PATCH] Modularized Loading on buttons --- src/frontend/src/components/ui/button.tsx | 35 +++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/components/ui/button.tsx b/src/frontend/src/components/ui/button.tsx index 431287f39..5fee364b4 100644 --- a/src/frontend/src/components/ui/button.tsx +++ b/src/frontend/src/components/ui/button.tsx @@ -2,6 +2,7 @@ import { Slot } from "@radix-ui/react-slot"; import { cva, type VariantProps } from "class-variance-authority"; import * as React from "react"; import { cn } from "../../utils/utils"; +import ForwardedIconComponent from "../genericIconComponent"; const buttonVariants = cva( "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background", @@ -32,13 +33,14 @@ const buttonVariants = cva( variant: "default", size: "default", }, - } + }, ); export interface ButtonProps extends React.ButtonHTMLAttributes, VariantProps { asChild?: boolean; + loading?: boolean; } function toTitleCase(text: string) { @@ -49,21 +51,36 @@ function toTitleCase(text: string) { } const Button = React.forwardRef( - ({ className, variant, size, asChild = false, children, ...props }, ref) => { + ( + { className, variant, size, loading, asChild = false, children, ...props }, + ref, + ) => { const Comp = asChild ? Slot : "button"; let newChildren = children; if (typeof children === "string") { newChildren = toTitleCase(children); } return ( - + +
+ +
+
+ {newChildren} +
+
); - } + }, ); Button.displayName = "Button";