BagFormFields.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import React from "react";
  2. import { useTranslation } from "react-i18next";
  3. import { Field } from "react-final-form";
  4. import Label from "../../ui/formUtils/Label";
  5. import { ImageField } from "../../mediaLibrary";
  6. import Hint from "../../ui/formUtils/Hint";
  7. import ColorPicker from "../../ui/formUtils/ColorPicker";
  8. import ActionList from "../ActionList";
  9. const interactions = ["reveal", "hide", "revealSelf", "stack"];
  10. const Form = ({ initialValues }) => {
  11. const { t } = useTranslation();
  12. return (
  13. <>
  14. <Label>
  15. {t("Accepted families")}
  16. <Field
  17. name="families"
  18. component="input"
  19. format={(val) => val && val.join(",")}
  20. parse={(val) => val && val.split(",").map((v) => v.trim())}
  21. initialValue={initialValues.families || []}
  22. />
  23. <Hint>
  24. {t(
  25. "Let this field empty to accept all items, " +
  26. "or set a comma separated list of families that will be accepted by the bag."
  27. )}
  28. </Hint>
  29. </Label>
  30. <Label>
  31. {t("Label")}
  32. <Field
  33. name="label"
  34. component="input"
  35. initialValue={initialValues.label}
  36. />
  37. </Label>
  38. <Label>
  39. {t("Label position")}
  40. <Field
  41. name="labelPosition"
  42. component="select"
  43. initialValue={initialValues.labelPosition || "left"}
  44. style={{ width: "10em" }}
  45. >
  46. <option value="left">{t("Left")}</option>
  47. <option value="top">{t("Top")}</option>
  48. </Field>
  49. </Label>
  50. <Label>
  51. {t("Label background color")}
  52. <Field
  53. name="labelBackgroundColor"
  54. component="input"
  55. initialValue={initialValues.labelBackgroundColor || "#CCCCCC33"}
  56. >
  57. {({ input: { onChange, value } }) => (
  58. <ColorPicker
  59. value={value}
  60. onChange={onChange}
  61. disableAlpha={false}
  62. />
  63. )}
  64. </Field>
  65. </Label>
  66. <Label>
  67. {t("Width")}
  68. <Field
  69. name="width"
  70. component="input"
  71. initialValue={initialValues.width}
  72. >
  73. {(props) => <input {...props.input} type="number" />}
  74. </Field>
  75. </Label>
  76. <Label>
  77. {t("Height")}
  78. <Field
  79. name="height"
  80. component="input"
  81. initialValue={initialValues.height}
  82. >
  83. {(props) => <input {...props.input} type="number" />}
  84. </Field>
  85. </Label>
  86. <Label>
  87. {t("Empty bag image")}
  88. <Field name="emptyBagImage" initialValue={initialValues.emptyBagImage}>
  89. {({ input: { value, onChange } }) => {
  90. return <ImageField value={value} onChange={onChange} />;
  91. }}
  92. </Field>
  93. </Label>
  94. <Label>
  95. {t("Full bag image")}
  96. <Field name="bagImage" initialValue={initialValues.bagImage}>
  97. {({ input: { value, onChange } }) => {
  98. return <ImageField value={value} onChange={onChange} />;
  99. }}
  100. </Field>
  101. </Label>
  102. <Label>
  103. {t("Counter visible")}
  104. <Field
  105. name="countervisible"
  106. component="input"
  107. type="checkbox"
  108. initialValue={initialValues.countervisible}
  109. />
  110. <Hint>{t("Check it to make bag counter visible")}</Hint>
  111. </Label>
  112. <Label>
  113. {t("Counter size")}
  114. <Field
  115. name="countersize"
  116. component="input"
  117. initialValue={initialValues.countersize}
  118. >
  119. {(props) => <input {...props.input} type="number" />}
  120. </Field>
  121. </Label>
  122. </>
  123. );
  124. };
  125. export default Form;