Skip to content

Commit 62897ec

Browse files
committed
refactor(anywidget): Simplify dark mode implementation
1 parent d20ed3c commit 62897ec

File tree

4 files changed

+0
-137
lines changed

4 files changed

+0
-137
lines changed

bigframes/display/anywidget.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class TableWidget(_WIDGET_BASE):
6868
page_size = traitlets.Int(0).tag(sync=True)
6969
row_count = traitlets.Int(allow_none=True, default_value=None).tag(sync=True)
7070
table_html = traitlets.Unicode("").tag(sync=True)
71-
css_styles = traitlets.Unicode("").tag(sync=True)
7271
sort_context = traitlets.List(traitlets.Dict(), default_value=[]).tag(sync=True)
7372
orderable_columns = traitlets.List(traitlets.Unicode(), []).tag(sync=True)
7473
_initial_load_complete = traitlets.Bool(False).tag(sync=True)
@@ -119,9 +118,6 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
119118
else:
120119
self.orderable_columns = []
121120

122-
# Load CSS manually to ensure it's available for JS injection if needed
123-
self.css_styles = self._css
124-
125121
self._initial_load()
126122

127123
# Signals to the frontend that the initial data load is complete.

bigframes/display/table_widget.js

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const ModelProperty = {
2222
ROW_COUNT: "row_count",
2323
SORT_CONTEXT: "sort_context",
2424
TABLE_HTML: "table_html",
25-
CSS_STYLES: "css_styles",
2625
};
2726

2827
const Event = {
@@ -38,14 +37,6 @@ const Event = {
3837
function render({ model, el }) {
3938
el.classList.add("bigframes-widget");
4039

41-
// Inject CSS styles passed from the backend.
42-
const cssStyles = model.get(ModelProperty.CSS_STYLES);
43-
if (cssStyles) {
44-
const style = document.createElement("style");
45-
style.textContent = cssStyles;
46-
el.appendChild(style);
47-
}
48-
4940
const errorContainer = document.createElement("div");
5041
errorContainer.classList.add("error-message");
5142

@@ -54,44 +45,6 @@ function render({ model, el }) {
5445
const footer = document.createElement("footer");
5546
footer.classList.add("footer");
5647

57-
/**
58-
* Adjusts container styles to prevent white frames in dark mode environments.
59-
* @param {boolean} isDark - Whether dark mode is active.
60-
*/
61-
function setContainerStyles(isDark) {
62-
const body = document.body;
63-
if (isDark) {
64-
// Clear background of ancestors to remove "white frame" from containers.
65-
let parent = el.parentElement;
66-
while (parent && parent !== document.body) {
67-
parent.style.setProperty(
68-
"background-color",
69-
"transparent",
70-
"important",
71-
);
72-
parent.style.setProperty("padding", "0", "important");
73-
parent = parent.parentElement;
74-
}
75-
76-
if (body) {
77-
body.style.setProperty("background-color", "#202124", "important");
78-
body.style.setProperty("margin", "0", "important");
79-
document.documentElement.style.setProperty(
80-
"background-color",
81-
"#202124",
82-
"important",
83-
);
84-
}
85-
} else {
86-
// Cleanup styles when switching back to light mode
87-
if (body) {
88-
body.style.removeProperty("background-color");
89-
body.style.removeProperty("margin");
90-
document.documentElement.style.removeProperty("background-color");
91-
}
92-
}
93-
}
94-
9548
/** Detects theme and applies necessary style overrides. */
9649
function updateTheme() {
9750
const body = document.body;
@@ -103,12 +56,8 @@ function render({ model, el }) {
10356

10457
if (isDark) {
10558
el.classList.add("bigframes-dark-mode");
106-
el.style.colorScheme = "dark";
107-
setContainerStyles(true);
10859
} else {
10960
el.classList.remove("bigframes-dark-mode");
110-
el.style.colorScheme = "light";
111-
setContainerStyles(false);
11261
}
11362
}
11463

tests/unit/display/test_anywidget.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -80,48 +80,6 @@ def handler(signum, frame):
8080
signal.alarm(0)
8181

8282

83-
def test_css_contains_dark_mode_media_query():
84-
from bigframes.display.anywidget import TableWidget
85-
86-
mock_df = mock.create_autospec(bigframes.dataframe.DataFrame, instance=True)
87-
# mock_df.columns and mock_df.dtypes are needed for __init__
88-
mock_df.columns = ["col1"]
89-
mock_df.dtypes = {"col1": "object"}
90-
91-
# Mock _block to avoid AttributeError during _set_table_html
92-
mock_block = mock.Mock()
93-
mock_block.has_index = False
94-
mock_df._block = mock_block
95-
96-
with mock.patch.object(TableWidget, "_initial_load"):
97-
widget = TableWidget(mock_df)
98-
assert "@media (prefers-color-scheme: dark)" in widget._css
99-
100-
101-
def test_css_styles_traitlet_is_populated():
102-
"""Verify that css_styles traitlet is populated from the external CSS file."""
103-
from bigframes.display.anywidget import TableWidget
104-
105-
# Mock the dataframe and its block
106-
mock_df = mock.create_autospec(bigframes.dataframe.DataFrame, instance=True)
107-
mock_df.columns = ["col1"]
108-
mock_df.dtypes = {"col1": "object"}
109-
mock_block = mock.Mock()
110-
mock_block.has_index = False
111-
mock_df._block = mock_block
112-
113-
# Mock _initial_load to avoid side effects
114-
with mock.patch.object(TableWidget, "_initial_load"):
115-
widget = TableWidget(mock_df)
116-
117-
# Check that css_styles is not empty
118-
assert widget.css_styles
119-
120-
# Check that it contains expected CSS content (e.g. dark mode query)
121-
assert "@media (prefers-color-scheme: dark)" in widget.css_styles
122-
assert ".bigframes-widget" in widget.css_styles
123-
124-
12583
@pytest.fixture
12684
def mock_df():
12785
df = mock.create_autospec(bigframes.dataframe.DataFrame, instance=True)

tests/unit/display/test_anywidget_css.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)