diff --git a/src/lib/utils/colors.test.ts b/src/lib/utils/colors.test.ts new file mode 100644 index 0000000..6dc1c0c --- /dev/null +++ b/src/lib/utils/colors.test.ts @@ -0,0 +1,25 @@ +import { describe, it, expect } from 'vitest'; +import { getNoteColor, NOTE_COLORS, NOTE_COLORS_DARK } from '$lib/utils/colors.js'; + +describe('getNoteColor', () => { + it('returns light color when isDark is false', () => { + expect(getNoteColor('default', false)).toBe('#faf5eb'); + expect(getNoteColor('coral', false)).toBe('#faafa8'); + }); + + it('returns dark color when isDark is true', () => { + expect(getNoteColor('default', true)).toBe('#2a2520'); + expect(getNoteColor('coral', true)).toBe('#4a2522'); + }); + + it('returns default color for unknown color name', () => { + expect(getNoteColor('unknown' as any, false)).toBe('#faf5eb'); + expect(getNoteColor('unknown' as any, true)).toBe('#2a2520'); + }); + + it('has matching keys in light and dark color maps', () => { + const lightKeys = Object.keys(NOTE_COLORS).sort(); + const darkKeys = Object.keys(NOTE_COLORS_DARK).sort(); + expect(lightKeys).toEqual(darkKeys); + }); +}); diff --git a/src/lib/utils/colors.ts b/src/lib/utils/colors.ts index 15f1ffe..09f7190 100644 --- a/src/lib/utils/colors.ts +++ b/src/lib/utils/colors.ts @@ -15,6 +15,26 @@ export const NOTE_COLORS: Record = { chalk: { bg: '#efeff1', label: 'Chalk' } }; +export const NOTE_COLORS_DARK: Record = { + default: { bg: '#2a2520', label: 'Default' }, + coral: { bg: '#4a2522', label: 'Coral' }, + peach: { bg: '#4a3020', label: 'Peach' }, + sand: { bg: '#3a3520', label: 'Sand' }, + mint: { bg: '#2a3a22', label: 'Mint' }, + sage: { bg: '#223a32', label: 'Sage' }, + fog: { bg: '#222e3a', label: 'Fog' }, + storm: { bg: '#1e2a35', label: 'Storm' }, + dusk: { bg: '#352540', label: 'Dusk' }, + blossom: { bg: '#3a2830', label: 'Blossom' }, + clay: { bg: '#302e28', label: 'Clay' }, + chalk: { bg: '#2e2e30', label: 'Chalk' } +}; + +export function getNoteColor(color: NoteColor, isDark: boolean): string { + const map = isDark ? NOTE_COLORS_DARK : NOTE_COLORS; + return (map[color] ?? map.default).bg; +} + export const COLOR_OPTIONS = Object.entries(NOTE_COLORS).map(([value, { label }]) => ({ value: value as NoteColor, label