import { ComponentType, useEffect, useState } from "react"; import { useDebouncedCallback } from "use-debounce"; import { getComponent, registerComponent } from "../../../registries/components"; import { getEventValue } from "../../../utils/getEventValue"; import { cleanFormControlProps, FormControl } from "../form-control/FormControl"; import { InputTextProps } from "./InputText.interface"; function Input(props: InputTextProps) { const { name, id = name, value, onChange, required, type, placeholder, debounceDelay = 300, ...otherProps } = props; const [localValue, setValue] = useState(value); const change = useDebouncedCallback(onChange || (() => {}), debounceDelay); useEffect(() => { setValue(value); }, [value]); return ( { const value = getEventValue(event); setValue(value); return change && change(name, value); }} /> ); } registerComponent("Input", Input); export function InputText(props: InputTextProps) { const { name, id = name, label, required, size, before, after, description, className } = props; const Input = getComponent>>("Input"); return ( ); } registerComponent("InputText", InputText);