WbwDetailBookMark.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { useState } from "react";
  2. import type { RadioChangeEvent } from "antd";
  3. import { Radio } from "antd";
  4. import { Input } from "antd";
  5. import type { IWbw } from "./WbwWord"
  6. const { TextArea } = Input;
  7. export const bookMarkColor = ["#fff", "#f99", "#ff9", "#9f9", "#9ff", "#99f"];
  8. interface IWidget {
  9. data: IWbw;
  10. onChange?: Function;
  11. }
  12. const WbwDetailBookMarkWidget = ({ data, onChange }: IWidget) => {
  13. const [value, setValue] = useState("none");
  14. const styleColor: React.CSSProperties = {
  15. display: "inline-block",
  16. width: 28,
  17. height: 18,
  18. };
  19. const options = bookMarkColor.map((item, id) => {
  20. return {
  21. label: (
  22. <span
  23. style={{
  24. ...styleColor,
  25. backgroundColor: item,
  26. }}
  27. ></span>
  28. ),
  29. value: id,
  30. };
  31. });
  32. const onColorChange = ({ target: { value } }: RadioChangeEvent) => {
  33. console.log("radio3 checked", value);
  34. setValue(value);
  35. if (typeof onChange !== "undefined") {
  36. onChange({ field: "bookMarkColor", value: value });
  37. }
  38. };
  39. const onTextChange = (
  40. e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
  41. ) => {
  42. console.log("Change:", e.target.value);
  43. if (typeof onChange !== "undefined") {
  44. onChange({ field: "bookMarkText", value: e.target.value });
  45. }
  46. };
  47. return (
  48. <>
  49. <Radio.Group
  50. options={options}
  51. defaultValue={data.bookMarkColor?.value}
  52. onChange={onColorChange}
  53. value={value}
  54. />
  55. <TextArea
  56. defaultValue={
  57. data.bookMarkText?.value ? data.bookMarkText?.value : undefined
  58. }
  59. showCount
  60. maxLength={512}
  61. autoSize={{ minRows: 6, maxRows: 8 }}
  62. onChange={onTextChange}
  63. />
  64. </>
  65. );
  66. };
  67. export default WbwDetailBookMarkWidget;