StringInput.tsx 956 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React, { useContext, useEffect } from "react";
  2. import InputRow from "../../values-form/InputRow";
  3. import useFormField from "../hooks/useFormField";
  4. import { StringInputField, StringInputFieldState } from "../types";
  5. interface Props extends StringInputField {
  6. id: string;
  7. }
  8. const StringInput: React.FC<Props> = ({
  9. id,
  10. label,
  11. required,
  12. placeholder,
  13. info,
  14. }) => {
  15. const { state, updateState } = useFormField<StringInputFieldState>(id, {
  16. value: "",
  17. });
  18. // TODO: needs a loading wrapper
  19. if (state == undefined) {
  20. return <></>;
  21. }
  22. return (
  23. <InputRow
  24. width="100%"
  25. type="text"
  26. value={state.value}
  27. setValue={(x: string) => {
  28. updateState((prev) => {
  29. return {
  30. ...prev,
  31. value: x,
  32. };
  33. });
  34. }}
  35. label={label}
  36. isRequired={required}
  37. placeholder={placeholder}
  38. info={info}
  39. />
  40. );
  41. };
  42. export default StringInput;