Skip to content

Commit 442657b

Browse files
committed
Option to restore the default theme
1 parent 7a20cce commit 442657b

3 files changed

Lines changed: 49 additions & 10 deletions

File tree

src/programs/Settings/Settings.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
StyledSections,
1414
StyledSettings,
1515
} from "./styles";
16+
import Button from "../../components/Button";
1617

1718
interface SettingsSectionProps {
1819
title: string;
@@ -37,6 +38,8 @@ function SettingsSection(section: SettingsSectionProps) {
3738
return "color";
3839
case "url":
3940
return "url";
41+
case "button":
42+
return "button";
4043
default:
4144
return "text";
4245
}
@@ -62,15 +65,26 @@ function SettingsSection(section: SettingsSectionProps) {
6265
}, 1000);
6366
}
6467

65-
return (
66-
<StyledSection>
67-
<StyledSectionTitle>{section.title}</StyledSectionTitle>
68-
<StyledSectionDescription>{section.description}</StyledSectionDescription>
68+
function getInputField() {
69+
const type = getInputType(section.type);
70+
if (type === "button")
71+
return (
72+
<Button name="Restore" onClick={() => section.onValueChanged("")} />
73+
);
74+
return (
6975
<StyledSectionValue
7076
type={getInputType(section.type)}
7177
value={String(value)}
7278
onChange={handleChange}
73-
></StyledSectionValue>
79+
/>
80+
);
81+
}
82+
83+
return (
84+
<StyledSection>
85+
<StyledSectionTitle>{section.title}</StyledSectionTitle>
86+
<StyledSectionDescription>{section.description}</StyledSectionDescription>
87+
{getInputField()}
7488
</StyledSection>
7589
);
7690
}

src/programs/Settings/settingsPageConfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ export function getPages(
7676
systemsSettings.setIconColor(value);
7777
},
7878
},
79+
{
80+
title: "Restore Default Theme",
81+
description: "Revert to the default theme",
82+
type: "button",
83+
onValueChanged: () => systemsSettings.restoreDefaultTheme(),
84+
currentValue: undefined,
85+
},
7986
],
8087
},
8188
};

src/stores/systemSettingsStore.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
import { create } from "zustand";
22
import { persist } from "zustand/middleware";
33

4+
type FunctionPropertyNames<T> = {
5+
// eslint-disable-next-line @typescript-eslint/ban-types
6+
[K in keyof T]: T[K] extends Function ? K : never;
7+
}[keyof T];
8+
9+
type Theme = Omit<
10+
SystemSettingState,
11+
FunctionPropertyNames<SystemSettingState>
12+
>;
13+
14+
const defaultTheme: Theme = {
15+
mainColor: "#2e3440",
16+
accentColor: "#454e60",
17+
fontColor: "#ffffff",
18+
iconColor: "#9298b9",
19+
background: "https://regolith-linux.org/images/releases/nord-dark.png",
20+
};
21+
422
export interface SystemSettingState {
523
mainColor: string;
624
accentColor: string;
@@ -12,16 +30,13 @@ export interface SystemSettingState {
1230
setFontColor: (color: string) => void;
1331
setIconColor: (color: string) => void;
1432
setBackground: (url: string) => void;
33+
restoreDefaultTheme: () => void;
1534
}
1635

1736
export const useSystemSettings = create<SystemSettingState>()(
1837
persist(
1938
(set) => ({
20-
mainColor: "#2e3440",
21-
accentColor: "#454e60",
22-
fontColor: "#ffffff",
23-
iconColor: "#9298b9",
24-
background: "https://regolith-linux.org/images/releases/nord-dark.png",
39+
...defaultTheme,
2540
setAccentColor(accentColor) {
2641
set({ accentColor });
2742
},
@@ -37,6 +52,9 @@ export const useSystemSettings = create<SystemSettingState>()(
3752
setBackground(background) {
3853
set({ background });
3954
},
55+
restoreDefaultTheme() {
56+
set({ ...defaultTheme });
57+
},
4058
}),
4159
{
4260
name: "system-settings",

0 commit comments

Comments
 (0)