Skip to content

Commit 4586638

Browse files
committed
test(modal, scripts): use config palette in scripts
1 parent 7db9e9c commit 4586638

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

core/scripts/testing/scripts.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ const DEFAULT_THEME = 'md';
8787
* Values can be `light`, `dark`, `high-contrast`,
8888
* or `high-contrast-dark`. Default to `light` for tests.
8989
*/
90-
const paletteQuery = window.location.search.match(/palette=([a-z]+)/);
91-
const paletteHash = window.location.hash.match(/palette=([a-z]+)/);
90+
const configDarkMode = window.Ionic?.config?.customTheme?.palette?.dark?.enabled === 'always' ? 'dark' : null;
91+
const configHighContrastMode = window.Ionic?.config?.customTheme?.palette?.highContrast?.enabled === 'always' ? 'high-contrast' : null;
92+
const configHighContrastDarkMode = window.Ionic?.config?.customTheme?.palette?.highContrastDark?.enabled === 'always' ? 'high-contrast-dark' : null;
93+
const configPalette = configDarkMode || configHighContrastMode || configHighContrastDarkMode;
94+
const paletteQuery = window.location.search.match(/palette=([a-z-]+)/);
95+
const paletteHash = window.location.hash.match(/palette=([a-z-]+)/);
9296
const darkClass = document.body?.classList.contains('ion-palette-dark') ? 'dark' : null;
9397

94-
const paletteName = paletteQuery?.[1] || paletteHash?.[1] || darkClass || 'light';
98+
const paletteName = configPalette || paletteQuery?.[1] || paletteHash?.[1] || darkClass || 'light';
9599

96100
// Load theme tokens if the theme is valid
97101
const validThemes = ['ionic', 'ios', 'md'];

core/src/components/modal/test/dark-mode/index.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,22 @@
88
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
99
/>
1010
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
11-
<link href="../../../../../css/palettes/dark.always.css" rel="stylesheet" />
1211
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
12+
<script>
13+
// Need to be called before loading Ionic else
14+
// the scripts.js logic runs too early.
15+
window.Ionic = {
16+
config: {
17+
customTheme: {
18+
palette: {
19+
dark: {
20+
enabled: 'always',
21+
},
22+
},
23+
},
24+
},
25+
};
26+
</script>
1327
<script src="../../../../../scripts/testing/scripts.js"></script>
1428
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
1529
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>

0 commit comments

Comments
 (0)