ImageFormFields.jsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React from "react";
  2. import { Field } from "react-final-form";
  3. import { useTranslation } from "react-i18next";
  4. import Label from "../../ui/formUtils/Label";
  5. import { ImageField } from "../../mediaLibrary";
  6. const ImageForm = ({ initialValues }) => {
  7. const { t } = useTranslation();
  8. return (
  9. <>
  10. <Label>
  11. {t("Label")}
  12. <Field
  13. name="label"
  14. component="input"
  15. initialValue={initialValues.label}
  16. />
  17. </Label>
  18. <Label>
  19. {t("Text")}
  20. <Field
  21. name="text"
  22. component="input"
  23. initialValue={initialValues.text}
  24. />
  25. </Label>
  26. <Label>
  27. {t("Back Text")}
  28. <Field
  29. name="backText"
  30. component="input"
  31. initialValue={initialValues.backText}
  32. />
  33. </Label>
  34. <Label>
  35. {t("Width")}
  36. <Field
  37. name="width"
  38. component="input"
  39. initialValue={initialValues.width}
  40. >
  41. {(props) => <input {...props.input} type="number" />}
  42. </Field>
  43. </Label>
  44. <Label>
  45. {t("Height")}
  46. <Field
  47. name="height"
  48. component="input"
  49. initialValue={initialValues.height}
  50. >
  51. {(props) => <input {...props.input} type="number" />}
  52. </Field>
  53. </Label>
  54. <Label>
  55. {t("Front image")}
  56. <Field name="content" initialValue={initialValues.content}>
  57. {({ input: { value, onChange } }) => {
  58. return <ImageField value={value} onChange={onChange} />;
  59. }}
  60. </Field>
  61. </Label>
  62. <Label>
  63. {t("Back image")}
  64. <Field name="backContent" initialValue={initialValues.backContent}>
  65. {({ input: { value, onChange } }) => {
  66. return <ImageField value={value} onChange={onChange} />;
  67. }}
  68. </Field>
  69. </Label>
  70. <Label>
  71. {t("Overlay image")}
  72. <Field
  73. name="overlay.content"
  74. initialValue={
  75. initialValues.overlay ? initialValues.overlay.content : ""
  76. }
  77. >
  78. {({ input: { value, onChange } }) => {
  79. return <ImageField value={value} onChange={onChange} />;
  80. }}
  81. </Field>
  82. </Label>
  83. </>
  84. );
  85. };
  86. export default ImageForm;