chore: rewrite LoginForm to use defaults from separate files
This commit is contained in:
@@ -8,38 +8,23 @@ import {
|
|||||||
import {
|
import {
|
||||||
type SubmitEvent,
|
type SubmitEvent,
|
||||||
type ChangeEvent,
|
type ChangeEvent,
|
||||||
type HTMLAttributes,
|
|
||||||
type InputHTMLAttributes,
|
|
||||||
type ButtonHTMLAttributes,
|
|
||||||
cloneElement,
|
cloneElement,
|
||||||
type ReactElement,
|
type ReactElement,
|
||||||
} from "react";
|
} from "react";
|
||||||
|
import {
|
||||||
export type InputAttributes = InputHTMLAttributes<HTMLInputElement>;
|
DefaultButtonComponent,
|
||||||
export type ButtonAttributes = ButtonHTMLAttributes<HTMLButtonElement>;
|
type ButtonAttributes,
|
||||||
|
} from "../DefaultButton/DefaultButton";
|
||||||
|
import {
|
||||||
|
DefaultInputComponent,
|
||||||
|
type InputAttributes,
|
||||||
|
} from "../DefaultInput/DefaultInput";
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
InputComponent?: ReactElement<InputAttributes>;
|
InputComponent?: ReactElement<InputAttributes>;
|
||||||
ButtonComponent?: ReactElement<ButtonAttributes>;
|
ButtonComponent?: ReactElement<ButtonAttributes>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DefaultInputComponent = ({
|
|
||||||
value,
|
|
||||||
onChange,
|
|
||||||
["aria-label"]: ariaLabel,
|
|
||||||
}: InputAttributes) => (
|
|
||||||
<input
|
|
||||||
type="email"
|
|
||||||
value={value}
|
|
||||||
onChange={onChange}
|
|
||||||
aria-label={ariaLabel}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
const DefaultButtonComponent = ({ disabled }: ButtonAttributes) => (
|
|
||||||
<button type="submit" disabled={disabled} />
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login form component
|
* Login form component
|
||||||
*/
|
*/
|
||||||
@@ -67,9 +52,9 @@ export function LoginForm({ InputComponent, ButtonComponent }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<form aria-label="Login form" onSubmit={handleSubmit}>
|
<form aria-label="Login form" onSubmit={handleSubmit}>
|
||||||
|
{/* EMAIL */}
|
||||||
{InputComponent ? (
|
{InputComponent ? (
|
||||||
cloneElement(InputComponent, {
|
cloneElement(InputComponent, {
|
||||||
type: "email",
|
|
||||||
value: email,
|
value: email,
|
||||||
onChange: handleEmailChange,
|
onChange: handleEmailChange,
|
||||||
"aria-label": "Email",
|
"aria-label": "Email",
|
||||||
@@ -82,9 +67,9 @@ export function LoginForm({ InputComponent, ButtonComponent }: Props) {
|
|||||||
aria-label="Email"
|
aria-label="Email"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{/* PASSWORD */}
|
||||||
{InputComponent ? (
|
{InputComponent ? (
|
||||||
cloneElement(InputComponent, {
|
cloneElement(InputComponent, {
|
||||||
type: "password",
|
|
||||||
value: password,
|
value: password,
|
||||||
onChange: handlePasswordChange,
|
onChange: handlePasswordChange,
|
||||||
"aria-label": "Password",
|
"aria-label": "Password",
|
||||||
@@ -97,14 +82,14 @@ export function LoginForm({ InputComponent, ButtonComponent }: Props) {
|
|||||||
aria-label="Password"
|
aria-label="Password"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{/* BUTTON */}
|
||||||
{ButtonComponent ? (
|
{ButtonComponent ? (
|
||||||
cloneElement(ButtonComponent, {
|
cloneElement(ButtonComponent, {
|
||||||
type: "submit",
|
type: "submit",
|
||||||
disabled: disabled,
|
disabled: disabled,
|
||||||
children: "Login",
|
|
||||||
})
|
})
|
||||||
) : (
|
) : (
|
||||||
<DefaultButtonComponent type="submit" disabled={disabled}>
|
<DefaultButtonComponent disabled={disabled}>
|
||||||
Login
|
Login
|
||||||
</DefaultButtonComponent>
|
</DefaultButtonComponent>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user