Skip to content

Commit bf1f452

Browse files
committed
add listener, update types
1 parent 496cbc5 commit bf1f452

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/client/initialize.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
PluginConfig,
44
PluginInstance,
55
PluginMessageResponse,
6+
PluginThemeColors,
67
WorkbookSelection,
78
WorkbookVariable,
89
} from '../types';
@@ -68,6 +69,10 @@ export function initialize<T = {}>(): PluginInstance<T> {
6869
effect();
6970
});
7071

72+
on('wb:plugin:theme:update', (themeColors: PluginThemeColors) => {
73+
pluginConfig.themeColors = themeColors;
74+
});
75+
7176
function on(event: string, listener: Function) {
7277
listeners[event] = listeners[event] || [];
7378
listeners[event].push(listener);
@@ -106,6 +111,15 @@ export function initialize<T = {}>(): PluginInstance<T> {
106111
return pluginConfig.screenshot;
107112
},
108113

114+
get themeColors() {
115+
return pluginConfig.themeColors;
116+
},
117+
118+
subscribeToThemeColors(callback: (themeColors: PluginThemeColors) => void) {
119+
on('wb:plugin:theme:update', callback);
120+
return () => off('wb:plugin:theme:update', callback);
121+
},
122+
109123
config: {
110124
// @ts-ignore
111125
getKey(key) {

src/types.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,21 @@ export interface PluginConfig<T> {
2020
id: string;
2121
config: T;
2222
screenshot: boolean;
23+
themeColors?: PluginThemeColors;
2324
[key: string]: any;
2425
}
2526

27+
/**
28+
* Theme colors available to plugins
29+
* @typedef {object} PluginThemeColors
30+
* @property {string} backgroundColor Background color from workbook theme
31+
* @property {string} textColor Primary text color from workbook theme
32+
*/
33+
export interface PluginThemeColors {
34+
backgroundColor: string;
35+
textColor: string;
36+
}
37+
2638
/**
2739
* @typedef {object} WorkbookVariable
2840
* @property {string} name Name of control variable within workbook
@@ -189,6 +201,21 @@ export type CustomPluginConfigOptions =
189201
export interface PluginInstance<T = any> {
190202
sigmaEnv: 'author' | 'viewer' | 'explorer';
191203

204+
/**
205+
* Theme colors from the workbook
206+
* @returns {PluginThemeColors | undefined} Theme colors if available
207+
*/
208+
themeColors?: PluginThemeColors | undefined;
209+
210+
/**
211+
* Subscribe to theme color changes
212+
* @param {Function} callback Function to call when theme colors change
213+
* @returns {Function} Unsubscriber function
214+
*/
215+
subscribeToThemeColors(
216+
callback: (themeColors: PluginThemeColors) => void,
217+
): () => void;
218+
192219
config: {
193220
/**
194221
* Getter for entire Plugin Config

0 commit comments

Comments
 (0)