Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Make modals follow the configured theme

Gabe Kangas7e694ce093a5
diff --git a/web/public/styles/plugin.css b/web/public/styles/plugin.css
index 67aebcbf9f..f7faee149d 100644
--- a/web/public/styles/plugin.css
+++ b/web/public/styles/plugin.css
@@ -11,14 +11,14 @@
--link-color: var(--theme-color-action);
--link-hover-color: var(--theme-color-action-hover);
--modal-header-bg: var(--theme-color-components-modal-header-background);
- --modal-content-bg: var(--theme-color-background-main);
+ --modal-content-bg: var(--theme-color-components-modal-content-background);
--alert-error-bg-color: var(--theme-color-palette-4);
--alert-error-border-color: var(--theme-color-palette-error);
--popover-background: var(--theme-color-components-menu-background);
--tag-default-color: var(--theme-color-action);
--border-radius-base: var(--theme-rounded-corners);
--background-color-light: var(--theme-color-background-main);
- --modal-close-color: var(--theme-color-background-main);
+ --modal-close-color: var(--theme-color-components-modal-header-text);
--primary-color: #6544e9; /* Text link/secondary light text */
--primary-color-hover: #2386e2; /* Fun color 1 */
--primary-color-active: #7a5cf3; /* Text link hover */
@@ -106,13 +106,17 @@
--theme-color-palette-15
); /* Lighter background */
--theme-color-components-modal-header-background: var(
- --theme-color-palette-1
- ); /* Dark secondary */
- --theme-color-components-modal-header-text: var(--theme-color-palette-3); /* Light primary */
- --theme-color-components-modal-content-background: var(
- --theme-color-palette-3
+ --theme-color-background-header
+ ); /* Dark primary */
+ --theme-color-components-modal-header-text: var(
+ --theme-color-components-text-on-dark
); /* Light primary */
- --theme-color-components-modal-content-text: var(--theme-color-palette-0); /* Dark primary */
+ --theme-color-components-modal-content-background: var(
+ --theme-color-components-content-background
+ ); /* Lighter background */
+ --theme-color-components-modal-content-text: var(
+ --theme-color-components-text-on-light
+ ); /* Dark primary */
--theme-color-components-menu-background: var(--theme-color-palette-3); /* Light primary */
--theme-color-components-menu-item-text: var(--theme-color-palette-0); /* Dark primary */
--theme-color-components-menu-item-bg: transparent;
diff --git a/web/style-definitions/tokens/color/antd-overrides.yaml b/web/style-definitions/tokens/color/antd-overrides.yaml
index f6d342c129..46f8b6e2da 100644
--- a/web/style-definitions/tokens/color/antd-overrides.yaml
+++ b/web/style-definitions/tokens/color/antd-overrides.yaml
@@ -9,7 +9,7 @@ link-hover-color:
modal-header-bg:
value: 'var(--theme-color-components-modal-header-background)'
modal-content-bg:
- value: 'var(--theme-color-background-main)'
+ value: 'var(--theme-color-components-modal-content-background)'
alert-error-bg-color:
value: 'var(--theme-color-palette-4)'
alert-error-border-color:
@@ -23,7 +23,7 @@ border-radius-base:
background-color-light:
value: 'var(--theme-color-background-main)'
modal-close-color:
- value: 'var(--theme-color-background-main)'
+ value: 'var(--theme-color-components-modal-header-text)'
# This values need to be statically assigned at build time and cannot be
# overridden by the user at runtime.
diff --git a/web/style-definitions/tokens/color/default-theme.yaml b/web/style-definitions/tokens/color/default-theme.yaml
index 69dec0210a..8c523dec24 100644
--- a/web/style-definitions/tokens/color/default-theme.yaml
+++ b/web/style-definitions/tokens/color/default-theme.yaml
@@ -185,20 +185,24 @@ theme:
value: 'var(--theme-color-palette-15)'
comment: '{theme.color.palette.15.comment}'
+ # Modal colors follow the admin-configurable theme rather than fixed
+ # palette entries so modals respect a custom appearance. The header
+ # mirrors the page header/footer and the body mirrors the page content
+ # area, including their respective text colors.
modal:
header:
background:
- value: 'var(--theme-color-palette-1)'
- comment: '{theme.color.palette.1.comment}'
+ value: 'var(--theme-color-background-header)'
+ comment: '{theme.color.palette.0.comment}'
text:
- value: 'var(--theme-color-palette-3)'
+ value: 'var(--theme-color-components-text-on-dark)'
comment: '{theme.color.palette.3.comment}'
content:
background:
- value: 'var(--theme-color-palette-3)'
- comment: '{theme.color.palette.3.comment}'
+ value: 'var(--theme-color-components-content-background)'
+ comment: '{theme.color.palette.15.comment}'
text:
- value: 'var(--theme-color-palette-0)'
+ value: 'var(--theme-color-components-text-on-light)'
comment: '{theme.color.palette.0.comment}'
menu:
diff --git a/web/styles/theme.less b/web/styles/theme.less
index 7a3a5d8ce8..3d040e6f8a 100644
--- a/web/styles/theme.less
+++ b/web/styles/theme.less
@@ -9,14 +9,14 @@
@link-color: var(--theme-color-action);
@link-hover-color: var(--theme-color-action-hover);
@modal-header-bg: var(--theme-color-components-modal-header-background);
-@modal-content-bg: var(--theme-color-background-main);
+@modal-content-bg: var(--theme-color-components-modal-content-background);
@alert-error-bg-color: var(--theme-color-palette-4);
@alert-error-border-color: var(--theme-color-palette-error);
@popover-background: var(--theme-color-components-menu-background);
@tag-default-color: var(--theme-color-action);
@border-radius-base: var(--theme-rounded-corners);
@background-color-light: var(--theme-color-background-main);
-@modal-close-color: var(--theme-color-background-main);
+@modal-close-color: var(--theme-color-components-modal-header-text);
@primary-color: #6544e9; // Text link/secondary light text
@primary-color-hover: #2386e2; // Fun color 1
@primary-color-active: #7a5cf3; // Text link hover
@@ -86,10 +86,10 @@
@theme-color-components-chat-background: var(--theme-color-palette-1); // Dark primary
@theme-color-components-chat-text: var(--theme-color-palette-15); // Lighter background
@theme-color-components-content-background: var(--theme-color-palette-15); // Lighter background
-@theme-color-components-modal-header-background: var(--theme-color-palette-1); // Dark secondary
-@theme-color-components-modal-header-text: var(--theme-color-palette-3); // Light primary
-@theme-color-components-modal-content-background: var(--theme-color-palette-3); // Light primary
-@theme-color-components-modal-content-text: var(--theme-color-palette-0); // Dark primary
+@theme-color-components-modal-header-background: var(--theme-color-background-header); // Dark primary
+@theme-color-components-modal-header-text: var(--theme-color-components-text-on-dark); // Light primary
+@theme-color-components-modal-content-background: var(--theme-color-components-content-background); // Lighter background
+@theme-color-components-modal-content-text: var(--theme-color-components-text-on-light); // Dark primary
@theme-color-components-menu-background: var(--theme-color-palette-3); // Light primary
@theme-color-components-menu-item-text: var(--theme-color-palette-0); // Dark primary
@theme-color-components-menu-item-bg: transparent;
diff --git a/web/styles/variables.css b/web/styles/variables.css
index b6f8e854af..42200fc639 100644
--- a/web/styles/variables.css
+++ b/web/styles/variables.css
@@ -11,14 +11,14 @@
--link-color: var(--theme-color-action);
--link-hover-color: var(--theme-color-action-hover);
--modal-header-bg: var(--theme-color-components-modal-header-background);
- --modal-content-bg: var(--theme-color-background-main);
+ --modal-content-bg: var(--theme-color-components-modal-content-background);
--alert-error-bg-color: var(--theme-color-palette-4);
--alert-error-border-color: var(--theme-color-palette-error);
--popover-background: var(--theme-color-components-menu-background);
--tag-default-color: var(--theme-color-action);
--border-radius-base: var(--theme-rounded-corners);
--background-color-light: var(--theme-color-background-main);
- --modal-close-color: var(--theme-color-background-main);
+ --modal-close-color: var(--theme-color-components-modal-header-text);
--primary-color: #6544e9; /* Text link/secondary light text */
--primary-color-hover: #2386e2; /* Fun color 1 */
--primary-color-active: #7a5cf3; /* Text link hover */
@@ -113,13 +113,17 @@
--theme-color-palette-15
); /* Lighter background */
--theme-color-components-modal-header-background: var(
- --theme-color-palette-1
- ); /* Dark secondary */
- --theme-color-components-modal-header-text: var(--theme-color-palette-3); /* Light primary */
- --theme-color-components-modal-content-background: var(
- --theme-color-palette-3
+ --theme-color-background-header
+ ); /* Dark primary */
+ --theme-color-components-modal-header-text: var(
+ --theme-color-components-text-on-dark
); /* Light primary */
- --theme-color-components-modal-content-text: var(--theme-color-palette-0); /* Dark primary */
+ --theme-color-components-modal-content-background: var(
+ --theme-color-components-content-background
+ ); /* Lighter background */
+ --theme-color-components-modal-content-text: var(
+ --theme-color-components-text-on-light
+ ); /* Dark primary */
--theme-color-components-menu-background: var(--theme-color-palette-3); /* Light primary */
--theme-color-components-menu-item-text: var(--theme-color-palette-0); /* Dark primary */
--theme-color-components-menu-item-bg: transparent;
@@ -171,10 +175,12 @@
--color-owncast-palette-15: #eff1f4; /* Lighter background */
--color-owncast-palette-error: #ff4b39; /* Error */
--color-owncast-palette-warning: #ffc655; /* Warning */
- --font-owncast-body: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
- 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
- 'Segoe UI Symbol', 'Noto Color Emoji';
- --font-owncast-display: 'Poppins', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
- Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
- 'Segoe UI Symbol', 'Noto Color Emoji';
+ --font-owncast-body:
+ 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
+ Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
+ 'Noto Color Emoji';
+ --font-owncast-display:
+ 'Poppins', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
+ Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
+ 'Noto Color Emoji';
}
diff --git a/web/tests/modalTheming.test.ts b/web/tests/modalTheming.test.ts
new file mode 100644
index 0000000000..8e176dba28
--- /dev/null
+++ b/web/tests/modalTheming.test.ts
@@ -0,0 +1,108 @@
+import fs from 'fs';
+import path from 'path';
+
+// These tests guard against a regression where modal colors were hardcoded to
+// fixed palette entries (e.g. --theme-color-palette-3) instead of deriving from
+// the admin-configurable theme variables. Because they were not indirected
+// through the themeable variables, modals always rendered as a "dark header +
+// light body" card and ignored any custom theme.
+//
+// The generated variables.css is the source of truth the browser actually
+// loads, so we parse its :root block and follow the var() chains the same way
+// the browser would.
+
+const variablesCssPath = path.join(__dirname, '..', 'styles', 'variables.css');
+const css = fs.readFileSync(variablesCssPath, 'utf8');
+
+function parseRootVariables(source: string): Record<string, string> {
+ const rootMatch = source.match(/:root\s*\{([\s\S]*?)\}/);
+ if (!rootMatch) {
+ throw new Error('No :root block found in variables.css');
+ }
+ const vars: Record<string, string> = {};
+ const declRegex = /(--[\w-]+)\s*:\s*([^;]+);/g;
+ let match: RegExpExecArray | null;
+ // eslint-disable-next-line no-cond-assign
+ while ((match = declRegex.exec(rootMatch[1])) !== null) {
+ // Values may be wrapped across multiple lines by the generator, e.g.
+ // `var(\n --foo\n)`. Collapse internal whitespace so var() references
+ // resolve regardless of formatting.
+ vars[match[1].trim()] = match[2].replace(/\s+/g, ' ').trim();
+ }
+ return vars;
+}
+
+const vars = parseRootVariables(css);
+
+// Resolve a variable's final value by following single var(--x) references.
+// `overrides` simulates the runtime appearance variables that the admin theme
+// editor (and theme plugins) inject into :root, which take precedence.
+function resolve(
+ name: string,
+ overrides: Record<string, string> = {},
+ seen: Set<string> = new Set(),
+): string {
+ if (overrides[name] !== undefined) {
+ return overrides[name];
+ }
+ if (seen.has(name)) {
+ throw new Error(`Cyclic variable reference at ${name}`);
+ }
+ seen.add(name);
+
+ const value = vars[name];
+ if (value === undefined) {
+ return '';
+ }
+
+ const varMatch = value.match(/^var\(\s*(--[\w-]+)\s*\)$/);
+ if (varMatch) {
+ return resolve(varMatch[1], overrides, seen);
+ }
+ return value;
+}
+
+describe('modal theming', () => {
+ // The four modal color slots and the themeable variable each must follow.
+ const followsTheme: Array<[string, string]> = [
+ [
+ '--theme-color-components-modal-content-background',
+ '--theme-color-components-content-background',
+ ],
+ ['--theme-color-components-modal-content-text', '--theme-color-components-text-on-light'],
+ ['--theme-color-components-modal-header-background', '--theme-color-background-header'],
+ ['--theme-color-components-modal-header-text', '--theme-color-components-text-on-dark'],
+ ];
+
+ test.each(followsTheme)('%s follows %s when a custom theme is applied', (modalVar, themeVar) => {
+ const customColor = '#abcdef';
+ expect(resolve(modalVar, { [themeVar]: customColor })).toBe(customColor);
+ });
+
+ test('the Ant modal-content-bg override follows the themed modal content background', () => {
+ const customColor = '#123456';
+ expect(
+ resolve('--modal-content-bg', {
+ '--theme-color-components-content-background': customColor,
+ }),
+ ).toBe(customColor);
+ });
+
+ test('the modal close icon color follows the themed modal header text', () => {
+ const customColor = '#fedcba';
+ expect(
+ resolve('--modal-close-color', {
+ '--theme-color-components-text-on-dark': customColor,
+ }),
+ ).toBe(customColor);
+ });
+
+ test('modal colors are not hardcoded directly to a fixed palette entry', () => {
+ // Each modal variable must point at a themeable component variable, never
+ // straight at a --theme-color-palette-* entry (the original bug).
+ followsTheme.forEach(([modalVar]) => {
+ expect(vars[modalVar]).toBeDefined();
+ expect(vars[modalVar]).not.toMatch(/var\(\s*--theme-color-palette-\d+\s*\)/);
+ });
+ });
+});