Skip to content

Commit a27ed15

Browse files
implemented theme change option
1 parent 674239f commit a27ed15

File tree

9 files changed

+44
-6
lines changed

9 files changed

+44
-6
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Changes in version 1.3.1 (in development)
22

3+
### New Features
4+
5+
* Users can now choose the application theme between light and dark mode
6+
from settings. Light mode is set as default.
7+
38
### Fixes
49

510
* The `<Time>` parameter is now no longer required to calculate the statistics

src/components/HelpButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ import MarkdownPopover from "@/components/MarkdownPopover";
3232
interface HelpButtonProps {
3333
size?: "small" | "medium" | "large";
3434
helpUrl?: string;
35+
currentAppTheme?: boolean;
3536
}
3637

37-
export default function HelpButton({ size, helpUrl }: HelpButtonProps) {
38+
export default function HelpButton({ size, helpUrl, currentAppTheme }: HelpButtonProps) {
3839
const [helpAnchorEl, setHelpAnchorEl] = useState<HTMLButtonElement | null>(
3940
null,
4041
);
@@ -59,6 +60,7 @@ export default function HelpButton({ size, helpUrl }: HelpButtonProps) {
5960
open={!!helpAnchorEl}
6061
onClose={handleHelpClose}
6162
markdownText={helpText}
63+
currentAppTheme={currentAppTheme}
6264
/>
6365
</>
6466
);

src/components/MarkdownPopover.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,32 @@ interface MarkdownPopoverProps {
3131
open: boolean;
3232
onClose?: () => void;
3333
markdownText?: string;
34+
currentAppTheme?: boolean;
3435
}
3536

3637
export default function MarkdownPopover({
3738
anchorEl,
3839
markdownText,
3940
open,
4041
onClose,
42+
currentAppTheme,
4143
}: MarkdownPopoverProps) {
4244
if (!markdownText) {
4345
return null;
4446
}
4547

4648
const components = {
49+
a: (props: Record<string, unknown>) => {
50+
const { node: _, ...rest } = props;
51+
return (
52+
<a
53+
{...rest}
54+
style={{
55+
color: currentAppTheme ? "#90caf9" : "#1e90ff",
56+
}}
57+
/>
58+
);
59+
},
4760
code: (props: Record<string, unknown>) => {
4861
const { node: _, ...rest } = props;
4962
return <code {...rest} style={{ color: "green" }} />;

src/components/SettingsDialog.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ const SettingsDialog: React.FC<SettingsDialogProps> = ({
279279
))}
280280
</TextField>
281281
</SettingsSubPanel>
282+
<SettingsSubPanel
283+
label={i18n.get("Change application theme to dark mode")}
284+
value={getOnOff(settings.currentAppTheme)}
285+
>
286+
<ToggleSetting
287+
propertyName={"currentAppTheme"}
288+
settings={settings}
289+
updateSettings={updateSettings}
290+
/>
291+
</SettingsSubPanel>
282292
</SettingsPanel>
283293

284294
<SettingsPanel title={i18n.get("Time-Series")}>

src/components/UserVariablesDialog/UserVariablesDialog.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ interface UserVariablesDialogProps {
6161
) => void;
6262
expressionCapabilities: ExpressionCapabilities | null;
6363
serverUrl: string;
64+
currentAppTheme: boolean;
6465
}
6566

6667
export default function UserVariablesDialog({
@@ -73,6 +74,7 @@ export default function UserVariablesDialog({
7374
updateDatasetUserVariables,
7475
expressionCapabilities,
7576
serverUrl,
77+
currentAppTheme,
7678
}: UserVariablesDialogProps) {
7779
const [localUserVariables, setLocalUserVariables] =
7880
useState<UserVariable[]>(userVariables);
@@ -139,6 +141,7 @@ export default function UserVariablesDialog({
139141
<HelpButton
140142
size="medium"
141143
helpUrl={i18n.get("docs/user-variables.en.md")}
144+
currentAppTheme={currentAppTheme}
142145
/>
143146
</Box>
144147
<Box>

src/connected/App.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,31 @@ import UserVariablesDialog from "./UserVariablesDialog";
4848

4949
interface AppProps {
5050
compact: boolean;
51+
currentAppTheme: boolean;
5152
}
5253

5354
// noinspection JSUnusedLocalSymbols
5455
const mapStateToProps = (_state: AppState) => {
5556
return {
5657
compact: Config.instance.branding.compact,
58+
currentAppTheme: _state.controlState.currentAppTheme,
5759
};
5860
};
5961

6062
const mapDispatchToProps = {};
6163

62-
const newTheme = () =>
63-
createTheme({
64+
const _App: React.FC<AppProps> = ({ compact, currentAppTheme }) => {
65+
const newTheme = () => createTheme({
6466
typography: {
6567
fontSize: 12,
6668
htmlFontSize: 14,
6769
},
6870
palette: {
69-
mode: Config.instance.branding.themeName,
71+
mode: currentAppTheme ? "dark" : "light", // Dynamic dark/light mode
7072
primary: Config.instance.branding.primaryColor,
7173
secondary: Config.instance.branding.secondaryColor,
7274
},
7375
});
74-
75-
const _App: React.FC<AppProps> = ({ compact }) => {
7676
return (
7777
<AuthWrapper>
7878
<StyledEngineProvider injectFirst>

src/connected/UserVariablesDialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const mapStateToProps = (state: AppState) => {
4545
userVariables: selectedUserVariablesSelector(state),
4646
expressionCapabilities: expressionCapabilitiesSelector(state),
4747
serverUrl: selectedServerSelector(state).url,
48+
currentAppTheme: state.controlState.currentAppTheme,
4849
};
4950
};
5051

src/states/controlState.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export interface ControlState {
160160
exportPlacesAsCollection: boolean;
161161
exportZipArchive: boolean;
162162
exportFileName: string;
163+
currentAppTheme: boolean;
163164
}
164165

165166
export function newControlState(): ControlState {
@@ -235,6 +236,7 @@ export function newControlState(): ControlState {
235236
exportPlacesAsCollection: true,
236237
exportZipArchive: true,
237238
exportFileName: "export",
239+
currentAppTheme: false,
238240
};
239241
return loadUserSettings(state);
240242
}

src/states/userSettings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export function storeUserSettings(settings: ControlState) {
112112
storage.setPrimitiveProperty("exportFileName", settings);
113113
storage.setPrimitiveProperty("userPlacesFormatName", settings);
114114
storage.setObjectProperty("userPlacesFormatOptions", settings);
115+
storage.setPrimitiveProperty("currentAppTheme", settings);
115116
if (import.meta.env.DEV) {
116117
console.debug("Stored user settings:", settings);
117118
}
@@ -213,6 +214,7 @@ export function loadUserSettings(defaultSettings: ControlState): ControlState {
213214
settings,
214215
defaultSettings,
215216
);
217+
storage.getBooleanProperty("currentAppTheme", settings, defaultSettings);
216218
if (import.meta.env.DEV) {
217219
console.debug("Loaded user settings:", settings);
218220
}

0 commit comments

Comments
 (0)