Skip to content

Commit 9c6e520

Browse files
authored
Merge pull request #303 from torchbox/chore/light-mode-docs
Documentation and MR template updates relating to light mode
2 parents 5867f74 + 607b4f0 commit 9c6e520

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

.github/pull_request_template.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
- [ ] Not relevant
4646
- [ ] This adds new sources of PII and documents it and modifies Birdbath processors accordingly
4747

48+
#### Light and dark mode
49+
50+
- [ ] I have tested the changes in both light and dark mode
51+
- [ ] The change is not relevant to dark and light mode
52+
4853
#### Accessibility
4954

5055
- [ ] Automated WCAG 2.1 tests pass

docs/custom-features/modes.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Light and dark mode
2+
3+
The approach we use closely follows that used on the RNIB site.
4+
5+
## Dark mode by default
6+
7+
For sustainability reasons, we have a 'dark-mode-first' approach and serve up the site in dark mode by default.
8+
9+
This means that we do not check the user's preference using `prefers-color-scheme`, because there is no way to distinguish between 'light' and setting no preference - see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme#syntax. If we could detect a specific preference for light mode we could serve light mode up to those users - but if we serve it to users who have not set a preference as well then we are no longer serving dark mode by default.
10+
11+
## torchbox-mode cookie
12+
13+
The user can switch to light mode, and their preference will be saved in a `torchbox-mode` cookie. This always has a value of either `light` or `dark` - if it is set to anything different the site will be served in dark mode. If it is not present the site will be served in dark mode.
14+
15+
The cookie is set via JavaScript when the user clicks the toggle in the header area of the site. If JavaScript is disabled for any reason, the toggle submits a form, which will set the cookie on the server side, and refresh the page with the new mode enabled.
16+
17+
The cookie is always read on the server-side, which allows us to avoid a FOUC that might happen with reading the cookie with JavaScript. The page will be served up with a class of `mode-light` or `mode-dark` on the html class depending on the value of the cookie.
18+
19+
## Styling
20+
21+
See [themes and modes](/front-end/themes_and_modes).
22+
23+
## Incident form
24+
25+
The incident form is embedded in an iframe at https://torchbox.com/incident/. It also reads the `torchbox-mode` cookie and will render in dark or light mode accordingly - it also has some JavaScript that will watch for the cookie change and dynamically update the theme if it is switched whilst the incident form page is being viewed.
26+
27+
The `torchbox-mode` cookie therefore explicitly sets a `domain` value in order to be read by `incident-form.torchbox.com` where the form is hosted.
28+
29+
Note that there isn't any easy way to test the incident form's reading of the `torchbox-mode` cookie locally, as the domains won't match.
30+
31+
## Cloudflare workers
32+
33+
In order to avoid cloudflare caching an incorrect version of a page, we use some custom cloudflare workers to ensure that both versions of the page are cached, and the user's preference respected.

docs/front-end/themes_and_modes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Modes
44

5-
The site has been initially built in dark-mode only, but the longer-term plan is to introduce a toggle switch where the user can opt to display it in light mode. The CSS to set the mode is an html class of either `.mode-dark` or `.mode-light`.
5+
The CSS to set the mode is an html class of either `.mode-dark` or `.mode-light`.
66

77
## Themes
88

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ nav:
8383
- 'Custom features':
8484
- 'Migration-friendly StreamFields': 'custom-features/migration-friendly-streamfields.md'
8585
- 'Theme': 'custom-features/theme.md'
86+
- 'Modes': 'custom-features/modes.md'
8687
- 'Contact': 'custom-features/contact.md'
8788
- 'Continuous integration': 'continuous-integration.md'
8889
- 'Anonymised data': 'anonymised-data.md'

tbx/static_src/sass/config/_mixins.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@
215215
/* ============================================
216216
High Contrast mode in dark mode
217217
prefers-color-scheme: dark + forced-colors: active
218+
219+
Note that this is unrelated to the 'dark mode' option on the site.
218220
*/
219221
@mixin high-contrast-dark-mode() {
220222
@media (prefers-color-scheme: dark) and (forced-colors: active) {
@@ -225,6 +227,8 @@
225227
/* ============================================
226228
High Contrast mode in light mode
227229
prefers-color-scheme: light + forced-colors: active
230+
231+
Note that this is unrelated to the 'light mode' option on the site.
228232
*/
229233
@mixin high-contrast-light-mode() {
230234
@media (prefers-color-scheme: light) and (forced-colors: active) {

0 commit comments

Comments
 (0)