RightToolsSwitch.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { Segmented } from "antd";
  2. import { useEffect, useState } from "react";
  3. import { useIntl } from "react-intl";
  4. import { useAppSelector } from "../../hooks";
  5. import { rightPanel } from "../../reducers/right-panel";
  6. import type { TPanelName } from "./RightPanel"
  7. interface IWidget {
  8. initMode?: string;
  9. onModeChange?: Function;
  10. }
  11. const RightToolsSwitchWidget = ({
  12. initMode = "close",
  13. onModeChange,
  14. }: IWidget) => {
  15. const intl = useIntl();
  16. const [mode, setMode] = useState<string>(initMode);
  17. const _openPanel = useAppSelector(rightPanel);
  18. useEffect(() => {
  19. if (typeof _openPanel !== "undefined") {
  20. if (typeof onModeChange !== "undefined") {
  21. onModeChange(_openPanel);
  22. }
  23. setMode(_openPanel);
  24. }
  25. }, [_openPanel]);
  26. return (
  27. <Segmented
  28. size="middle"
  29. style={{
  30. color: "rgb(134 134 134 / 90%)",
  31. backgroundColor: "rgb(129 129 129 / 17%)",
  32. display: "block",
  33. }}
  34. options={[
  35. {
  36. label: intl.formatMessage({ id: "columns.library.dict.title" }),
  37. value: "dict",
  38. },
  39. {
  40. label: intl.formatMessage({ id: "columns.studio.channel.title" }),
  41. value: "channel",
  42. },
  43. {
  44. label: intl.formatMessage({ id: "buttons.close" }),
  45. value: "close",
  46. },
  47. ]}
  48. value={mode}
  49. onChange={(value) => {
  50. const newMode: TPanelName = value.toString() as TPanelName;
  51. if (typeof onModeChange !== "undefined") {
  52. onModeChange(newMode);
  53. }
  54. setMode(newMode);
  55. }}
  56. />
  57. );
  58. };
  59. export default RightToolsSwitchWidget;