Skip to content

Commit 00d956e

Browse files
authored
fix(input_dark_mode): Allow users to customize style attribute (#1207)
1 parent 02d3f62 commit 00d956e

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

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

26+
* `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)
27+
2628
* Calling `ui.update_selectize()` with `choices` and `selected` now clears the current selection before updating the choices and selected value. (#1221)
2729

2830
* 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)

shiny/ui/_input_dark_mode.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,19 @@ def input_dark_mode(
5555

5656
return web_component(
5757
"bslib-input-dark-mode",
58+
{
59+
"style": css(
60+
**{
61+
"--text-1": "var(--bs-emphasis-color)",
62+
"--text-2": "var(--bs-tertiary-color)",
63+
# TODO: Fix the vertical correction to work better with Bootstrap
64+
"--vertical-correction": " ",
65+
},
66+
)
67+
},
5868
id=id,
5969
attribute="data-bs-theme",
6070
mode=mode,
61-
style=css(
62-
**{
63-
"--text-1": "var(--bs-emphasis-color)",
64-
"--text-2": "var(--bs-tertiary-color)",
65-
# TODO: Fix the vertical correction to work better with Bootstrap
66-
"--vertical-correction": " ",
67-
}
68-
),
6971
**kwargs,
7072
)
7173

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from htmltools import css
2+
3+
from shiny.ui import input_dark_mode
4+
5+
6+
def test_input_dark_mode_style():
7+
base = input_dark_mode()
8+
base_style = base.attrs["style"]
9+
assert isinstance(base_style, str)
10+
11+
dark_mode = input_dark_mode(style="color: red;")
12+
assert dark_mode.attrs["style"] == base_style + " color: red;"
13+
14+
css_position = css(position="absolute", top="1em", left="1em")
15+
assert isinstance(css_position, str)
16+
17+
dark_mode = input_dark_mode(style=css_position)
18+
assert dark_mode.attrs["style"] == base_style + " " + css_position

0 commit comments

Comments
 (0)