Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
899325a
refactor: Avoid needing to directly inspect shiny's bootstrap_deps
gadenbuie Apr 3, 2024
5e166c8
fix: remove unused import
gadenbuie Apr 3, 2024
35139e0
fix: version for bootstrap suppression
gadenbuie Apr 4, 2024
face07d
chore: Use `shinyswatch-{js,css,ionrangeslider`
gadenbuie Apr 4, 2024
4a0768e
feat: Add dep for all shinyswatch, refactor out reused components
gadenbuie Apr 4, 2024
7e02cb4
refactor: Refactor shinyswatch theme picker for faster smoother trans…
gadenbuie Apr 4, 2024
344ead5
chore: remove unused import
gadenbuie Apr 4, 2024
85220e9
feat: smooth theme transitions and initial theme load
gadenbuie Apr 5, 2024
e4447e7
chore: import from the future
gadenbuie Apr 5, 2024
13a665d
feat: safer old stylesheet removal to avoid FOUC
gadenbuie Apr 5, 2024
928fb7c
fix: clearTimeout not cance
gadenbuie Apr 5, 2024
bd1295c
refactor: finish refactoring shinyswatch-js
gadenbuie Apr 5, 2024
a681942
chore: Account for changing very quickly between themes
gadenbuie Apr 5, 2024
6758bd3
feat: Limit transition rule to transitioning only
gadenbuie Apr 5, 2024
31775dc
chore: format
gadenbuie Apr 5, 2024
aa7f348
fix(typo)
gadenbuie Apr 5, 2024
0a69de2
fix(typo): dataset.shinyswatchCss
gadenbuie Apr 5, 2024
e5c734e
factor out replaceShinyswatchCSS
gadenbuie Apr 5, 2024
df95807
fix copilot typo
gadenbuie Apr 5, 2024
1c192b1
move basedir into refactored function
gadenbuie Apr 5, 2024
349d7a9
refactor: getShinySwatchLibPath()
gadenbuie Apr 5, 2024
44029bf
send css file names from the python side
gadenbuie Apr 5, 2024
f7203d7
only transition when transitioning
gadenbuie Apr 5, 2024
6e6e9ee
not a function, just an array
gadenbuie Apr 5, 2024
298cdef
a final bit of refactoring
gadenbuie Apr 5, 2024
a1ca10d
chore: bump version, add changelog note
gadenbuie Apr 5, 2024
1cf43b3
changelog edits
gadenbuie Apr 5, 2024
28f5819
remove debug code
gadenbuie Apr 5, 2024
436ec1e
feat: User can provide default theme
gadenbuie Apr 5, 2024
b60a38b
chore: add a couple more comments
gadenbuie Apr 5, 2024
7b473f3
refactor(theme_picker.js): Use IIFE to avoid polluting global scope
gadenbuie Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions shinyswatch/_get_theme_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

from htmltools import HTMLDependency

# from shiny.ui._html_deps_external import bootstrap_deps_suppress
from shiny._versions import bootstrap as shiny_bootstrap_version

from ._assert import assert_theme
from ._bsw5 import BSW5_THEME_NAME, bsw5_version
from ._shiny import base_dep_version, bs5_path, bs_dep_no_files

bs5_path = os.path.join(os.path.dirname(__file__), "bs5")


def get_theme_deps(name: BSW5_THEME_NAME) -> list[HTMLDependency]:
Expand All @@ -33,22 +37,31 @@ def get_theme_deps(name: BSW5_THEME_NAME) -> list[HTMLDependency]:
# This is to prevent the Shiny bootstrap stylesheet from being loaded and instead load the bootswatch + bootstrap stylesheet
# _Disable_ bootstrap html dep
# Prevents bootstrap from being loaded at a later time (Ex: shiny.ui.card() https://github.com/rstudio/py-shiny/blob/d08af1a8534677c7026b60559cd5eafc5f6608d7/shiny/ui/_navs.py#L983)
#
# bootstrap_deps_suppress(["css", "js"]),
# TODO: Replace the next three lines with the above line when available
HTMLDependency(
name="bootstrap-js",
version=shiny_bootstrap_version + "9999",
Comment thread
gadenbuie marked this conversation as resolved.
Outdated
),
HTMLDependency(
name="bootstrap-css",
version=shiny_bootstrap_version + "9999",
),
HTMLDependency(
name="bootstrap",
version=base_dep_version,
version=shiny_bootstrap_version + "9999",
),
# Use a custom version of bootstrap with no stylesheets/JS
bs_dep_no_files,
# Add in the matching JS files
HTMLDependency(
name="bootstrap-js",
name=f"bootstrap-{name}-js",
Comment thread
gadenbuie marked this conversation as resolved.
Outdated
version=bsw5_version,
source={"package": "shinyswatch", "subdir": bs5_path},
script={"src": "bootstrap.bundle.min.js"},
),
Comment thread
gadenbuie marked this conversation as resolved.
Outdated
# Shinyswatch - bootstrap / bootswatch css
HTMLDependency(
name=f"bootswatch-{name}-and-bootstrap",
name=f"bootswatch-{name}-css",
version=bsw5_version,
source={"package": "shinyswatch", "subdir": subdir},
stylesheet=[{"href": "bootswatch.min.css"}],
Expand All @@ -59,7 +72,7 @@ def get_theme_deps(name: BSW5_THEME_NAME) -> list[HTMLDependency]:
# Disable ionRangeSlider
HTMLDependency(
name="preset-shiny-ionrangeslider",
version=base_dep_version,
version="9999",
),
# Shinyswatch - ionRangeSlider css
HTMLDependency(
Expand Down
36 changes: 0 additions & 36 deletions shinyswatch/_shiny.py

This file was deleted.

12 changes: 5 additions & 7 deletions shinyswatch/_theme_picker.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from htmltools import HTMLDependency, TagList
from htmltools import TagList
from packaging.version import Version
from shiny import reactive, render, req, ui
from shiny.session import require_active_session

from ._bsw5 import BSW5_THEME_NAME, bsw5_themes
from ._get_theme_deps import get_theme_deps
from ._shiny import base_dep_version

default_theme_name = "superhero"

Expand Down Expand Up @@ -102,12 +102,10 @@ def shinyswatch_theme_deps(): # pyright: ignore[reportUnusedFunction]

# Get the theme dependencies and set them to a version that will always be registered
theme_deps = get_theme_deps(theme_name())
incremented_version = HTMLDependency(
name="VersionOnly",
version=f"{base_dep_version}.{counter()}",
).version
incremented_version = Version(f"9999.{counter()}")
for theme_dep in theme_deps:
theme_dep.version = incremented_version
if hasattr(theme_dep, "version"):
theme_dep.version = incremented_version
# Return dependencies in a TagList so they can all be utilized
return TagList(theme_deps)

Expand Down