Skip to content

Commit

Permalink
Add hook on theme change to allow extensions to adapt theit themes.
Browse files Browse the repository at this point in the history
Mostly thinking of jupyter-lite-sphinx which wants to sync the
JupyterLab theme with pydata one.

I'm not sure this is the right approach, but at least that should get
the discussion started.
  • Loading branch information
Carreau committed Jun 24, 2024
1 parent 149eebb commit 810327f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function autoTheme(e) {
: "light";
}

if (window.pst_theme_change_hooks == undefined) {
window.pst_theme_change_hooks = [];
}

/**
* Set the theme using the specified mode.
* It can be one of ["auto", "dark", "light"]
Expand Down Expand Up @@ -55,6 +59,13 @@ function setTheme(mode) {

// add a listener if set on auto
prefersDark.onchange = mode == "auto" ? autoTheme : "";
for (var hook of window.pst_theme_change_hooks) {
try {
hook({ mode: mode });
} catch (e) {
console.error("Error running there change hook:", hook);
}
}
}

/**
Expand Down

0 comments on commit 810327f

Please sign in to comment.