AnchorCard.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { useIntl } from "react-intl";
  2. import { useState } from "react";
  3. import { Card, Space, Segmented } from "antd";
  4. import store from "../../store";
  5. import { modeChange } from "../../reducers/article-mode";
  6. import { ArticleMode } from "../article/Article";
  7. interface IWidgetArticleCard {
  8. children?: React.ReactNode;
  9. onModeChange?: Function;
  10. }
  11. const Widget = ({ children, onModeChange }: IWidgetArticleCard) => {
  12. const intl = useIntl();
  13. const [mode, setMode] = useState<string>("read");
  14. const modeSwitch = (
  15. <Segmented
  16. size="middle"
  17. options={[
  18. {
  19. label: intl.formatMessage({ id: "buttons.translate" }),
  20. value: "edit",
  21. },
  22. {
  23. label: intl.formatMessage({ id: "buttons.wbw" }),
  24. value: "wbw",
  25. },
  26. ]}
  27. value={mode}
  28. onChange={(value) => {
  29. const newMode = value.toString();
  30. if (typeof onModeChange !== "undefined") {
  31. if (mode === "read" || newMode === "read") {
  32. onModeChange(newMode);
  33. }
  34. }
  35. setMode(newMode);
  36. //发布mode变更
  37. store.dispatch(modeChange(newMode as ArticleMode));
  38. }}
  39. />
  40. );
  41. return (
  42. <Card
  43. size="small"
  44. title={<Space>{"title"}</Space>}
  45. extra={<Space>{modeSwitch}</Space>}
  46. >
  47. {children}
  48. </Card>
  49. );
  50. };
  51. export default Widget;