Skip to content

Commit

Permalink
feat: allow getting the currently set theme
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiksta committed Jul 2, 2024
1 parent 13c9395 commit 2e7c5b0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/core/src/style/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export function themeVariables<T extends ThemeDef>(
return ret;
}

const themes: { [libName: string]: ThemeDef } = { };

/**
Set the current theme. See {@link themeVariables} for more details and an example.
*/
Expand All @@ -72,8 +74,14 @@ export function setTheme(
}

util.applySheetAsStyleTag(document.head, wrapperSheet, `${libName}-theme`);
themes[libName] = def;
}

/** Get the current theme (after calling {@link setTheme}). */
export const getTheme = (libName: string): ThemeDef | false =>
(libName in themes) ? themes[libName] : false;


// TODO: share with refcount
const _currentTheme$ = new Stream<'dark' | 'light'>(observer => {
if (!window.matchMedia) {
Expand Down

0 comments on commit 2e7c5b0

Please sign in to comment.