ZoneFormFields.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 Hint from "../../ui/formUtils/Hint";
  6. import ColorPicker from "../../ui/formUtils/ColorPicker";
  7. import ActionList from "../ActionList";
  8. const interactions = ["reveal", "hide", "revealSelf", "stack"];
  9. const Form = ({ initialValues }) => {
  10. const { t } = useTranslation();
  11. const initOnItem = React.useMemo(
  12. () =>
  13. (initialValues.onItem || []).map((action) => {
  14. if (typeof action === "string") {
  15. return { name: action };
  16. }
  17. return action;
  18. }),
  19. [initialValues.onItem]
  20. );
  21. return (
  22. <>
  23. <Label>
  24. {t("Label")}
  25. <Field
  26. name="label"
  27. component="input"
  28. initialValue={initialValues.label}
  29. />
  30. </Label>
  31. <Label>
  32. {t("Width")}
  33. <Field
  34. name="width"
  35. component="input"
  36. initialValue={initialValues.width}
  37. >
  38. {(props) => <input {...props.input} type="number" />}
  39. </Field>
  40. </Label>
  41. <Label>
  42. {t("Height")}
  43. <Field
  44. name="height"
  45. component="input"
  46. initialValue={initialValues.height}
  47. >
  48. {(props) => <input {...props.input} type="number" />}
  49. </Field>
  50. </Label>
  51. <Label>
  52. {t("Background color")}
  53. <Field
  54. name="backgroundColor"
  55. component="input"
  56. initialValue={initialValues.backgroundColor || "#CCCCCC00"}
  57. >
  58. {({ input: { onChange, value } }) => (
  59. <ColorPicker
  60. value={value}
  61. onChange={onChange}
  62. disableAlpha={false}
  63. />
  64. )}
  65. </Field>
  66. </Label>
  67. <Label>
  68. {t("Border color")}
  69. <Field
  70. name="borderColor"
  71. component="input"
  72. initialValue={initialValues.borderColor || "#CCCCCC33"}
  73. >
  74. {({ input: { onChange, value } }) => (
  75. <ColorPicker
  76. value={value}
  77. onChange={onChange}
  78. disableAlpha={false}
  79. />
  80. )}
  81. </Field>
  82. </Label>
  83. <Label>
  84. {t("Border style")}
  85. <Field
  86. name="borderStyle"
  87. component="select"
  88. initialValue={initialValues.borderStyle || "dotted"}
  89. style={{ width: "10em" }}
  90. >
  91. <option value="dotted">{t("Dotted")}</option>
  92. <option value="Solid">{t("solid")}</option>
  93. <option value="dashed">{t("Dashed")}</option>
  94. </Field>
  95. </Label>
  96. <Label>
  97. {t("Label position")}
  98. <Field
  99. name="labelPosition"
  100. component="select"
  101. initialValue={initialValues.labelPosition || "left"}
  102. style={{ width: "10em" }}
  103. >
  104. <option value="left">{t("Left")}</option>
  105. <option value="top">{t("Top")}</option>
  106. </Field>
  107. </Label>
  108. <h3>{t("Interactions")}</h3>
  109. <Hint>{t("Interaction help")}</Hint>
  110. <Label>
  111. <ActionList
  112. name="onItem"
  113. initialValue={initOnItem}
  114. availableActions={interactions}
  115. />
  116. </Label>
  117. </>
  118. );
  119. };
  120. export default Form;