filled default light and dark theme

This commit is contained in:
Fedor Katurov 2023-04-29 21:46:21 +06:00
parent 44d903b6e2
commit b39633c736
5 changed files with 95 additions and 30 deletions

View file

@ -16,5 +16,10 @@
"Light theme": "Light theme", "Light theme": "Light theme",
"Blueberry boar": "Blueberry boar", "Blueberry boar": "Blueberry boar",
"User defined theme": "User defined", "User defined theme": "User defined",
"Built-in theme": "Built-in" "Built-in theme": "Built-in",
"Heading 1": "Heading 1",
"Heading 2": "Heading 2",
"Heading 3": "Heading 3",
"Heading 4": "Heading 4",
"Heading 5": "Heading 5"
} }

View file

@ -16,5 +16,10 @@
"Light theme": "Светлая", "Light theme": "Светлая",
"Blueberry boar": "Черничный кабанчик", "Blueberry boar": "Черничный кабанчик",
"User defined theme": "Пользовательская", "User defined theme": "Пользовательская",
"Built-in theme": "Встроенная" "Built-in theme": "Встроенная",
"Heading 1": "Заголовок 1",
"Heading 2": "Заголовок 2",
"Heading 3": "Заголовок 3",
"Heading 4": "Заголовок 4",
"Heading 5": "Заголовок 5"
} }

View file

