Add dark mode based on device color-scheme preference
Move the color palette into CSS custom properties (:root in globals.scss) with a prefers-color-scheme: dark override, and point the existing $color-* Sass variables at them so every component picks up dark mode automatically. Replaced the handful of rgba($color, alpha) call sites with color-mix(), since Sass can't alpha-blend a color that's now a CSS variable at compile time. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
$color-text: #1a1a1a;
|
||||
$color-text-muted: #6b6b6b;
|
||||
$color-background: #ffffff;
|
||||
$color-surface: #f7f7f5;
|
||||
$color-border: #e2e0dc;
|
||||
$color-primary: #b5432b;
|
||||
$color-primary-contrast: #ffffff;
|
||||
$color-danger: #a33;
|
||||
$color-success: #2f7a4f;
|
||||
// These resolve to the CSS custom properties defined in globals.scss, which
|
||||
// swap values under `prefers-color-scheme: dark` — keep referencing them by
|
||||
// these names rather than hardcoding hex so components pick up dark mode
|
||||
// automatically.
|
||||
$color-text: var(--color-text);
|
||||
$color-text-muted: var(--color-text-muted);
|
||||
$color-background: var(--color-background);
|
||||
$color-surface: var(--color-surface);
|
||||
$color-border: var(--color-border);
|
||||
$color-primary: var(--color-primary);
|
||||
$color-primary-contrast: var(--color-primary-contrast);
|
||||
$color-danger: var(--color-danger);
|
||||
$color-success: var(--color-success);
|
||||
|
||||
$space-1: 0.25rem;
|
||||
$space-2: 0.5rem;
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
@use './variables' as *;
|
||||
|
||||
:root {
|
||||
--color-text: #1a1a1a;
|
||||
--color-text-muted: #6b6b6b;
|
||||
--color-background: #ffffff;
|
||||
--color-surface: #f7f7f5;
|
||||
--color-border: #e2e0dc;
|
||||
--color-primary: #b5432b;
|
||||
--color-primary-contrast: #ffffff;
|
||||
--color-danger: #a33333;
|
||||
--color-success: #2f7a4f;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--color-text: #f2ede6;
|
||||
--color-text-muted: #a89e8f;
|
||||
--color-background: #16130f;
|
||||
--color-surface: #201c17;
|
||||
--color-border: #3a342a;
|
||||
--color-primary: #d9694a;
|
||||
--color-primary-contrast: #ffffff;
|
||||
--color-danger: #ef6b62;
|
||||
--color-success: #4fbb7c;
|
||||
color-scheme: dark;
|
||||
}
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
|
||||
Reference in New Issue
Block a user