mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
* #1952 Fix incorrect localization key for sign-up failure message * feat: add typeScript support to enforce valid translation keys * feat: add typeScript support to enforce valid translation keys * fix lint errors * fix lint error
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { Option, Select } from "@mui/joy";
|
|
import { FC } from "react";
|
|
import { useTranslate } from "@/utils/i18n";
|
|
import Icon from "./Icon";
|
|
|
|
interface Props {
|
|
value: Appearance;
|
|
onChange: (appearance: Appearance) => void;
|
|
className?: string;
|
|
}
|
|
|
|
const appearanceList = ["system", "light", "dark"] as const;
|
|
|
|
const AppearanceSelect: FC<Props> = (props: Props) => {
|
|
const { onChange, value, className } = props;
|
|
const t = useTranslate();
|
|
|
|
const getPrefixIcon = (appearance: Appearance) => {
|
|
const className = "w-4 h-auto";
|
|
if (appearance === "light") {
|
|
return <Icon.Sun className={className} />;
|
|
} else if (appearance === "dark") {
|
|
return <Icon.Moon className={className} />;
|
|
} else {
|
|
return <Icon.Smile className={className} />;
|
|
}
|
|
};
|
|
|
|
const handleSelectChange = async (appearance: Appearance) => {
|
|
onChange(appearance);
|
|
};
|
|
|
|
return (
|
|
<Select
|
|
className={`!min-w-[10rem] w-auto whitespace-nowrap ${className ?? ""}`}
|
|
value={value}
|
|
onChange={(_, appearance) => {
|
|
if (appearance) {
|
|
handleSelectChange(appearance);
|
|
}
|
|
}}
|
|
startDecorator={getPrefixIcon(value)}
|
|
>
|
|
{appearanceList.map((item) => (
|
|
<Option key={item} value={item} className="whitespace-nowrap">
|
|
{t(`setting.appearance-option.${item}`)}
|
|
</Option>
|
|
))}
|
|
</Select>
|
|
);
|
|
};
|
|
|
|
export default AppearanceSelect;
|