From aca8ea63b616f46e827519968f989db26b96ba31 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Fri, 8 Mar 2024 12:31:16 -0500 Subject: [PATCH 1/2] fix(input_dark_mode): Allow users to customize `style` attribute --- shiny/ui/_input_dark_mode.py | 18 ++++++++++-------- tests/pytest/test_input_dark_mode.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 tests/pytest/test_input_dark_mode.py diff --git a/shiny/ui/_input_dark_mode.py b/shiny/ui/_input_dark_mode.py index 2439000d7..1d4f68bc6 100644 --- a/shiny/ui/_input_dark_mode.py +++ b/shiny/ui/_input_dark_mode.py @@ -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, ) diff --git a/tests/pytest/test_input_dark_mode.py b/tests/pytest/test_input_dark_mode.py new file mode 100644 index 000000000..1b287249a --- /dev/null +++ b/tests/pytest/test_input_dark_mode.py @@ -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 From 3e343ed100f3d47d9e42964b038e39a989bc6405 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Fri, 8 Mar 2024 12:32:16 -0500 Subject: [PATCH 2/2] docs: Add news --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cf9e3435..397141302 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes +* `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) + ### Other changes ## [0.8.1] - 2024-03-06