@ -7,14 +7,13 @@ import {
SettingsValue, SettingsValue,
useSettings, useSettings,
} from "~/modules/settings/context/SettingsContext"; } from "~/modules/settings/context/SettingsContext";
import { ThemeSelect } from "../../components/ThemeSelect";
import { useBuiltinThemes } from "~/modules/theme/constants/themes"; import { useBuiltinThemes } from "~/modules/theme/constants/themes";
import { useDefaultTheme } from "~/modules/theme/hooks/useDefaultTheme"; import { fillThemeHeadings } from "~/modules/theme/utils/fillThemeHeadings";
import { ThemeSelect } from "../../components/ThemeSelect";
const ColorSettings: FC = () => { const ColorSettings: FC = () => {
const { update, settings } = useSettings(); const { update, settings } = useSettings();
const { t } = useTranslation(); const { t } = useTranslation();
const defaultColors = useDefaultTheme();
const setString = useCallback( const setString = useCallback(
(field: keyof SettingsValue) => (event: ChangeEvent<HTMLInputElement>) => { (field: keyof SettingsValue) => (event: ChangeEvent<HTMLInputElement>) => {
@ -28,19 +27,19 @@ const ColorSettings: FC = () => {
const currentTheme = useMemo( const currentTheme = useMemo(
() => () =>
themes.find((it) => themes.find((it) =>
Object.entries({ ...defaultColors, ...it.colors }).every( Object.entries(fillThemeHeadings(it.colors)).every(
([key, value]) => ([key, value]) =>
(settings as unknown as Record<string, string>)[key] === value (settings as unknown as Record<string, string>)[key] === value
) )
), ),
[themes, defaultColors, settings] [themes, settings]
); );
const setThemeColors = useCallback( const setThemeColors = useCallback(
(val: ColorSettings) => { (val: ColorSettings) => {
update({ ...defaultColors, ...val }); update(fillThemeHeadings(val));
}, },
[defaultColors, update] [update]
); );
const themeSubtitle = useMemo(() => { const themeSubtitle = useMemo(() => {
@ -57,7 +56,7 @@ const ColorSettings: FC = () => {
return ( return (
<RowGroup> <RowGroup>
<label htmlFor="theme"> <label>
<SettingsRow title={t("Color theme")} subTitle={themeSubtitle}> <SettingsRow title={t("Color theme")} subTitle={themeSubtitle}>
<ThemeSelect <ThemeSelect
value={currentTheme} value={currentTheme}
@ -67,49 +66,95 @@ const ColorSettings: FC = () => {
</SettingsRow> </SettingsRow>
</label> </label>
<label htmlFor="backgroundColor"> <label>
<SettingsRow title={t("Background")}> <SettingsRow title={t("Background")}>
<input <input
type="color" type="color"
id="backgroundColor"
onChange={setString("backgroundColor")} onChange={setString("backgroundColor")}
value={settings.backgroundColor} value={settings.backgroundColor}
/> />
</SettingsRow> </SettingsRow>
</label> </label>
<label htmlFor="textColor"> <label>
<SettingsRow title={t("Text")}> <SettingsRow title={t("Text")}>
<input <input
type="color" type="color"
id="textColor"
onChange={setString("textColor")} onChange={setString("textColor")}
value={settings.textColor} value={settings.textColor}
/> />
</SettingsRow> </SettingsRow>
</label> </label>
<label htmlFor="linkColor"> <label>
<SettingsRow title={t("Links")}> <SettingsRow title={t("Links")}>
<input <input
type="color" type="color"
id="linkColor"
onChange={setString("linkColor")} onChange={setString("linkColor")}
value={settings.linkColor} value={settings.linkColor}
/> />
</SettingsRow> </SettingsRow>
</label> </label>
<label htmlFor="codeColor"> <label>
<SettingsRow title={t("Inline code")}> <SettingsRow title={t("Inline code")}>
<input <input
type="color" type="color"
id="codeColor"
onChange={setString("codeColor")} onChange={setString("codeColor")}
value={settings.codeColor} value={settings.codeColor}
/> />
</SettingsRow> </SettingsRow>
</label> </label>
<label>
<SettingsRow title={t("Heading 1")}>
<input
type="color"
onChange={setString("h1Color")}
value={settings.h1Color || settings.textColor}
/>
</SettingsRow>
</label>
<label>
<SettingsRow title={t("Heading 2")}>
<input
type="color"
onChange={setString("h2Color")}
value={settings.h2Color || settings.textColor}
/>
</SettingsRow>
</label>
<label>
<SettingsRow title={t("Heading 3")}>
<input
type="color"
onChange={setString("h3Color")}
value={settings.h3Color || settings.textColor}
/>
</SettingsRow>
</label>
<label>
<SettingsRow title={t("Heading 4")}>
<input
type="color"
onChange={setString("h4Color")}
value={settings.h4Color || settings.textColor}
/>
</SettingsRow>
</label>
<label>
<SettingsRow title={t("Heading 5")}>
<input
type="color"
onChange={setString("h5Color")}
value={settings.h5Color || settings.textColor}
/>
</SettingsRow>
</label>
</RowGroup> </RowGroup>
); );
}; };

View file

@ -10,21 +10,21 @@ export const defaultDarkTheme: ColorSettings = {
textColor: "#eeeeee", textColor: "#eeeeee",
linkColor: "#25bfe6", linkColor: "#25bfe6",
codeColor: "#ff3344", codeColor: "#ff3344",
h1Color: "", h1Color: "#f66151",
h2Color: "", h2Color: "#ffbe6f",
h3Color: "", h3Color: "#f9f06b",
h4Color: "", h4Color: "#8ff0a4",
h5Color: "", h5Color: "#99c1f1",
}; };
export const defaultLightTheme: ColorSettings = { export const defaultLightTheme: ColorSettings = {
backgroundColor: "#eeeeee", backgroundColor: "#deddda",
textColor: "#2e2e2e", textColor: "#2e2e2e",
linkColor: "#25bfe6", linkColor: "#1c71d8",
codeColor: "#ff3344", codeColor: "#ff3344",
h1Color: "", h1Color: "#6b5554",
h2Color: "", h2Color: "#4f403f",
h3Color: "", h3Color: "#3d302f",
h4Color: "", h4Color: "#2e2625",
h5Color: "", h5Color: "#2c2322",
}; };

View file

@ -0,0 +1,10 @@
import { ColorSettings } from "~/modules/settings/context/SettingsContext";
export const fillThemeHeadings = (theme: ColorSettings): ColorSettings => ({
...theme,
h1Color: theme.h1Color || theme.textColor,
h2Color: theme.h2Color || theme.textColor,
h3Color: theme.h3Color || theme.textColor,
h4Color: theme.h4Color || theme.textColor,
h5Color: theme.h5Color || theme.textColor,
});