summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useThemeCommand.ts
diff options
context:
space:
mode:
authorTaylor Mullen <[email protected]>2025-04-22 18:57:47 -0700
committerN. Taylor Mullen <[email protected]>2025-04-22 22:08:13 -0700
commit4c2a5045a0d209cfda5723a4dc84fe59670b558e (patch)
tree2a874aa35a524f683a39f89d5fc288b0a09596f7 /packages/cli/src/ui/hooks/useThemeCommand.ts
parente163e024996ff8bb1152284322831c4f35696801 (diff)
Add theming support.
- Added a number of common themes to our support matrix: - AtomOneDark - Dracula - VS - GitHub - GoogleCode - XCode - ... Admittedly these all were randomly picked, we could probably curate these better... - Added a new `ThemeDialog` UI that can be accessed via `/theme`. It shows your currentlyt available themes and allows you to change them freely. It does **not**: - Save the theme between sessions - Allow you to hit escape - Show a preview prior to selection. - These themes are from reacts highlight js library. Fixes https://b.corp.google.com/issues/412797985
Diffstat (limited to 'packages/cli/src/ui/hooks/useThemeCommand.ts')
-rw-r--r--packages/cli/src/ui/hooks/useThemeCommand.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/packages/cli/src/ui/hooks/useThemeCommand.ts b/packages/cli/src/ui/hooks/useThemeCommand.ts
new file mode 100644
index 00000000..85bd4906
--- /dev/null
+++ b/packages/cli/src/ui/hooks/useThemeCommand.ts
@@ -0,0 +1,40 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { useState, useCallback } from 'react';
+import { themeManager } from '../themes/theme-manager.js';
+
+interface UseThemeCommandReturn {
+ isThemeDialogOpen: boolean;
+ openThemeDialog: () => void;
+ handleThemeSelect: (themeName: string) => void;
+}
+
+export const useThemeCommand = (): UseThemeCommandReturn => {
+ const [isThemeDialogOpen, setIsThemeDialogOpen] = useState(false);
+ const [, setForceRender] = useState(0);
+
+ const openThemeDialog = useCallback(() => {
+ setIsThemeDialogOpen(true);
+ }, []);
+
+ const handleThemeSelect = useCallback((themeName: string) => {
+ try {
+ themeManager.setActiveTheme(themeName);
+ setForceRender((v) => v + 1); // Trigger potential re-render
+ } catch (error) {
+ console.error(`Error setting theme: ${error}`);
+ } finally {
+ setIsThemeDialogOpen(false); // Close the dialog
+ }
+ }, []);
+
+ return {
+ isThemeDialogOpen,
+ openThemeDialog,
+ handleThemeSelect,
+ };
+};