diff --git a/e2e/playground.e2e.ts b/e2e/playground.e2e.ts index a589595c4f9..6a141ea1449 100644 --- a/e2e/playground.e2e.ts +++ b/e2e/playground.e2e.ts @@ -248,11 +248,11 @@ test('the demo follows the site theme, including after a reset', async ({ page } const playground = page.locator('.playground').first(); const demo = playground.frameLocator('iframe[src*="ionic:mode=ios"]').locator('html'); - await expect(demo).toHaveClass(/ion-theme-dark/); + await expect(demo).toHaveClass(/ion-palette-dark/); // Marks the demo, so the check below waits for the reloaded one. await demo.evaluate((html) => html.setAttribute('data-before-reset', '')); await playground.getByRole('button', { name: 'Reset demo' }).click(); await expect(demo).not.toHaveAttribute('data-before-reset'); - await expect(demo).toHaveClass(/ion-theme-dark/); + await expect(demo).toHaveClass(/ion-palette-dark/); }); diff --git a/static/usage/v8/animations/preference-based/demo.html b/static/usage/v8/animations/preference-based/demo.html index a4f750e9118..d141beb1e62 100644 --- a/static/usage/v8/animations/preference-based/demo.html +++ b/static/usage/v8/animations/preference-based/demo.html @@ -49,7 +49,7 @@ } /* Demo does not use `prefers-color-scheme` media query because Docusaurus already checks for it. Otherwise, the demo might have the wrong background on certain edge cases. */ - body.dark ion-card { + .ion-palette-dark ion-card { --background: green; } diff --git a/static/usage/v8/common.js b/static/usage/v8/common.js index 752a7424bb6..9698ecb1c03 100644 --- a/static/usage/v8/common.js +++ b/static/usage/v8/common.js @@ -1,10 +1,3 @@ -const linkElement = document.createElement('link'); - -linkElement.rel = 'stylesheet'; -linkElement.href = 'https://cdn.jsdelivr.net/npm/@ionic/core@8/css/palettes/dark.class.css'; - -document.head.appendChild(linkElement); - /** * Wait for the initial HTML document to be * loaded and parsed before adding the message @@ -12,6 +5,22 @@ document.head.appendChild(linkElement); * listener will fire before the body is ready. */ window.addEventListener('DOMContentLoaded', () => { + /** + * The dark palette goes right after ionic.bundle.css, the order an app + * imports them in. Before it, the bundle's default colors win; after the + * demo's own styles, it overrides them. Demos that load a palette of + * their own, such as the theming demos, are left to it. + */ + if (!document.querySelector('link[href*="/css/palettes/"]')) { + const linkElement = document.createElement('link'); + + linkElement.rel = 'stylesheet'; + linkElement.href = 'https://cdn.jsdelivr.net/npm/@ionic/core@8/css/palettes/dark.class.css'; + + const bundle = document.querySelector('link[href*="ionic.bundle.css"]'); + bundle ? bundle.after(linkElement) : document.head.append(linkElement); + } + /** * The parent Playground component will * dispatch messages whenever the theme on @@ -23,9 +32,9 @@ window.addEventListener('DOMContentLoaded', () => { const { data } = event; if (data.darkMode) { - document.documentElement.classList.add('ion-theme-dark'); + document.documentElement.classList.add('ion-palette-dark'); } else { - document.documentElement.classList.remove('ion-theme-dark'); + document.documentElement.classList.remove('ion-palette-dark'); } }); diff --git a/static/usage/v8/datetime/styling/global-theming/demo.html b/static/usage/v8/datetime/styling/global-theming/demo.html index df3278ab1d8..a066f2d32df 100644 --- a/static/usage/v8/datetime/styling/global-theming/demo.html +++ b/static/usage/v8/datetime/styling/global-theming/demo.html @@ -10,8 +10,8 @@ diff --git a/static/usage/v9/common.js b/static/usage/v9/common.js index 486b95aab0c..17f5a81be5d 100644 --- a/static/usage/v9/common.js +++ b/static/usage/v9/common.js @@ -1,10 +1,3 @@ -const linkElement = document.createElement('link'); - -linkElement.rel = 'stylesheet'; -linkElement.href = 'https://cdn.jsdelivr.net/npm/@ionic/core@9/css/palettes/dark.class.css'; - -document.head.appendChild(linkElement); - /** * Wait for the initial HTML document to be * loaded and parsed before adding the message @@ -12,6 +5,22 @@ document.head.appendChild(linkElement); * listener will fire before the body is ready. */ window.addEventListener('DOMContentLoaded', () => { + /** + * The dark palette goes right after ionic.bundle.css, the order an app + * imports them in. Before it, the bundle's default colors win; after the + * demo's own styles, it overrides them. Demos that load a palette of + * their own, such as the theming demos, are left to it. + */ + if (!document.querySelector('link[href*="/css/palettes/"]')) { + const linkElement = document.createElement('link'); + + linkElement.rel = 'stylesheet'; + linkElement.href = 'https://cdn.jsdelivr.net/npm/@ionic/core@9/css/palettes/dark.class.css'; + + const bundle = document.querySelector('link[href*="ionic.bundle.css"]'); + bundle ? bundle.after(linkElement) : document.head.append(linkElement); + } + /** * The parent Playground component will * dispatch messages whenever the theme on @@ -23,9 +32,9 @@ window.addEventListener('DOMContentLoaded', () => { const { data } = event; if (data.darkMode) { - document.documentElement.classList.add('ion-theme-dark'); + document.documentElement.classList.add('ion-palette-dark'); } else { - document.documentElement.classList.remove('ion-theme-dark'); + document.documentElement.classList.remove('ion-palette-dark'); } }); diff --git a/static/usage/v9/datetime/styling/global-theming/demo.html b/static/usage/v9/datetime/styling/global-theming/demo.html index 50813a7e303..e99bbb29408 100644 --- a/static/usage/v9/datetime/styling/global-theming/demo.html +++ b/static/usage/v9/datetime/styling/global-theming/demo.html @@ -10,8 +10,8 @@