Skip to content

Commit e745ace

Browse files
authored
Add theming support to error page (#2077)
1 parent ba51f61 commit e745ace

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

special-pages/pages/errorpage/public/index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta http-equiv="X-UA-Compatible" content="ie=edge">
88
<link rel="stylesheet" href="style.css">
99
</head>
10-
<body>
10+
<body data-theme-variant="$THEME_VARIANT$">
1111
<div class="content-container">
1212
<div class="error-container">
1313
<div class="header-container">
@@ -21,5 +21,16 @@ <h1 class="error-header">$HEADER$</h1>
2121
<img src="img/logo-horizontal.svg" alt="DuckDuckGo" class="watermark">
2222
</div>
2323
</div>
24+
<script>
25+
/**
26+
* Called by native to update the page theme at runtime
27+
* @param {{ themeVariant: string }} payload
28+
*/
29+
window.onChangeTheme = function(payload) {
30+
if (payload && payload.themeVariant) {
31+
document.body.dataset.themeVariant = payload.themeVariant;
32+
}
33+
};
34+
</script>
2435
</body>
2536
</html>

special-pages/pages/errorpage/public/style.css

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,26 @@ body {
6565
.error-description, .error-header {
6666
color: rgb(210, 210, 210);
6767
}
68-
}
68+
}
69+
70+
/* TODO: Use colour variables from design-tokens */
71+
72+
/* Theme variants - light mode */
73+
[data-theme-variant="coolGray"] { background: #d2d5e3; }
74+
[data-theme-variant="slateBlue"] { background: #d2e5f3; }
75+
[data-theme-variant="green"] { background: #e3eee1; }
76+
[data-theme-variant="violet"] { background: #e7e4f5; }
77+
[data-theme-variant="rose"] { background: #f8ebf5; }
78+
[data-theme-variant="orange"] { background: #fcedd8; }
79+
[data-theme-variant="desert"] { background: #eee9e1; }
80+
81+
/* Theme variants - dark mode */
82+
@media (prefers-color-scheme: dark) {
83+
[data-theme-variant="coolGray"] { background: #2b2f45; }
84+
[data-theme-variant="slateBlue"] { background: #1e3347; }
85+
[data-theme-variant="green"] { background: #203b30; }
86+
[data-theme-variant="violet"] { background: #2e2158; }
87+
[data-theme-variant="rose"] { background: #5b194b; }
88+
[data-theme-variant="orange"] { background: #54240c; }
89+
[data-theme-variant="desert"] { background: #3c3833; }
90+
}

special-pages/pages/errorpage/readme.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,34 @@ So far, the following platforms are supported
1010

1111
- macOS
1212

13+
### Theming
14+
15+
The error page supports theming through two mechanisms:
16+
17+
#### Template Variable: `$THEME_VARIANT$`
18+
19+
Native performs string interpolation to replace `$THEME_VARIANT$` in the HTML with a theme variant name.
20+
21+
If string interpolation is not performed (i.e., `$THEME_VARIANT$` is left as-is), the page falls back to the default styling.
22+
23+
**Supported variants:** `default`, `coolGray`, `slateBlue`, `green`, `violet`, `rose`, `orange`, `desert`
24+
25+
#### Callback: `window.onChangeTheme`
26+
27+
Native can call `window.onChangeTheme(payload)` to update the theme at runtime.
28+
29+
**Payload:**
30+
```json
31+
{
32+
"themeVariant": "coolGray"
33+
}
34+
```
35+
36+
**Example native usage:**
37+
```javascript
38+
window.onChangeTheme({ themeVariant: 'coolGray' });
39+
```
40+
1341
---
1442

1543
## Contributing
@@ -26,4 +54,3 @@ Don't edit the generated files directly - any changes you make will not be refle
2654

2755
Instead, make your changes in `src/` and then run `npm run build` from the root folder
2856
- or to build the special pages only (faster), run `npm run postbuild` instead
29-

0 commit comments

Comments
 (0)