judge4c-old-2/src/store/useCodeEditorStore.ts
ngc2207 0be9cf3baa refactor(constants): move languages.ts and themes.ts to editor folder
refactor(imports): update SUPPORTED_LANGUAGES and SUPPORTED_THEMES import path to use editor folder

feat(constants): add MIN_FONT_SIZE、MAX_FONT_SIZE and DEFAULT_FONT_SIZE

feat(store): add font size management to code editor store
2024-12-31 23:57:27 +08:00

25 lines
804 B
TypeScript

import { create } from "zustand";
import { CodeEditorState } from "@/types";
import { DEFAULT_THEME } from "@/constants/editor/themes";
import { DEFAULT_LANGUAGE } from "@/constants/editor/languages";
import { persist, createJSONStorage } from "zustand/middleware";
import { DEFAULT_FONT_SIZE } from "@/constants/editor/options";
export const useCodeEditorStore = create<CodeEditorState>()(
persist(
(set) => ({
language: DEFAULT_LANGUAGE,
theme: DEFAULT_THEME,
fontSize: DEFAULT_FONT_SIZE,
setLanguage: (language: string) => set({ language }),
setTheme: (theme: string) => set({ theme }),
setFontSize: (fontSize: number) => set({ fontSize }),
}),
{
name: "code-editor-storage",
storage: createJSONStorage(() => localStorage),
}
)
);