From 4d95159c4f22756d944160cc91e0b7529ce0b2f0 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Thu, 2 Apr 2026 12:46:45 +0300 Subject: [PATCH] feat(RegisterForm): add custom input and button components support with component as prop pattern --- .../auth/ui/RegisterForm/RegisterForm.tsx | 109 ++++++++++++++---- 1 file changed, 84 insertions(+), 25 deletions(-) diff --git a/src/features/auth/ui/RegisterForm/RegisterForm.tsx b/src/features/auth/ui/RegisterForm/RegisterForm.tsx index f12da9f..6a34c74 100644 --- a/src/features/auth/ui/RegisterForm/RegisterForm.tsx +++ b/src/features/auth/ui/RegisterForm/RegisterForm.tsx @@ -1,22 +1,45 @@ -import { useState, type ChangeEvent, type SubmitEvent } from "react"; import { + cloneElement, + useState, + type ChangeEvent, + type ReactElement, + type SubmitEvent, +} from "react"; +import { + selectEmail, selectFormValid, + selectPassword, selectStatusIsLoading, useAuthStore, } from "../../model"; +import { + DefaultInputComponent, + type InputAttributes, +} from "../DefaultInput/DefaultInput"; +import { + DefaultButtonComponent, + type ButtonAttributes, +} from "../DefaultButton/DefaultButton"; + +export interface Props { + InputComponent?: ReactElement; + ButtonComponent?: ReactElement; +} /** * Register form component */ -export function RegisterForm() { - const { formData, setEmail, setPassword, register } = useAuthStore(); +export function RegisterForm({ InputComponent, ButtonComponent }: Props) { + const { setEmail, setPassword, register } = useAuthStore(); + const email = useAuthStore(selectEmail); + const password = useAuthStore(selectPassword); const [confirmedPassword, setConfirmedPassword] = useState(""); const formValid = useAuthStore(selectFormValid); const isLoading = useAuthStore(selectStatusIsLoading); - const passwordMatch = formData?.password?.value === confirmedPassword; + const passwordMatch = password === confirmedPassword; const disabled = isLoading || !formValid || !passwordMatch; const handleEmailChange = (e: ChangeEvent) => { @@ -38,27 +61,63 @@ export function RegisterForm() { return (
- - - - + {/* EMAIL */} + {InputComponent ? ( + cloneElement(InputComponent, { + value: email, + onChange: handleEmailChange, + "aria-label": "Email", + }) + ) : ( + + )} + + {/* PASSWORD */} + {InputComponent ? ( + cloneElement(InputComponent, { + value: password, + onChange: handlePasswordChange, + "aria-label": "Password", + }) + ) : ( + + )} + {/* PASSWORD */} + {InputComponent ? ( + cloneElement(InputComponent, { + value: confirmedPassword, + onChange: handleConfirmChange, + "aria-label": "Confirm", + }) + ) : ( + + )} + {/* BUTTON */} + {ButtonComponent ? ( + cloneElement(ButtonComponent, { + type: "submit", + disabled: disabled, + }) + ) : ( + + Register + + )} ); }