Skip to content

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

Preserve custom CSS overrides with Ant Design (#5162)

Gabe Kangasd27b78387472
diff --git a/test/automated/browser/cypress/e2e/offline/05-offline_identifier_check.cy.js b/test/automated/browser/cypress/e2e/offline/05-offline_identifier_check.cy.js
index ad2a86e879..c95f58ed4a 100644
--- a/test/automated/browser/cypress/e2e/offline/05-offline_identifier_check.cy.js
+++ b/test/automated/browser/cypress/e2e/offline/05-offline_identifier_check.cy.js
@@ -37,4 +37,105 @@ filterTests(['desktop'], () => {
cy.get(modalContainer, { timeout: 2000 }).should('be.visible');
});
});
+
+ describe('Applies documented CSS variable customizations', () => {
+ before(() => {
+ cy.setConfig('appearance', {
+ 'theme-color-action': 'blue',
+ });
+ cy.setConfig(
+ 'customstyles',
+ `:root {
+ --theme-color-action: red;
+ --theme-color-components-primary-button-border: green;
+ --theme-text-display-font-family: monospace;
+ --theme-text-body-font-family: monospace;
+ }
+
+ #notify-button {
+ border-width: 4px;
+ }
+
+ #notify-button:focus {
+ background-color: rgb(0, 0, 255);
+ }`,
+ );
+ cy.visit('http://localhost:8080/');
+ });
+
+ after(() => {
+ cy.setConfig('customstyles', '');
+ cy.setConfig('appearance', {});
+ });
+
+ it('applies font variables to native and Ant Design elements', () => {
+ cy.get('body').should('have.css', 'font-family', 'monospace');
+ cy.get('#global-header-text').should(
+ 'have.css',
+ 'font-family',
+ 'monospace',
+ );
+ cy.get('#notify-button').should('have.css', 'font-family', 'monospace');
+ });
+
+ it('lets custom variables override appearance variables', () => {
+ cy.document().then((document) => {
+ expect(
+ getComputedStyle(document.documentElement)
+ .getPropertyValue('--theme-color-action')
+ .trim(),
+ ).to.equal('red');
+ });
+ cy.get('#notify-button')
+ .should('have.css', 'background-color', 'rgb(255, 0, 0)')
+ .and('have.css', 'border-color', 'rgb(0, 128, 0)');
+ });
+
+ it('applies custom selectors with higher specificity than component styles', () => {
+ cy.get('#notify-button').should('have.css', 'border-width', '4px');
+ });
+
+ it('applies custom interactive state selectors', () => {
+ cy.get('#notify-button')
+ .focus()
+ .should('have.css', 'background-color', 'rgb(0, 0, 255)');
+ });
+
+ it('retains the cascade after a full page reload', () => {
+ cy.reload();
+ cy.get('#notify-button').should(
+ 'have.css',
+ 'background-color',
+ 'rgb(255, 0, 0)',
+ );
+ });
+ });
+});
+
+filterTests(['mobile'], () => {
+ describe('Applies responsive custom CSS', () => {
+ before(() => {
+ cy.setConfig(
+ 'customstyles',
+ `@media (max-width: 600px) {
+ #global-header-text {
+ color: rgb(0, 128, 0);
+ }
+ }`,
+ );
+ cy.visit('http://localhost:8080/');
+ });
+
+ after(() => {
+ cy.setConfig('customstyles', '');
+ });
+
+ it('applies media-query overrides at the mobile viewport', () => {
+ cy.get('#global-header-text').should(
+ 'have.css',
+ 'color',
+ 'rgb(0, 128, 0)',
+ );
+ });
+ });
});
diff --git a/web/components/theme/antd-default-theme.json b/web/components/theme/antd-default-theme.json
index 0b52f1e2a8..3a78d8d236 100644
--- a/web/components/theme/antd-default-theme.json
+++ b/web/components/theme/antd-default-theme.json
@@ -13,7 +13,7 @@
"colorTextSecondary": "#5d5f72",
"colorError": "#ff4b39",
"colorWarning": "#ffc655",
- "fontFamily": "Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif"
+ "fontFamily": "var(--theme-text-body-font-family)"
},
"components": {
"Modal": {
diff --git a/web/styles/ant-overrides.scss b/web/styles/ant-overrides.scss
index 25f2399b93..d9d61d60ec 100644
--- a/web/styles/ant-overrides.scss
+++ b/web/styles/ant-overrides.scss
@@ -8,6 +8,25 @@
height: auto;
}
+// Keep public Owncast CSS variables authoritative for Ant Design buttons.
+.ant-btn.ant-btn-color-primary {
+ --ant-btn-color-base: var(--theme-color-components-primary-button-background);
+ --ant-btn-color-hover: var(--theme-color-action-hover);
+ --ant-btn-color-active: var(--theme-color-action-hover);
+}
+
+.ant-btn.ant-btn-color-primary.ant-btn-variant-solid {
+ --ant-btn-border-color: var(--theme-color-components-primary-button-border);
+ --ant-btn-text-color: var(--theme-color-components-primary-button-text);
+}
+
+.ant-btn.ant-btn-color-primary:disabled,
+.ant-btn.ant-btn-color-primary.ant-btn-disabled {
+ border-color: var(--theme-color-components-primary-button-border-disabled);
+ color: var(--theme-color-components-primary-button-text-disabled);
+ background: var(--theme-color-components-primary-button-background-disabled);
+}
+
.ant-alert-error {
.ant-alert-icon {
color: var(--theme-color-palette-error);
diff --git a/web/styles/antd.css b/web/styles/antd.css
index 0f6df7ccae..b45f0c9c85 100644
--- a/web/styles/antd.css
+++ b/web/styles/antd.css
@@ -5292,9 +5292,7 @@ span.ant-typography-ellipsis-single-line {
--ant-color-link: #6544e9;
--ant-color-text-base: #000;
--ant-color-bg-base: #fff;
- --ant-font-family:
- Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
- Arial, 'Noto Sans', sans-serif;
+ --ant-font-family: var(--theme-text-body-font-family);
--ant-font-family-code: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
--ant-font-size: 14px;
--ant-line-width: 1px;
@@ -6158,9 +6156,7 @@ span.ant-typography-ellipsis-single-line {
--ant-color-link: #6544e9;
--ant-color-text-base: #000;
--ant-color-bg-base: #fff;
- --ant-font-family:
- Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
- Arial, 'Noto Sans', sans-serif;
+ --ant-font-family: var(--theme-text-body-font-family);
--ant-font-family-code: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
--ant-font-size: 14px;
--ant-line-width: 1px;
@@ -22650,9 +22646,7 @@ a[disabled] {
--ant-color-link: #6544e9;
--ant-color-text-base: #000;
--ant-color-bg-base: #fff;
- --ant-font-family:
- Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
- Arial, 'Noto Sans', sans-serif;
+ --ant-font-family: var(--theme-text-body-font-family);
--ant-font-family-code: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
--ant-font-size: 14px;
--ant-line-width: 1px;
diff --git a/web/tests/themeCascade.test.tsx b/web/tests/themeCascade.test.tsx
new file mode 100644
index 0000000000..ffede43b7c
--- /dev/null
+++ b/web/tests/themeCascade.test.tsx
@@ -0,0 +1,83 @@
+import { act, fireEvent, render } from '@testing-library/react';
+import { createStore, Provider } from 'jotai';
+import { ReactElement } from 'react';
+import { clientConfigStateAtom } from '../components/stores/ClientConfigStore';
+import { Theme } from '../components/theme/Theme';
+import { PluginTabFrame } from '../components/ui/PluginTabFrame/PluginTabFrame';
+import { ClientConfig, makeEmptyClientConfig } from '../interfaces/client-config.model';
+
+const CASCADE_VARIABLE = '--cascade-probe';
+const pluginStyles = `:root { ${CASCADE_VARIABLE}: plugin; }`;
+const appearanceVariables = { 'cascade-probe': 'appearance' };
+const customStyles = `:root { ${CASCADE_VARIABLE}: custom; }`;
+
+const renderWithConfig = (component: ReactElement, config: Partial<ClientConfig>) => {
+ const store = createStore();
+ store.set(clientConfigStateAtom, { ...makeEmptyClientConfig(), ...config });
+ return { store, ...render(<Provider store={store}>{component}</Provider>) };
+};
+
+const cascadeValue = (doc: Document) =>
+ doc.defaultView?.getComputedStyle(doc.documentElement).getPropertyValue(CASCADE_VARIABLE).trim();
+
+describe('theme cascade', () => {
+ it('orders plugin styles, appearance variables, and custom CSS on the viewer', () => {
+ const config = {
+ ...makeEmptyClientConfig(),
+ pluginStyles,
+ appearanceVariables,
+ customStyles,
+ };
+ const { store } = renderWithConfig(<Theme />, config);
+
+ expect(cascadeValue(document)).toBe('custom');
+
+ act(() => store.set(clientConfigStateAtom, { ...config, customStyles: '' }));
+ expect(cascadeValue(document)).toBe('appearance');
+
+ act(() =>
+ store.set(clientConfigStateAtom, {
+ ...config,
+ customStyles: '',
+ appearanceVariables: {},
+ }),
+ );
+ expect(cascadeValue(document)).toBe('plugin');
+ });
+
+ it.each([
+ ['plugin styles over author styles', { pluginStyles }, 'plugin'],
+ [
+ 'appearance variables over plugin styles',
+ { pluginStyles, appearanceVariables },
+ 'appearance',
+ ],
+ [
+ 'custom CSS over appearance variables',
+ { pluginStyles, appearanceVariables, customStyles },
+ 'custom',
+ ],
+ ])('applies %s inside plugin tabs', (_name, config, expected) => {
+ const { getByTitle } = renderWithConfig(
+ <PluginTabFrame content={`<style>:root { ${CASCADE_VARIABLE}: author; }</style>`} />,
+ config,
+ );
+ const frame = getByTitle('Plugin tab') as HTMLIFrameElement;
+ const doc = frame.contentDocument;
+ const win = frame.contentWindow;
+ expect(doc).not.toBeNull();
+ expect(win).not.toBeNull();
+
+ doc!.head.innerHTML = `<style>:root { ${CASCADE_VARIABLE}: author; }</style>`;
+ Object.defineProperty(win, 'ResizeObserver', {
+ configurable: true,
+ value: class ResizeObserver {
+ observe() {}
+ disconnect() {}
+ },
+ });
+ fireEvent.load(frame);
+
+ expect(cascadeValue(doc!)).toBe(expected);
+ });
+});