Skip to content

Commit

Permalink
implement suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
iisakkirotko committed Mar 15, 2024
1 parent ca06b00 commit c74b4bf
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions solara/server/templates/solara.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
{{ resources.include_css("/static/highlight-dark.css") }}
{{ resources.include_css("/static/assets/style.css") }}
<style id="jupyter-theme-css" class="solara-template-css">
{{ resources.include_css("/static/assets/theme-"~theme.variant~".css") }}
</style>
{{ resources.include_css("/static/assets/custom.css") }}

Expand All @@ -39,6 +38,8 @@
<style class="solara-template-css">
{% include "loader-"~theme.loader~".css" %}
</style>
<!-- Include Vuetify background colours so static html from SSG renders the right general colour theme
before first render. We remove these after Vue takes over rendering to avoid collisions -->
<style id="pre-render-theme">
.theme--light .v-sheet {
background-color: #fff;
Expand Down Expand Up @@ -187,9 +188,6 @@
<div id="pre-rendered-html-present" style="display: none"></div>
</div>
<script>
solara.rootPath = {{ root_path | tojson | safe}};
console.log("rootPath", solara.rootPath);
var theme = {{ theme | tojson | safe }}
function getThemeVariant() {
if (localStorage.getItem(':solara:theme.variant')) {
Expand All @@ -212,19 +210,14 @@
}
}
// Init theme
let app_container = document.getElementById('app');
let appContainer = document.getElementById('app');
if (inDarkMode()) {
app_container.classList.remove('theme--light');
app_container.classList.add('theme--dark');
appContainer.classList.remove('theme--light');
appContainer.classList.add('theme--dark');
} else {
app_container.classList.remove('theme--dark');
app_container.classList.add('theme--light');
appContainer.classList.remove('theme--dark');
appContainer.classList.add('theme--light');
}
async function changeThemeCSS(theme) {
let css = await fetch(`${solara.rootPath}/static/assets/theme-${theme}.css`).then(r => r.text());
document.getElementById('jupyter-theme-css').innerHTML = css;
}
changeThemeCSS(inDarkMode() ? 'dark' : 'light');
</script>
{% block after_pre_rendered_html %}{% endblock %}
{% if vue3 == True %}
Expand All @@ -242,6 +235,16 @@
<script src="{{cdn}}/@widgetti/[email protected]/dist/solara-vuetify-app{{ipywidget_major_version}}.js"></script>
{% endif %}
{% endif %}
<script>
solara.rootPath = {{ root_path | tojson | safe}};
console.log("rootPath", solara.rootPath);
async function changeThemeCSS(theme) {
let css = await fetch(`${solara.rootPath}/static/assets/theme-${theme}.css`).then(r => r.text());
document.getElementById('jupyter-theme-css').innerHTML = css;
}
changeThemeCSS(inDarkMode() ? 'dark' : 'light');
</script>

{{ resources.include_js("/static/assets/custom.js") }}
{{ resources.include_js("/static/assets/theme.js") }}
Expand Down Expand Up @@ -345,12 +348,12 @@
'$vuetify.theme.dark': function (value) {
if ( value ) {
this.changeThemeCSS('dark');
app_container.classList.remove('theme--light');
app_container.classList.add('theme--dark');
appContainer.classList.remove('theme--light');
appContainer.classList.add('theme--dark');
} else {
this.changeThemeCSS('light');
app_container.classList.remove('theme--dark');
app_container.classList.add('theme--light');
appContainer.classList.remove('theme--dark');
appContainer.classList.add('theme--light');
}
}
},
Expand Down

0 comments on commit c74b4bf

Please sign in to comment.