Skip to content

Commit db751ac

Browse files
History: Use design system colors (#2097)
* Add theme variant CSS vars, fix background colors * Swap history color vars with --ds color vars * Add empty history mock * Update header, item, and sidebar to use --ds colors * Fix icon color typo * Fix: Prevent theme flash by using useLayoutEffect and sync initial theme Co-authored-by: randerson <randerson@duckduckgo.com> * Remove synchronous theme variant application Co-authored-by: randerson <randerson@duckduckgo.com> * Fix prettier formatting * Update snapshots * DRY NTP and history's theme mappings into shared theme-mappings.css --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 29f2286 commit db751ac

24 files changed

+828
-892
lines changed

special-pages/pages/history/app/components/App.jsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,7 @@ export function App() {
6464
}, [onKeyDown, query]);
6565

6666
return (
67-
<div
68-
class={styles.layout}
69-
data-theme={theme}
70-
data-theme-variant={themeVariant}
71-
data-platform={platformName}
72-
data-layout-mode={mode}
73-
onClick={clickAnywhere}
74-
>
67+
<div class={styles.layout} data-platform={platformName} data-layout-mode={mode} onClick={clickAnywhere}>
7568
<aside class={styles.aside}>
7669
<Sidebar ranges={ranges} />
7770
</aside>

special-pages/pages/history/app/components/App.module.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import url("../../../../shared/styles/variables.css");
2+
@import url("../../../../shared/styles/theme-mappings.css");
23
@import url("../../styles/base.css");
34
@import url("../../styles/history-theme.css");
45

@@ -7,7 +8,7 @@ body {
78
font-weight: var(--body-font-weight);
89
line-height: var(--body-line-height);
910
background-color: var(--history-background-color);
10-
color: var(--history-text-normal);
11+
color: var(--ds-color-theme-text-primary);
1112
}
1213

1314
.layout {
@@ -55,7 +56,7 @@ body {
5556
padding: 10px 16px;
5657
/* Nav child will handle this to accommodate a scrollbar */
5758
padding-right: 0;
58-
border-right: 1px solid var(--history-surface-border-color);
59+
border-right: 1px solid var(--ds-color-theme-surface-decoration-primary);
5960
}
6061

6162
.main {

special-pages/pages/history/app/components/Header.module.css

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
justify-content: space-between;
44
align-items: center;
55
gap: 8px;
6-
color: var(--history-text-normal);
6+
color: var(--ds-color-theme-text-primary);
77
padding: 16px 0;
8-
border-bottom: 1px solid var(--history-surface-border-color);
8+
border-bottom: 1px solid var(--ds-color-theme-surface-decoration-primary);
99
}
1010

1111
.controls {
@@ -22,7 +22,7 @@
2222
height: 28px;
2323
border: none;
2424
border-radius: 4px;
25-
color: var(--history-text-normal);
25+
color: var(--ds-color-theme-text-primary);
2626
padding-left: 8px;
2727
padding-right: 8px;
2828

@@ -32,17 +32,11 @@
3232
}
3333

3434
&:hover {
35-
background-color: var(--color-black-at-6);
36-
[data-theme="dark"] & {
37-
background-color: var(--color-white-at-6)
38-
}
35+
background-color: var(--ds-color-theme-control-fill-secondary);
3936
}
4037

4138
&:active {
42-
background-color: var(--color-black-at-12);
43-
[data-theme="dark"] & {
44-
background-color: var(--color-white-at-12)
45-
}
39+
background-color: var(--ds-color-theme-control-fill-tertiary);
4640
}
4741

4842
&[aria-disabled="true"] {
@@ -72,30 +66,29 @@
7266
top: 50%;
7367
left: 9px;
7468
transform: translateY(-50%);
75-
color: black;
76-
[data-theme="dark"] & {
77-
color: white;
78-
}
69+
color: var(--ds-color-theme-icons-primary);
7970
}
8071
.searchInput {
8172
width: 100%;
8273
height: 28px;
8374
border-radius: 6px;
84-
border: 0.5px solid var(--history-surface-border-color);
75+
border: 0.5px solid var(--ds-color-theme-control-border-primary);
8576
/* these precise numbers help it match figma when overriding default UI */
8677
padding-left: 31px;
8778
padding-right: 9px;
8879
background: inherit;
8980
color: inherit;
81+
background: var(--ds-color-theme-surface-tertiary);
9082

91-
[data-theme="dark"] & {
92-
background: var(--color-white-at-6);
93-
border-color: var(--color-white-at-9);
83+
&:hover {
84+
border-color: var(--ds-color-theme-control-border-secondary);
9485
}
9586

9687
&:focus {
9788
outline: none;
98-
box-shadow: 0px 0px 0px 2.5px rgba(87, 151, 237, 0.64), 0px 0px 0px 1px rgba(87, 151, 237, 0.64) inset, 0px 0.5px 0px -0.5px rgba(0, 0, 0, 0.10), 0px 1px 0px -0.5px rgba(0, 0, 0, 0.10);
89+
border: 2px solid var(--ds-color-theme-accent-primary);
90+
padding-left: 29.5px;
91+
padding-right: 7.5px;
9992
}
10093

10194
&::-webkit-search-cancel-button {
@@ -111,4 +104,4 @@
111104
[data-theme="dark"] &::-webkit-search-cancel-button {
112105
background-image: url("../../public/icons/clear-dark.svg");
113106
}
114-
}
107+
}

special-pages/pages/history/app/components/Item.module.css

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
font-weight: var(--title-3-em-font-weight);
1111
line-height: var(--title-3-em-line-height);
1212
white-space: nowrap;
13-
color: var(--history-text-normal);
13+
color: var(--ds-color-theme-text-primary);
1414
display: flex;
1515
align-items: center;
1616
padding-left: 8px;
@@ -32,8 +32,8 @@
3232
.hover {
3333
--row-bg: inherit;
3434
--row-radius: 5px;
35-
--row-color: var(--history-text-normal);
36-
--dots-bg-hover: var(--color-black-at-9);
35+
--row-color: var(--ds-color-theme-text-primary);
36+
--dots-bg-hover: var(--ds-color-theme-control-fill-primary);
3737
--dots-opacity: 0;
3838
--time-opacity: 0.6;
3939
--time-visibility: visible;
@@ -49,20 +49,17 @@
4949
}
5050

5151
&:hover:not([aria-selected="true"]) {
52-
--row-bg: var(--color-black-at-6);
53-
[data-theme="dark"] & {
54-
--row-bg: var(--color-white-at-6);
55-
}
52+
--row-bg: var(--ds-color-theme-control-fill-primary);
5653
}
5754

58-
[data-theme="dark"] & {
59-
--dots-bg-hover: var(--color-white-at-12);
55+
&:active:not([aria-selected="true"]) {
56+
--row-bg: var(--ds-color-theme-control-fill-secondary);
6057
}
6158

6259
&[aria-selected="true"] {
63-
--row-bg: #2565D9;
64-
--row-color: var(--color-white-at-84);
65-
--dots-bg-hover: var(--color-white-at-9);
60+
--row-bg: var(--ds-color-theme-accent-primary);
61+
--row-color: var(--ds-color-theme-accent-content-primary);
62+
--dots-bg-hover: var(--ds-color-theme-accent-secondary);
6663
}
6764
}
6865

@@ -163,4 +160,4 @@
163160

164161
.last {
165162
margin-bottom: 24px;
166-
}
163+
}

special-pages/pages/history/app/components/Sidebar.module.css

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212

1313
.pageTitle {
14-
color: var(--history-text-normal);
14+
color: var(--ds-color-theme-text-primary);
1515
font-size: var(--title-font-size);
1616
font-weight: var(--title-font-weight);
1717
line-height: 24px;
@@ -29,15 +29,11 @@
2929

3030
&:hover,
3131
&:focus-visible {
32-
background: var(--color-black-at-6);
32+
background: var(--ds-color-theme-control-fill-primary);
3333
}
3434

35-
[data-theme="dark"] & {
36-
37-
&:hover,
38-
&:focus-visible {
39-
background: var(--color-white-at-6);
40-
}
35+
&:active {
36+
background: var(--ds-color-theme-control-fill-secondary);
4137
}
4238

4339
&.item_sites {
@@ -49,11 +45,7 @@
4945
top: -8px;
5046
left: 16px;
5147
right: 16px;
52-
border-top: 1px solid var(--color-black-at-6);
53-
}
54-
55-
[data-theme="dark"] &::before {
56-
border-top: 1px solid var(--color-white-at-6);
48+
border-top: 1px solid var(--ds-color-theme-surface-decoration-primary);
5749
}
5850
}
5951
}
@@ -64,18 +56,10 @@
6456
}
6557

6658
.active {
67-
background: var(--color-black-at-12);
59+
background: var(--ds-color-theme-control-fill-secondary);
6860

6961
&:hover {
70-
background: var(--color-black-at-18);
71-
}
72-
73-
[data-theme="dark"] & {
74-
background: var(--color-white-at-9);
75-
76-
&:hover {
77-
background: var(--color-white-at-12);
78-
}
62+
background: var(--ds-color-theme-control-fill-tertiary);
7963
}
8064
}
8165

@@ -84,7 +68,7 @@
8468
font-size: var(--label-font-size);
8569
font-weight: var(--label-font-weight);
8670
line-height: var(--label-line-height);
87-
color: var(--history-text-normal);
71+
color: var(--ds-color-theme-text-primary);
8872

8973
height: 40px;
9074
display: flex;
@@ -115,28 +99,18 @@
11599
border: none;
116100
cursor: pointer;
117101
opacity: 0;
118-
color: var(--history-text-normal);
102+
color: var(--ds-color-theme-text-primary);
119103

120104
&:not([aria-disabled="true"]) {
121105

122106
&:hover,
123107
&:focus-visible {
124-
background: var(--color-black-at-9);
108+
background: var(--ds-color-theme-control-fill-primary);
125109
opacity: 1;
126110
}
127-
}
128-
129-
&:active {
130-
background: var(--color-black-at-12);
131-
}
132-
133-
[data-theme="dark"] & {
134-
&:hover {
135-
background: var(--color-white-at-9);
136-
}
137111

138112
&:active {
139-
background: var(--color-white-at-12);
113+
background: var(--ds-color-theme-control-fill-secondary);
140114
}
141115
}
142116

special-pages/pages/history/app/components/VirtualizedList.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
width: 100%;
1515
height: 100%;
1616
text-align: center;
17-
color: var(--history-text-normal);
17+
color: var(--ds-color-theme-text-primary);
1818
display: grid;
1919
grid-template-rows: max-content max-content;
2020
justify-items: center;
@@ -45,5 +45,5 @@
4545
}
4646
.emptyText {
4747
margin-top: 8px;
48-
color: var(--history-text-muted)
48+
color: var(--ds-color-theme-text-secondary)
4949
}

