import PasswordVisible from "@/app/icons/passwordVisible.svg"; import PasswordInvisible from "@/app/icons/passwordInvisible.svg"; import { DetailedHTMLProps, InputHTMLAttributes, useContext, useLayoutEffect, useState, } from "react"; import List, { ListContext } from "@/app/components/List"; export interface CommonInputProps extends Omit< DetailedHTMLProps, HTMLInputElement>, "onChange" | "type" | "value" > { className?: string; } export interface NumberInputProps { onChange?: (v: number) => void; type?: "number"; value?: number; } export interface TextInputProps { onChange?: (v: string) => void; type?: "text" | "password"; value?: string; } export interface InputProps { onChange?: ((v: string) => void) | ((v: number) => void); type?: "text" | "password" | "number"; value?: string | number; } export default function Input( props: CommonInputProps & NumberInputProps, ): JSX.Element; export default function Input( props: CommonInputProps & TextInputProps, ): JSX.Element; export default function Input(props: CommonInputProps & InputProps) { const { value, type = "text", onChange, className, ...rest } = props; const [show, setShow] = useState(false); const { inputClassName } = useContext(ListContext); const internalType = (show && "text") || type; const { update, handleValidate } = useContext(List.ListContext); useLayoutEffect(() => { update?.({ type: "input" }); }, []); useLayoutEffect(() => { handleValidate?.(value); }, [value]); return (
{ if (type === "number") { const v = e.currentTarget.valueAsNumber; (onChange as NumberInputProps["onChange"])?.(v); } else { const v = e.currentTarget.value; (onChange as TextInputProps["onChange"])?.(v); } }} /> {type == "password" && (
setShow((pre) => !pre)}> {show ? : }
)}
); }