theme-mode-switch.tsx 813 B

123456789101112131415161718192021222324252627282930313233
  1. import { useTranslation } from "react-i18next";
  2. import { Button, ButtonGroup } from "@mui/material";
  3. type ThemeValue = IVergeConfig["theme_mode"];
  4. interface Props {
  5. value?: ThemeValue;
  6. onChange?: (value: ThemeValue) => void;
  7. }
  8. const ThemeModeSwitch = (props: Props) => {
  9. const { value, onChange } = props;
  10. const { t } = useTranslation();
  11. const modes = ["light", "dark", "system"] as const;
  12. return (
  13. <ButtonGroup size="small" sx={{ my: "4px" }}>
  14. {modes.map((mode) => (
  15. <Button
  16. key={mode}
  17. variant={mode === value ? "contained" : "outlined"}
  18. onClick={() => onChange?.(mode)}
  19. sx={{ textTransform: "capitalize" }}
  20. >
  21. {t(`theme.${mode}`)}
  22. </Button>
  23. ))}
  24. </ButtonGroup>
  25. );
  26. };
  27. export default ThemeModeSwitch;