mirror of https://github.com/usememos/memos
feat: dark mode support for auth page (#569)
* feat: dark mode support for auth page * chore: updatepull/584/head
parent
2d5d734da4
commit
90c85103c3
@ -0,0 +1,53 @@
|
||||
import { Option, Select } from "@mui/joy";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import Icon from "./Icon";
|
||||
import { APPERANCE_OPTIONS } from "../helpers/consts";
|
||||
import useApperance, { Apperance } from "../hooks/useApperance";
|
||||
|
||||
const ApperanceDropdownMenu = () => {
|
||||
const [apperance, setApperance] = useApperance();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const apperanceOptionItems = [
|
||||
[
|
||||
APPERANCE_OPTIONS[0],
|
||||
<>
|
||||
<Icon.Feather className="w-4 h-4" />
|
||||
<p>{t("setting.apperance-option.follow-system")}</p>
|
||||
</>,
|
||||
],
|
||||
[
|
||||
APPERANCE_OPTIONS[1],
|
||||
<>
|
||||
<Icon.Sun className="w-4 h-4" />
|
||||
<p>{t("setting.apperance-option.always-light")}</p>
|
||||
</>,
|
||||
],
|
||||
[
|
||||
APPERANCE_OPTIONS[2],
|
||||
<>
|
||||
<Icon.Moon className="w-4 h-4" />
|
||||
<p>{t("setting.apperance-option.always-dark")}</p>
|
||||
</>,
|
||||
],
|
||||
] as const;
|
||||
|
||||
return (
|
||||
<Select
|
||||
className="w-56 text-sm"
|
||||
value={apperance}
|
||||
onChange={(_, value) => {
|
||||
setApperance(value as Apperance);
|
||||
}}
|
||||
>
|
||||
{apperanceOptionItems.map((item) => (
|
||||
<Option key={item[0]} value={item[0]}>
|
||||
<span className="flex items-center gap-2">{item[1]}</span>
|
||||
</Option>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
};
|
||||
|
||||
export default ApperanceDropdownMenu;
|
@ -0,0 +1,28 @@
|
||||
import { useEffect } from "react";
|
||||
import { useColorScheme } from "@mui/joy/styles";
|
||||
|
||||
import { APPERANCE_OPTIONS, APPERANCE_OPTIONS_STORAGE_KEY } from "../helpers/consts";
|
||||
import useLocalStorage from "./useLocalStorage";
|
||||
|
||||
export type Apperance = typeof APPERANCE_OPTIONS[number];
|
||||
|
||||
const useApperance = () => {
|
||||
const [apperance, setApperance] = useLocalStorage<Apperance>(APPERANCE_OPTIONS_STORAGE_KEY, APPERANCE_OPTIONS[0]);
|
||||
|
||||
const { setMode } = useColorScheme();
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
if (apperance === "dark" || (apperance === "auto" && window.matchMedia("(prefers-color-scheme: dark)").matches)) {
|
||||
root.classList.add("dark");
|
||||
setMode("dark");
|
||||
} else {
|
||||
root.classList.remove("dark");
|
||||
setMode("light");
|
||||
}
|
||||
}, [apperance]);
|
||||
|
||||
return [apperance, setApperance] as const;
|
||||
};
|
||||
|
||||
export default useApperance;
|
Loading…
Reference in New Issue