Skip to content

Commit 21abf68

Browse files
committed
Add dark mode initialization script to prevent flash on load
1 parent 898ce22 commit 21abf68

File tree

2 files changed

+104
-12
lines changed

2 files changed

+104
-12
lines changed

themes/icarus/include/style/dark-mode.styl

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,68 @@
22
* Dark Mode Styles
33
* --------------------------------- */
44

5+
/* CSS Custom Properties for theming */
6+
:root
7+
--bg-primary: #ffffff
8+
--bg-secondary: #f5f5f5
9+
--bg-tertiary: #e0e0e0
10+
--text-primary: #000000
11+
--text-secondary: #4a4a4a
12+
--text-tertiary: #767676
13+
--border-color: #dbdbdb
14+
--link-color: #3273dc
15+
--link-hover: #363636
16+
--card-bg: #ffffff
17+
--navbar-bg: #ffffff
18+
--footer-bg: #fafafa
19+
--code-bg: #f5f5f5
20+
--highlight-bg: #fafafa
21+
22+
.dark-mode
23+
--bg-primary: #0d1117
24+
--bg-secondary: #161b22
25+
--bg-tertiary: #21262d
26+
--text-primary: #c9d1d9
27+
--text-secondary: #8b949e
28+
--text-tertiary: #6e7681
29+
--border-color: #30363d
30+
--link-color: #58a6ff
31+
--link-hover: #79c0ff
32+
--card-bg: #161b22
33+
--navbar-bg: #161b22
34+
--footer-bg: #161b22
35+
--code-bg: #21262d
36+
--highlight-bg: #1e1e1e
37+
538
/* Add smooth transition for theme changes */
639
html, body, .card, .navbar-main, .footer, a, .content, .title, p, h1, h2, h3, h4, h5, h6, span
740
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease
841

942
/* Dark mode base styles */
1043
.dark-mode
11-
background: #0d1117
12-
color: #c9d1d9
44+
background: var(--bg-primary)
45+
color: var(--text-primary)
46+
47+
*, *::before, *::after
48+
border-color: var(--border-color)
1349

1450
body
15-
background: #0d1117
16-
color: #c9d1d9
51+
background: var(--bg-primary)
52+
color: var(--text-primary)
1753

1854
.navbar-main
19-
background: #161b22
20-
border-bottom: 1px solid #30363d
55+
background: var(--navbar-bg)
56+
border-bottom: 1px solid var(--border-color)
2157

2258
.card
23-
background: #161b22
24-
border: 1px solid #30363d
25-
color: #c9d1d9
59+
background: var(--card-bg)
60+
border: 1px solid var(--border-color)
61+
color: var(--text-primary)
2662

2763
.footer
28-
background: #161b22
29-
border-top: 1px solid #30363d
30-
color: #c9d1d9
64+
background: var(--footer-bg)
65+
border-top: 1px solid var(--border-color)
66+
color: var(--text-primary)
3167

3268
/* Dark mode link colors - bright blue for better visibility */
3369
a
@@ -299,6 +335,49 @@ html, body, .card, .navbar-main, .footer, a, .content, .title, p, h1, h2, h3, h4
299335
&:hover
300336
opacity: 0.8
301337

338+
/* Dark mode share button styles */
339+
.dark-mode
340+
/* AddToAny share buttons in dark mode */
341+
.a2a_kit a
342+
filter: brightness(1.2)
343+
344+
/* AddToAny menu/popup in dark mode */
345+
.a2a_menu
346+
background: #161b22 !important
347+
border-color: #30363d !important
348+
349+
.a2a_menu a
350+
color: #c9d1d9 !important
351+
352+
&:hover
353+
background: #21262d !important
354+
color: #e6eef8 !important
355+
356+
/* AddToAny cookie notice in dark mode */
357+
.a2a_notice
358+
background: #161b22 !important
359+
border-color: #30363d !important
360+
color: #c9d1d9 !important
361+
362+
.a2a_notice a
363+
color: #58a6ff !important
364+
365+
&:hover
366+
color: #79c0ff !important
367+
368+
/* AddToAny overlay background in dark mode */
369+
#a2a_overlay
370+
background: rgba(13, 17, 23, 0.8) !important
371+
372+
/* AddToAny modal in dark mode */
373+
#a2a_modal
374+
background: #161b22 !important
375+
border-color: #30363d !important
376+
color: #c9d1d9 !important
377+
378+
#a2a_modal .a2a_button_text
379+
color: #c9d1d9 !important
380+
302381
/* Post card separator line - lighter gray */
303382
.card-content hr,
304383
.content hr

themes/icarus/layout/common/head.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ module.exports = class extends Component {
124124
{meta && meta.length ? <MetaTags meta={meta} /> : null}
125125

126126
<title>{getPageTitle(page, config.title, helper)}</title>
127+
128+
{/* Apply dark mode immediately to prevent flash */}
129+
<script dangerouslySetInnerHTML={{
130+
__html: `
131+
(function() {
132+
const stored = localStorage.getItem('theme-mode');
133+
const isDark = stored !== null ? stored === 'true' : false;
134+
if (isDark) {
135+
document.documentElement.classList.add('dark-mode');
136+
}
137+
})();
138+
`
139+
}} />
127140

128141
<WebApp.Cacheable
129142
helper={helper}

0 commit comments

Comments
 (0)