WbwDetailCase.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Button, Dropdown } from "antd";
  2. import { MoreOutlined } from "@ant-design/icons";
  3. import { useAppSelector } from "../../../hooks";
  4. import { inlineDict as _inlineDict } from "../../../reducers/inline-dict";
  5. import type { IWbw } from "./WbwWord"
  6. import SelectCase from "../../dict/SelectCase";
  7. import { caseInDict } from "./WbwCase";
  8. import { useIntl } from "react-intl";
  9. interface IWidget {
  10. data: IWbw;
  11. readonly?: boolean;
  12. onChange?: Function;
  13. }
  14. const WbwDetailCaseWidget = ({ data, readonly = false, onChange }: IWidget) => {
  15. const inlineDict = useAppSelector(_inlineDict);
  16. const intl = useIntl();
  17. console.debug("readonly", readonly);
  18. return (
  19. <div style={{ display: "flex", width: "100%" }}>
  20. <SelectCase
  21. readonly={readonly}
  22. value={data.case?.value}
  23. onCaseChange={(value: string) => {
  24. if (typeof onChange !== "undefined") {
  25. onChange(value);
  26. }
  27. }}
  28. />
  29. <Dropdown
  30. trigger={readonly ? [] : ["click"]}
  31. menu={{
  32. items: data.real.value
  33. ? caseInDict(
  34. data.real.value,
  35. inlineDict.wordIndex,
  36. inlineDict.wordList,
  37. intl
  38. )
  39. : [],
  40. onClick: (e) => {
  41. console.log("click ", e.key);
  42. if (typeof onChange !== "undefined") {
  43. onChange(e.key);
  44. }
  45. },
  46. }}
  47. placement="bottomRight"
  48. >
  49. <Button disabled={readonly} type="text" icon={<MoreOutlined />} />
  50. </Dropdown>
  51. </div>
  52. );
  53. };
  54. export default WbwDetailCaseWidget;