Skip to content

Commit 1609ed0

Browse files
committed
add hook
1 parent bf1f452 commit 1609ed0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/react/hooks.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
WorkbookElementData,
99
WorkbookSelection,
1010
WorkbookVariable,
11+
PluginThemeColors,
1112
} from '../types';
1213
import { deepEqual } from '../utils/deepEqual';
1314

@@ -246,3 +247,19 @@ export function useActionEffect(configId: string, effect: () => void) {
246247
return client.config.registerEffect(configId, effectRef.current);
247248
}, [client, configId, effect]);
248249
}
250+
251+
/**
252+
* React hook for accessing workbook theme colors with live updates
253+
* @returns {PluginThemeColors | undefined} Theme colors from the workbook if available
254+
*/
255+
export function useThemeColors(): PluginThemeColors | undefined {
256+
const client = usePlugin();
257+
const [themeColors, setThemeColors] = useState(client.themeColors);
258+
259+
useEffect(() => {
260+
setThemeColors(client.themeColors);
261+
return client.subscribeToThemeColors(setThemeColors);
262+
}, [client]);
263+
264+
return themeColors;
265+
}

0 commit comments

Comments
 (0)