# All files / src/utils typeColors.ts

100% Statements 15/15
100% Branches 14/14
100% Functions 4/4
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61

    13x

    13x

    13x
    13x

    13x

    13x
    104x

    13x
    104x

    13224x
    13206x

    12965x
    12962x

     /**
     * Maps note types to their accent color CSS variables.
     * Single source of truth for type→color mapping used across Sidebar, NoteList, and Inspector.
     */

    const TYPE_COLOR_MAP: Record<string, string> = {
      Project: 'var(--accent-red)',
      Experiment: 'var(--accent-red)',
      Responsibility: 'var(--accent-purple)',
      Procedure: 'var(--accent-purple)',
      Person: 'var(--accent-yellow)',
      Event: 'var(--accent-yellow)',
      Topic: 'var(--accent-green)',
      Type: 'var(--accent-blue)',
    }

    const TYPE_LIGHT_COLOR_MAP: Record<string, string> = {
      Project: 'var(--accent-red-light)',
      Experiment: 'var(--accent-red-light)',
      Responsibility: 'var(--accent-purple-light)',
      Procedure: 'var(--accent-purple-light)',
      Person: 'var(--accent-yellow-light)',
      Event: 'var(--accent-yellow-light)',
      Topic: 'var(--accent-green-light)',
      Type: 'var(--accent-blue-light)',
    }

    const DEFAULT_COLOR = 'var(--muted-foreground)'
    const DEFAULT_LIGHT_COLOR = 'var(--muted)'

    /** Color key → CSS variable mapping for the design system accent palette */
    export const ACCENT_COLORS: { key: string; label: string; css: string; cssLight: string }[] = [
      { key: 'red', label: 'Red', css: 'var(--accent-red)', cssLight: 'var(--accent-red-light)' },
      { key: 'orange', label: 'Orange', css: 'var(--accent-orange)', cssLight: 'var(--accent-orange-light)' },
      { key: 'yellow', label: 'Yellow', css: 'var(--accent-yellow)', cssLight: 'var(--accent-yellow-light)' },
      { key: 'green', label: 'Green', css: 'var(--accent-green)', cssLight: 'var(--accent-green-light)' },
      { key: 'blue', label: 'Blue', css: 'var(--accent-blue)', cssLight: 'var(--accent-blue-light)' },
      { key: 'purple', label: 'Purple', css: 'var(--accent-purple)', cssLight: 'var(--accent-purple-light)' },
      { key: 'teal', label: 'Teal', css: 'var(--accent-teal)', cssLight: 'var(--accent-teal-light)' },
      { key: 'pink', label: 'Pink', css: 'var(--accent-pink)', cssLight: 'var(--accent-pink-light)' },
    ]

    const COLOR_KEY_TO_CSS: Record<string, string> = Object.fromEntries(
      ACCENT_COLORS.map((c) => [c.key, c.css]),
    )
    const COLOR_KEY_TO_CSS_LIGHT: Record<string, string> = Object.fromEntries(
      ACCENT_COLORS.map((c) => [c.key, c.cssLight]),
    )

    /** Returns the CSS variable for the accent color of a given note type, with optional custom override */
    export function getTypeColor(isA: string | null, customColorKey?: string | null): string {
      if (customColorKey && COLOR_KEY_TO_CSS[customColorKey]) return COLOR_KEY_TO_CSS[customColorKey]
      return (isA && TYPE_COLOR_MAP[isA]) ?? DEFAULT_COLOR
    }

    /** Returns the CSS variable for the light/background variant of a given note type's color */
    export function getTypeLightColor(isA: string | null, customColorKey?: string | null): string {
      if (customColorKey && COLOR_KEY_TO_CSS_LIGHT[customColorKey]) return COLOR_KEY_TO_CSS_LIGHT[customColorKey]
      return (isA && TYPE_LIGHT_COLOR_MAP[isA]) ?? DEFAULT_LIGHT_COLOR
    }