Skip to content

Commit 9d21f5f

Browse files
committed
dark mode spike
1 parent dd940e5 commit 9d21f5f

11 files changed

Lines changed: 47 additions & 22 deletions

src/frets/Chord.svelte

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import { getChordVariations } from "../frets/chordFingerings.js";
33
import { tunings } from "$lib";
4-
import { getContext } from "svelte";
4+
import { getContext, onMount } from "svelte";
55
import { SVGuitarChord } from "svguitar";
66
77
let {
@@ -16,11 +16,15 @@
1616
let el = $state(null);
1717
let width = $state(0);
1818
let height = $state(0);
19+
let isDarkMode = $state(false);
1920
2021
const variations = $derived(getChordVariations(chordName, tuning));
2122
// Use the first variation
2223
const chordData = $derived(variations.positions[position]);
2324
25+
// Colors based on color scheme
26+
const chordColor = $derived(isDarkMode ? "#e5e7eb" : "#333");
27+
2428
function playChord() {
2529
if (chordData?.midi) {
2630
console.log("Playing chord:", chordName, "MIDI:", chordData.midi);
@@ -32,6 +36,17 @@
3236
}
3337
}
3438
39+
onMount(() => {
40+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
41+
isDarkMode = mediaQuery.matches;
42+
43+
const handler = (e) => {
44+
isDarkMode = e.matches;
45+
};
46+
mediaQuery.addEventListener("change", handler);
47+
return () => mediaQuery.removeEventListener("change", handler);
48+
});
49+
3550
$effect(() => {
3651
// Redraw the chord whenever props or chordData changes
3752
if (!el || !chordData) return;
@@ -49,11 +64,12 @@
4964
position: chordData.position,
5065
strokeWidth: 1,
5166
fingerSize: 0.5,
52-
fingerColor: "#333",
67+
fingerColor: chordColor,
68+
fingerTextColor: isDarkMode ? "#374151" : "#fff",
5369
fingerTextSize: 20,
5470
fretSize: 1.1,
55-
fretColor: "#333",
56-
color: "#333",
71+
fretColor: chordColor,
72+
color: chordColor,
5773
titleFontSize: 28,
5874
titleBottomMargin: 10,
5975
fretLabelFontSize: 20,
@@ -87,7 +103,7 @@
87103
88104
<style>
89105
:global(.barre-rectangle) {
90-
fill: #333 !important;
106+
@apply fill-[#333] dark:fill-[#e5e7eb];
91107
}
92108
93109
:global(.tuning) {

src/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@
1414
--color-purple-900: #581c87;
1515
--color-purple-950: #3b0764;
1616
}
17+
18+
/* Base styles for light/dark mode */
19+
html {
20+
@apply bg-white text-gray-900 dark:bg-gray-900 dark:text-gray-100;
21+
}

src/lib/FretBoard.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<line
5353
x1={fretX(1) - margin.left}
5454
x2={width - margin.right - margin.left}
55-
class="stroke-gray-100"
55+
class="stroke-gray-100 dark:stroke-gray-600"
5656
stroke-width={lineW(i)} />
5757
{#each notes as stringNote}
5858
<g
@@ -99,12 +99,12 @@
9999
@reference "tailwindcss";
100100
101101
.fret-label {
102-
@apply text-xs fill-gray-800 text-center -translate-y-2;
102+
@apply text-xs fill-gray-800 dark:fill-gray-200 text-center -translate-y-2;
103103
text-anchor: middle;
104104
dominant-baseline: ideographic;
105105
}
106106
107107
.fret-line {
108-
@apply fill-gray-400 stroke-0;
108+
@apply fill-gray-400 dark:fill-gray-500 stroke-0;
109109
}
110110
</style>

src/lib/FretNote.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626
@reference "tailwindcss";
2727
2828
.fret-note-background {
29-
@apply fill-white;
29+
@apply fill-white dark:fill-gray-800;
3030
}
3131
3232
.fret-note-text {
33-
@apply text-xs fill-gray-500;
33+
@apply text-xs fill-gray-500 dark:fill-gray-400;
3434
}
3535
3636
.fret-note:not(.in-position):is(.in-scale) .fret-note-background {
3737
@apply hidden;
3838
}
3939
4040
.fret-note:not(.in-position):is(.in-scale) .fret-note-text {
41-
@apply font-normal fill-gray-500;
41+
@apply font-normal fill-gray-500 dark:fill-gray-400;
4242
}
4343
4444
.in-scale .fret-note-background {
@@ -50,7 +50,11 @@
5050
}
5151
5252
.in-scale[data-interval="1P"] circle {
53-
@apply fill-gray-800 stroke-gray-900 stroke-2;
53+
@apply fill-gray-800 dark:fill-gray-200 stroke-gray-900 dark:stroke-gray-100 stroke-2;
54+
}
55+
56+
.in-scale[data-interval="1P"] .fret-note-text {
57+
@apply dark:fill-gray-900;
5458
}
5559
5660
.in-scale:is([data-interval^="3"], [data-interval^="5"]) circle {

src/lib/KeySelector.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
let notes = ["C", "C#", "D", "Eb", "E", "F", "F#", "G", "Ab", "A", "Bb", "B"];
44
</script>
55

6-
<select bind:value class="border-gray-300 w-fit">
6+
<select bind:value class="border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 w-fit">
77
{#each notes as note}
88
<option value={note}>
99
{note}

src/lib/ScaleChords.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
});
2222
</script>
2323

24-
<div class="text-xs text-gray-500 grid grid-cols-4 md:grid-cols-7 gap-5">
24+
<div class="text-xs text-gray-500 dark:text-gray-400 grid grid-cols-4 md:grid-cols-7 gap-5">
2525
{#each chords as chord}
26-
<div class="bg-gray-100 py-5">
26+
<div class="bg-gray-100 dark:bg-gray-700 py-5">
2727
<Chord chordName={chord} />
2828
</div>
2929
{/each}

src/lib/ScaleInfo.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
text-anchor="middle"
4444
dy="25"
4545
font-size="10"
46-
class="text-black"
46+
class="text-black dark:text-gray-200"
4747
fill="currentColor">{note.interval}</text>
4848
</g>
4949
{/each}

src/lib/ScaleSelector.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
];
1818
</script>
1919

20-
<select bind:value class="border-gray-300 w-fit">
20+
<select bind:value class="border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 w-fit">
2121
{#each scales as scale}
2222
<option value={scale}>
2323
{scale}

src/lib/SystemSelector.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<div class="flex gap-5">
1414
<div>
15-
<select bind:value={system} class="w-fit border border-gray-200">
15+
<select bind:value={system} class="w-fit border border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100">
1616
<option value="CAGED">CAGED</option>
1717
<option value="Pentatonic">Pentatonic</option>
1818
</select>
@@ -47,7 +47,7 @@
4747
@reference "tailwindcss";
4848
4949
input[type="radio"] {
50-
@apply border-gray-400 checked:bg-sky-600 checked:border-sky-600 active:bg-sky-200 focus:ring-1 focus:ring-sky-500;
50+
@apply border-gray-400 checked:bg-sky-600 checked:border-sky-600 active:bg-sky-200 focus:ring-1 focus:ring-sky-500 dark:bg-gray-700 dark:border-gray-500 dark:active:bg-sky-700;
5151
}
5252
5353
label {

src/lib/TuningSelector.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
let { value = $bindable() } = $props();
55
</script>
66

7-
<select bind:value name="tuning" class="w-full border border-gray-200">
7+
<select bind:value name="tuning" class="w-full border border-gray-200 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100">
88
{#each tunings as [name]}
99
<option value={name}>{name}</option>
1010
{/each}

0 commit comments

Comments
 (0)