Skip to content

Commit

Permalink
fix(input_dark_mode): Allow users to customize style attribute (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie authored Mar 19, 2024
1 parent 02d3f62 commit 00d956e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* On Windows, Shiny Express app files are now read in as UTF-8. (#1203)

* `input_dark_mode()` now accepts a `style` argument that can be used to customize the appearance and position of the dark mode toggle switch. (#1207)

* Calling `ui.update_selectize()` with `choices` and `selected` now clears the current selection before updating the choices and selected value. (#1221)

* Fixed an issue that could happen with a `ui.card()` or `ui.value_box()` that is rendered dynamically via `@render.ui` when an updated card replaces a card that the user has expanded into full screen mode. Now the full screen state is reset for the new card or value box. If you want to update a card without potentially exiting the full-screen mode, update specific parts of the card using `ui.output_ui()` or `ui.output_text()`. (#1221)
Expand Down
18 changes: 10 additions & 8 deletions shiny/ui/_input_dark_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@ def input_dark_mode(

return web_component(
"bslib-input-dark-mode",
{
"style": css(
**{
"--text-1": "var(--bs-emphasis-color)",
"--text-2": "var(--bs-tertiary-color)",
# TODO: Fix the vertical correction to work better with Bootstrap
"--vertical-correction": " ",
},
)
},
id=id,
attribute="data-bs-theme",
mode=mode,
style=css(
**{
"--text-1": "var(--bs-emphasis-color)",
"--text-2": "var(--bs-tertiary-color)",
# TODO: Fix the vertical correction to work better with Bootstrap
"--vertical-correction": " ",
}
),
**kwargs,
)

Expand Down
18 changes: 18 additions & 0 deletions tests/pytest/test_input_dark_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from htmltools import css

from shiny.ui import input_dark_mode


def test_input_dark_mode_style():
base = input_dark_mode()
base_style = base.attrs["style"]
assert isinstance(base_style, str)

dark_mode = input_dark_mode(style="color: red;")
assert dark_mode.attrs["style"] == base_style + " color: red;"

css_position = css(position="absolute", top="1em", left="1em")
assert isinstance(css_position, str)

dark_mode = input_dark_mode(style=css_position)
assert dark_mode.attrs["style"] == base_style + " " + css_position

0 comments on commit 00d956e

Please sign in to comment.