mirror of https://github.com/usememos/memos
refactor: unify theme and apperance
parent
4eb5b67baf
commit
e93f3cbb8b
@ -1,51 +0,0 @@
|
||||
import { SunIcon, MoonIcon, SmileIcon } from "lucide-react";
|
||||
import { FC } from "react";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { useTranslate } from "@/utils/i18n";
|
||||
|
||||
interface Props {
|
||||
value: Appearance;
|
||||
onChange: (appearance: Appearance) => void;
|
||||
}
|
||||
|
||||
const appearanceList = ["system", "light", "dark"] as const;
|
||||
|
||||
const AppearanceSelect: FC<Props> = (props: Props) => {
|
||||
const { onChange, value } = props;
|
||||
const t = useTranslate();
|
||||
|
||||
const getPrefixIcon = (appearance: Appearance) => {
|
||||
const className = "w-4 h-auto";
|
||||
if (appearance === "light") {
|
||||
return <SunIcon className={className} />;
|
||||
} else if (appearance === "dark") {
|
||||
return <MoonIcon className={className} />;
|
||||
} else {
|
||||
return <SmileIcon className={className} />;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectChange = async (appearance: Appearance) => {
|
||||
onChange(appearance);
|
||||
};
|
||||
|
||||
return (
|
||||
<Select value={value} onValueChange={handleSelectChange}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select appearance" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{appearanceList.map((item) => (
|
||||
<SelectItem key={item} value={item} className="whitespace-nowrap">
|
||||
<div className="flex items-center gap-2">
|
||||
{getPrefixIcon(item)}
|
||||
{t(`setting.appearance-option.${item}`)}
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppearanceSelect;
|
||||
@ -0,0 +1,52 @@
|
||||
import { Moon, Palette, Sun, Wallpaper } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { workspaceStore } from "@/store";
|
||||
|
||||
interface ThemeSelectProps {
|
||||
value?: string;
|
||||
onValueChange?: (theme: string) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const ThemeSelect = ({ value, onValueChange, className }: ThemeSelectProps = {}) => {
|
||||
const currentTheme = value || workspaceStore.state.theme || "default";
|
||||
|
||||
const themeOptions: { value: Theme; icon: JSX.Element; label: string }[] = [
|
||||
{ value: "default", icon: <Sun className="w-4 h-4" />, label: "Default Light" },
|
||||
{ value: "default-dark", icon: <Moon className="w-4 h-4" />, label: "Default Dark" },
|
||||
{ value: "paper", icon: <Palette className="w-4 h-4" />, label: "Paper" },
|
||||
{ value: "whitewall", icon: <Wallpaper className="w-4 h-4" />, label: "Whitewall" },
|
||||
];
|
||||
|
||||
const handleThemeChange = (newTheme: Theme) => {
|
||||
if (onValueChange) {
|
||||
onValueChange(newTheme);
|
||||
} else {
|
||||
workspaceStore.setTheme(newTheme);
|
||||
}
|
||||
};
|
||||
|
||||
const currentThemeOption = themeOptions.find((option) => option.value === currentTheme);
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" className={`justify-start ${className || ""}`}>
|
||||
{currentThemeOption?.icon}
|
||||
<span className="ml-2">{currentThemeOption?.label}</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start">
|
||||
{themeOptions.map((option) => (
|
||||
<DropdownMenuItem key={option.value} onClick={() => handleThemeChange(option.value)}>
|
||||
{option.icon}
|
||||
<span className="ml-2">{option.label}</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
};
|
||||
|
||||
export default ThemeSelect;
|
||||
@ -1,32 +0,0 @@
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
|
||||
interface ThemeSelectorProps {
|
||||
value?: string;
|
||||
onValueChange: (value: string) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const THEMES = [
|
||||
{ value: "default", label: "Default" },
|
||||
{ value: "paper", label: "Paper" },
|
||||
{ value: "whitewall", label: "Whitewall" },
|
||||
] as const;
|
||||
|
||||
export const ThemeSelector = ({ value = "default", onValueChange, className }: ThemeSelectorProps) => {
|
||||
return (
|
||||
<Select value={value} onValueChange={onValueChange}>
|
||||
<SelectTrigger className={className}>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{THEMES.map((theme) => (
|
||||
<SelectItem key={theme.value} value={theme.value}>
|
||||
{theme.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
};
|
||||
|
||||
export default ThemeSelector;
|
||||
@ -0,0 +1,103 @@
|
||||
:root {
|
||||
--background: oklch(0.08 0.005 270);
|
||||
--foreground: oklch(0.75 0.01 270);
|
||||
--card: oklch(0.08 0.005 270);
|
||||
--card-foreground: oklch(0.75 0.01 270);
|
||||
--popover: oklch(0.12 0.008 270);
|
||||
--popover-foreground: oklch(0.7 0.01 270);
|
||||
--primary: oklch(0.65 0.12 250);
|
||||
--primary-foreground: oklch(0.08 0.005 270);
|
||||
--secondary: oklch(0.15 0.01 270);
|
||||
--secondary-foreground: oklch(0.7 0.01 270);
|
||||
--muted: oklch(0.12 0.008 270);
|
||||
--muted-foreground: oklch(0.6 0.01 270);
|
||||
--accent: oklch(0.18 0.015 270);
|
||||
--accent-foreground: oklch(0.75 0.01 270);
|
||||
--destructive: oklch(0.6 0.15 25);
|
||||
--destructive-foreground: oklch(1 0 0);
|
||||
--border: oklch(0.35 0.02 270);
|
||||
--input: oklch(0.4 0.025 270);
|
||||
--ring: oklch(0.65 0.12 250);
|
||||
--chart-1: oklch(0.7 0.15 30);
|
||||
--chart-2: oklch(0.7 0.15 260);
|
||||
--chart-3: oklch(0.6 0.12 120);
|
||||
--chart-4: oklch(0.65 0.15 300);
|
||||
--chart-5: oklch(0.75 0.18 60);
|
||||
--sidebar: oklch(0.06 0.003 270);
|
||||
--sidebar-foreground: oklch(0.75 0.01 270);
|
||||
--sidebar-primary: oklch(0.65 0.12 250);
|
||||
--sidebar-primary-foreground: oklch(0.08 0.005 270);
|
||||
--sidebar-accent: oklch(0.18 0.015 270);
|
||||
--sidebar-accent-foreground: oklch(0.75 0.01 270);
|
||||
--sidebar-border: oklch(0.35 0.02 270);
|
||||
--sidebar-ring: oklch(0.65 0.12 250);
|
||||
--font-sans:
|
||||
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
|
||||
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
||||
--font-serif: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
|
||||
--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
--radius: 0.5rem;
|
||||
--shadow-2xs: 0 1px 3px 0px hsl(0 0% 0% / 0.05);
|
||||
--shadow-xs: 0 1px 3px 0px hsl(0 0% 0% / 0.05);
|
||||
--shadow-sm: 0 1px 3px 0px hsl(0 0% 0% / 0.1), 0 1px 2px -1px hsl(0 0% 0% / 0.1);
|
||||
--shadow: 0 1px 3px 0px hsl(0 0% 0% / 0.1), 0 1px 2px -1px hsl(0 0% 0% / 0.1);
|
||||
--shadow-md: 0 1px 3px 0px hsl(0 0% 0% / 0.1), 0 2px 4px -1px hsl(0 0% 0% / 0.1);
|
||||
--shadow-lg: 0 1px 3px 0px hsl(0 0% 0% / 0.1), 0 4px 6px -1px hsl(0 0% 0% / 0.1);
|
||||
--shadow-xl: 0 1px 3px 0px hsl(0 0% 0% / 0.1), 0 8px 10px -1px hsl(0 0% 0% / 0.1);
|
||||
--shadow-2xl: 0 1px 3px 0px hsl(0 0% 0% / 0.25);
|
||||
--tracking-normal: 0em;
|
||||
--spacing: 0.25rem;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-card: var(--card);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-destructive-foreground: var(--destructive-foreground);
|
||||
--color-border: var(--border);
|
||||
--color-input: var(--input);
|
||||
--color-ring: var(--ring);
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||
--color-sidebar-accent: var(--sidebar-accent);
|
||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||
--color-sidebar-border: var(--sidebar-border);
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
|
||||
--font-sans: var(--font-sans);
|
||||
--font-mono: var(--font-mono);
|
||||
--font-serif: var(--font-serif);
|
||||
|
||||
--radius-sm: calc(var(--radius) - 4px);
|
||||
--radius-md: calc(var(--radius) - 2px);
|
||||
--radius-lg: var(--radius);
|
||||
--radius-xl: calc(var(--radius) + 4px);
|
||||
|
||||
--shadow-2xs: var(--shadow-2xs);
|
||||
--shadow-xs: var(--shadow-xs);
|
||||
--shadow-sm: var(--shadow-sm);
|
||||
--shadow: var(--shadow);
|
||||
--shadow-md: var(--shadow-md);
|
||||
--shadow-lg: var(--shadow-lg);
|
||||
--shadow-xl: var(--shadow-xl);
|
||||
--shadow-2xl: var(--shadow-2xl);
|
||||
}
|
||||
@ -1 +1 @@
|
||||
type Appearance = "system" | "light" | "dark";
|
||||
type Theme = "default" | "default-dark" | "paper" | "whitewall";
|
||||
|
||||
Loading…
Reference in New Issue