Skip to content

Commit bbc4234

Browse files
committed
feat: Detect dark mode via body classes/attributes in TableWidget
1 parent dc9073b commit bbc4234

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

bigframes/display/table_widget.js

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,33 @@ function render({ model, el }) {
3939
// Main container with a unique class for CSS scoping
4040
el.classList.add("bigframes-widget");
4141

42+
// Theme detection logic
43+
function updateTheme() {
44+
const body = document.body;
45+
// Check for common dark mode indicators in VS Code / Jupyter
46+
const isDark =
47+
body.classList.contains("vscode-dark") ||
48+
body.classList.contains("theme-dark") ||
49+
body.dataset.theme === "dark" ||
50+
body.getAttribute("data-vscode-theme-kind") === "vscode-dark";
51+
52+
if (isDark) {
53+
el.classList.add("bigframes-dark-mode");
54+
} else {
55+
el.classList.remove("bigframes-dark-mode");
56+
}
57+
}
58+
59+
// Initial check
60+
updateTheme();
61+
62+
// Observe body attribute changes to react to theme switching
63+
const observer = new MutationObserver(updateTheme);
64+
observer.observe(document.body, {
65+
attributes: true,
66+
attributeFilter: ["class", "data-theme", "data-vscode-theme-kind"],
67+
});
68+
4269
// Add error message container at the top
4370
const errorContainer = document.createElement("div");
4471
errorContainer.classList.add("error-message");
@@ -48,15 +75,6 @@ function render({ model, el }) {
4875
const footer = document.createElement("footer");
4976
footer.classList.add("footer");
5077

51-
// Debug info container
52-
const debugInfo = document.createElement("div");
53-
debugInfo.classList.add("debug-info");
54-
debugInfo.style.fontSize = "10px";
55-
debugInfo.style.color = "gray";
56-
debugInfo.style.marginTop = "8px";
57-
debugInfo.style.borderTop = "1px solid #ccc";
58-
debugInfo.style.paddingTop = "4px";
59-
6078
// Pagination controls
6179
const paginationContainer = document.createElement("div");
6280
paginationContainer.classList.add("pagination");
@@ -142,28 +160,6 @@ function render({ model, el }) {
142160
model.save_changes();
143161
}
144162

145-
function updateDebugInfo() {
146-
const computedStyle = getComputedStyle(el);
147-
const prefersDark = window.matchMedia(
148-
"(prefers-color-scheme: dark)",
149-
).matches;
150-
const vscodeFg = computedStyle.getPropertyValue(
151-
"--vscode-editor-foreground",
152-
);
153-
const vscodeBg = computedStyle.getPropertyValue(
154-
"--vscode-editor-background",
155-
);
156-
157-
debugInfo.innerHTML = `
158-
<strong>Debug Info:</strong><br>
159-
Prefers Dark Scheme: ${prefersDark}<br>
160-
VSCode Foreground: ${vscodeFg || "Not Set"}<br>
161-
VSCode Background: ${vscodeBg || "Not Set"}<br>
162-
Computed Color: ${computedStyle.color}<br>
163-
Computed Bg: ${computedStyle.backgroundColor}
164-
`;
165-
}
166-
167163
/** Updates the HTML in the table container and refreshes button states. */
168164
function handleTableHTMLChange() {
169165
// Note: Using innerHTML is safe here because the content is generated
@@ -241,7 +237,6 @@ function render({ model, el }) {
241237
});
242238

243239
updateButtonStates();
244-
updateDebugInfo();
245240
}
246241

247242
// Add error message handler
@@ -285,7 +280,6 @@ function render({ model, el }) {
285280
footer.appendChild(rowCountLabel);
286281
footer.appendChild(paginationContainer);
287282
footer.appendChild(pageSizeContainer);
288-
footer.appendChild(debugInfo);
289283

290284
el.appendChild(errorContainer);
291285
el.appendChild(tableContainer);

0 commit comments

Comments
 (0)