special-pages/pages/history/app/global/Providers/ThemeProvider.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createContext, h } from 'preact';
2-
import { useContext, useEffect, useState } from 'preact/hooks';
2+
import { useContext, useEffect, useLayoutEffect, useState } from 'preact/hooks';
33
import { useMessaging } from '../../types.js';
44
import { useEnv } from '../../../../../shared/components/EnvironmentProvider.js';
55

@@ -41,6 +41,14 @@ export function ThemeProvider({ children, initialTheme, initialThemeVariant }) {
4141
const theme = explicitTheme ?? initialTheme ?? (isDarkMode ? 'dark' : 'light');
4242
const themeVariant = explicitThemeVariant ?? initialThemeVariant ?? 'default';
4343

44+
// Sync theme attributes to <body>
45+
useLayoutEffect(() => {
46+
document.body.dataset.theme = theme;
47+
}, [theme]);
48+
useLayoutEffect(() => {
49+
document.body.dataset.themeVariant = themeVariant;
50+
}, [themeVariant]);
51+
4452
return <ThemeContext.Provider value={{ theme, themeVariant }}>{children}</ThemeContext.Provider>;
4553
}
4654

special-pages/pages/history/app/mocks/history.mocks.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import { HistoryService } from '../history.service.js';
44
* @type {Record<string, import("../../types/history").HistoryQueryResponse>}
55
*/
66
export const historyMocks = {
7+
empty: {
8+
info: {
9+
finished: true,
10+
query: { term: '' },
11+
},
12+
value: [],
13+
},
714
few: {
815
info: {
916
finished: true,

special-pages/pages/history/integration-tests/history-theme.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,48 @@ test.describe('history theme and theme variants', () => {
66
const hp = HistoryTestPage.create(page, workerInfo);
77
await hp.openPage({ additional: { theme: 'dark', themeVariant: 'violet' } });
88
await hp.hasTheme('dark', 'violet');
9-
await hp.hasBackgroundColor({ hex: '#2e2158' });
9+
await hp.hasBackgroundColor({ hex: '#271c49' }); // violet dark surface-canvas
1010
});
1111

1212
test('setting theme = light and themeVariant via initialSetup', async ({ page }, workerInfo) => {
1313
const hp = HistoryTestPage.create(page, workerInfo);
1414
await hp.openPage({ additional: { theme: 'light', themeVariant: 'coolGray' } });
1515
await hp.hasTheme('light', 'coolGray');
16-
await hp.hasBackgroundColor({ hex: '#d2d5e3' });
16+
await hp.hasBackgroundColor({ hex: '#e3e5ec' }); // coolGray light surface-canvas
1717
});
1818

1919
test('light theme and default themeVariant when unspecified', async ({ page }, workerInfo) => {
2020
const hp = HistoryTestPage.create(page, workerInfo);
2121
await hp.openPage();
2222
await hp.hasTheme('light', 'default');
23-
await hp.hasBackgroundColor({ hex: '#fafafa' });
23+
await hp.hasBackgroundColor({ hex: '#fafafa' }); // default light surface-canvas
2424
});
2525

2626
test('dark theme and default themeVariant when unspecified', async ({ page }, workerInfo) => {
2727
const hp = HistoryTestPage.create(page, workerInfo);
2828
await hp.darkMode();
2929
await hp.openPage();
3030
await hp.hasTheme('dark', 'default');
31-
await hp.hasBackgroundColor({ hex: '#333333' });
31+
await hp.hasBackgroundColor({ hex: '#1c1c1c' }); // default dark surface-canvas
3232
});
3333

3434
test('changing theme to dark and themeVariant using onThemeUpdate', async ({ page }, workerInfo) => {
3535
const hp = HistoryTestPage.create(page, workerInfo);
3636
await hp.openPage({ additional: { theme: 'light', themeVariant: 'desert' } });
3737
await hp.hasTheme('light', 'desert');
38-
await hp.hasBackgroundColor({ hex: '#eee9e1' });
38+
await hp.hasBackgroundColor({ hex: '#f5f4ef' }); // desert light surface-canvas
3939
await hp.acceptsThemeUpdate('dark', 'slateBlue');
4040
await hp.hasTheme('dark', 'slateBlue');
41-
await hp.hasBackgroundColor({ hex: '#1e3347' });
41+
await hp.hasBackgroundColor({ hex: '#243a50' }); // slateBlue dark surface-canvas
4242
});
4343

4444
test('changing theme to light and themeVariant using onThemeUpdate', async ({ page }, workerInfo) => {
4545
const hp = HistoryTestPage.create(page, workerInfo);
4646
await hp.openPage({ additional: { theme: 'dark', themeVariant: 'rose' } });
4747
await hp.hasTheme('dark', 'rose');
48-
await hp.hasBackgroundColor({ hex: '#5b194b' });
48+
await hp.hasBackgroundColor({ hex: '#511442' }); // rose dark surface-canvas
4949
await hp.acceptsThemeUpdate('light', 'green');
5050
await hp.hasTheme('light', 'green');
51-
await hp.hasBackgroundColor({ hex: '#e3eee1' });
51+
await hp.hasBackgroundColor({ hex: '#ecf5ea' }); // green light surface-canvas
5252
});
5353
});

0 commit comments

Comments
 (0)