posit-dev / py-shinyswatch

Bootswatch themes for py-shiny
https://posit-dev.github.io/py-shinyswatch/
MIT License
28 stars 3 forks source link

feat!: Use `shiny.ui.Theme` #39

Closed gadenbuie closed 5 months ago

gadenbuie commented 5 months ago

There are three core changes in this PR:

  1. We now use shiny.ui.Theme as the provider of the Shiny theme, using posit-dev/py-shiny#1358. This means that the Bootswatch themes are now complete Shiny themes, including built-in Shiny components in the bootswatch.min.css file.

  2. BREAKING CHANGE: As part of this change, shinyswatch no longer suppresses any Shiny component Sass, as that is handled by Shiny directly. shinyswatch now provides only the CSS styles, not a complete Bootswatch dependency. As a result, shinyswatch themes should be provided directly to the theme argument of shiny.ui.page_*() functions rather than being added anywhere in the UI.

    • In posit-dev/py-shiny#1358, shiny.ui.Theme() objects have a .tagify() method that raises an error, telling users to instead pass the theme object to theme=. We could consider a similar change for shinyswatch, but we'd need to think through the mechanism.
  3. BREAKING CHANGE: The default parameter of shinyswatch.theme_picker_ui() is now deprecated and ignored if provided. Due to the changes in 2 above, the initial theme should be set via shiny.ui.page_*(theme=).

    • The theme picker ui/server logic was updated such that the app will report its current theme on startup and the UI selector will be updated to match the initial theme.
    • We now also support returning to the first theme, which we call "default". This means that an app with shinyswatch can start with the default Shiny theme and users can then switch to a Bootswatch theme (and back again). This option is only available if the initial theme is the Shiny theme.
  4. BREAKING CHANGE: I've removed shinyswatch.get_theme_deps(). It's no longer useful given the current structure.

Example

I've updated the examples, but the most "complete" is now examples/page-sidebar/app.py. This app includes a custom initial theme that is added into the theme picker choices. Notice that bootstrap and shiny are also included in the theme picker choices.

https://github.com/posit-dev/py-shinyswatch/assets/5420529/8989acef-0d86-4ee7-95fc-d982a497fadc

TODO