Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(settings): Turn the theme toggle into a field in the settings form. #184

Merged
merged 6 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/components/modals/SettingsModal/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
getConfig,
setConfig,
} from "../../../utils/config";
import ThemeSwitchToggle from "./ThemeSwitchToggle";
import ThemeSwitchFormField from "./ThemeSwitchFormField";


const CONFIG_FORM_FIELDS = [
Expand Down Expand Up @@ -141,12 +141,10 @@ const SettingsDialog = forwardRef<HTMLFormElement>((_, ref) => {
size={"lg"}
>
<DialogTitle className={"settings-dialog-title"}>
<span className={"settings-dialog-title-text"}>
Settings
</span>
<ThemeSwitchToggle/>
Settings
</DialogTitle>
<DialogContent>
<ThemeSwitchFormField/>
{CONFIG_FORM_FIELDS.map((field, index) => (
<FormControl
className={"config-form-control"}
Expand Down
64 changes: 64 additions & 0 deletions src/components/modals/SettingsModal/ThemeSwitchFormField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
Button,
FormControl,
FormHelperText,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to later comment

Suggested change
FormHelperText,

FormLabel,
ToggleButtonGroup,
useColorScheme,
} from "@mui/joy";
import type {Mode} from "@mui/system/cssVars/useCurrentColorScheme";

import DarkModeIcon from "@mui/icons-material/DarkMode";
import LightModeIcon from "@mui/icons-material/LightMode";
import SettingsBrightnessIcon from "@mui/icons-material/SettingsBrightness";

import {THEME_NAME} from "../../../typings/config";


/**
* Renders a toggle button form field for theme selection.
*
* @return
*/
const ThemeSwitchFormField = () => {
const {setMode, mode} = useColorScheme();

return (
<FormControl>
<FormLabel>
Theme
</FormLabel>
<ToggleButtonGroup
size={"sm"}
value={mode as string}
onChange={(__, newValue) => {
setMode(newValue as Mode);
}}
>
<Button
startDecorator={<LightModeIcon/>}
value={THEME_NAME.LIGHT}
>
Light
</Button>
<Button
startDecorator={<SettingsBrightnessIcon/>}
value={THEME_NAME.SYSTEM}
>
System
</Button>
<Button
startDecorator={<DarkModeIcon/>}
value={THEME_NAME.DARK}
>
Dark
</Button>
</ToggleButtonGroup>
<FormHelperText>
Log viewer color theme. System theme will match your system settings.
</FormHelperText>
</FormControl>
);
};

export default ThemeSwitchFormField;
53 changes: 0 additions & 53 deletions src/components/modals/SettingsModal/ThemeSwitchToggle.tsx

This file was deleted.

5 changes: 1 addition & 4 deletions src/components/modals/SettingsModal/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
}

.settings-dialog-title-text {
flex-grow: 1;
font-size: 2rem;
font-size: 2rem !important;
}

.config-form-control {
Expand Down