From 7658211efe4588b9580e743b692026002e53d3c8 Mon Sep 17 00:00:00 2001 From: Erik Figueiredo Date: Mon, 16 Sep 2024 16:32:04 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20adicionado=20isLoading=20no=20bot=C3=A3?= =?UTF-8?q?o=20e=20resolvido=20zoom=20de=20form=20no=20safari?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/button/index.tsx | 16 ++++++++++++++-- src/components/form/input/input-field.tsx | 2 +- src/components/spinner/index.tsx | 14 ++++++++++++++ src/pages/login.tsx | 8 ++++---- 4 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 src/components/spinner/index.tsx diff --git a/src/components/button/index.tsx b/src/components/button/index.tsx index 9c39830..fa128cf 100644 --- a/src/components/button/index.tsx +++ b/src/components/button/index.tsx @@ -1,14 +1,17 @@ import { ReactNode, HTMLAttributes, HTMLProps, createElement } from 'react' +import { Spinner } from '../spinner' export type ButtonProps = HTMLAttributes & HTMLProps & { children?: ReactNode, type?: "button" | "submit" | "reset", color?: string, + isLoading?: boolean, } -export const Button = ({ children, className, color, ...props }: ButtonProps) => { +export const Button = ({ children, className, color, isLoading, ...props }: ButtonProps) => { let tag = 'button' let localClassName = 'text-white disabled:bg-dark hover:bg-dark font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 transition-all duration-300' + let localChildren = children if (props.href) { tag = 'a' @@ -18,7 +21,16 @@ export const Button = ({ children, className, color, ...props }: ButtonProps) => localClassName = `${localClassName} ${className}` } + if (isLoading) { + localChildren = ( +
+ +
{children}
+
+ ) + } + localClassName = `${localClassName} ${color ? color : `bg-primary`}` - return createElement(tag, { ...props, className: localClassName }, children) + return createElement(tag, { ...props, className: localClassName }, localChildren) } diff --git a/src/components/form/input/input-field.tsx b/src/components/form/input/input-field.tsx index 0b6d286..4174afe 100644 --- a/src/components/form/input/input-field.tsx +++ b/src/components/form/input/input-field.tsx @@ -7,7 +7,7 @@ export type InputFieldProps = { isLoading?: boolean } & InputHTMLAttributes -const classNameTemplate = 'bg-gray-50 border-2 border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white' +const classNameTemplate = 'bg-gray-50 border-2 border-gray-300 text-gray-900 text-md rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white' const classNameErrorTemplate = '!border-red-500 !outline-red-500' export const resolveClassName = ({ className, error }: Partial): string => { diff --git a/src/components/spinner/index.tsx b/src/components/spinner/index.tsx new file mode 100644 index 0000000..0285e88 --- /dev/null +++ b/src/components/spinner/index.tsx @@ -0,0 +1,14 @@ +type SpinnerProps = { + width?: string + height?: string +} + +export const Spinner = ({ width = "w-8", height = "h-8" }: SpinnerProps) => ( +
+ + Loading... +
+) diff --git a/src/pages/login.tsx b/src/pages/login.tsx index 7ade94b..bf9a60f 100644 --- a/src/pages/login.tsx +++ b/src/pages/login.tsx @@ -53,16 +53,16 @@ export const LoginPage = () => { label="Email" type="email" errors={errors} - placeholder='Field with HTML props support' + placeholder='E-mail' /> { errors={errors} /> - +