Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

impove islands styling slightly (#1233)

Myles Scolnick4eebcec13a27
diff --git a/frontend/postcss.config.cjs b/frontend/postcss.config.cjs
index 0b5c3217fa..d4ad7ae8ec 100644
--- a/frontend/postcss.config.cjs
+++ b/frontend/postcss.config.cjs
@@ -5,7 +5,7 @@ const config = {
require("tailwindcss"),
process.env.VITE_MARIMO_ISLANDS === "true"
? require("postcss-plugin-namespace")(".marimo", {
- ignore: [".marimo", "html", "body"],
+ ignore: [".marimo", "html", ".marimo:is(.dark *)"],
})
: undefined,
process.env.NODE_ENV === "production" ? require("cssnano") : undefined,
diff --git a/frontend/src/core/islands/islands.css b/frontend/src/core/islands/islands.css
index f9a4f81109..44a5296ce7 100644
--- a/frontend/src/core/islands/islands.css
+++ b/frontend/src/core/islands/islands.css
@@ -4,3 +4,7 @@
@import url("../../css/katex.min.css");
@import url("../../css/table.css");
@import url("../../css/md.css");
+
+.marimo {
+ @apply bg-background text-foreground;
+}
diff --git a/frontend/src/css/globals.css b/frontend/src/css/globals.css
index 8e0b7c4985..e0f245b292 100644
--- a/frontend/src/css/globals.css
+++ b/frontend/src/css/globals.css
@@ -25,7 +25,7 @@
@layer base {
:root,
- .light .marimo {
+ .marimo {
color-scheme: light;
--monospace-font: "Fira Mono";
@@ -104,7 +104,7 @@
}
.dark,
- .dark .marimo {
+ .marimo:is(.dark *) {
color-scheme: dark;
/* Radix dark colors for reference: https://github.com/radix-ui/colors/blob/main/src/dark.ts */
@@ -177,8 +177,7 @@
@apply border-border;
}
- body,
- .marimo {
+ body {
@apply bg-background text-foreground;
font-feature-settings:
diff --git a/frontend/src/theme/useTheme.ts b/frontend/src/theme/useTheme.ts
index d9bbe062fd..7d9141b314 100644
--- a/frontend/src/theme/useTheme.ts
+++ b/frontend/src/theme/useTheme.ts
@@ -2,6 +2,7 @@
import { store } from "@/core/state/jotai";
import { atom, useAtomValue } from "jotai";
import { userConfigAtom } from "@/core/config/config";
+import { isIslands } from "@/core/islands/utils";
export type Theme = "light" | "dark" | "system";
export type ResolvedTheme = "light" | "dark";
@@ -9,6 +10,27 @@ export type ResolvedTheme = "light" | "dark";
export const THEMES: Theme[] = ["light", "dark", "system"];
const themeAtom = atom((get) => {
+ // If it is islands, try a few ways to infer if it is dark mode.
+ if (isIslands()) {
+ // If it has a dark mode class on the body, use dark mode.
+ if (
+ document.body.classList.contains("dark-mode") ||
+ document.body.classList.contains("dark")
+ ) {
+ return "dark";
+ }
+ // If it has data-theme=dark or data-mode=dark on the body, use dark mode.
+ if (
+ document.body.dataset.theme === "dark" ||
+ document.body.dataset.mode === "dark"
+ ) {
+ return "dark";
+ }
+ // We don't want to infer from the system theme,
+ // since the island consumer may not support dark mode.
+ return "light";
+ }
+
return get(userConfigAtom).display.theme;
});