All files / src/components/appearance tones.ts

100% Statements 10/10
100% Branches 4/4
100% Functions 2/2
100% Lines 9/9

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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110                                                                        29x                                                                                                                     29x   29x 490x       29x 12x 12x 472x   12x    
/** Accent palette shared by every surface the user can tint.
 *
 *  The one palette for tinted surfaces across fe-core — Overview's resource
 *  cards read from it too, so a styled resource looks the same wherever it
 *  appears rather than like a separate product. (Overview kept a private copy
 *  of `fg`/`bg` for a while; it drifted the moment a key was added here.)
 *  Dashboards and agents each store their accent as one of these keys; a
 *  dashboard's widgets inherit the board's unless they set their own.
 *
 *  `ACCENTS` in svc-core's `app/services/appearance.py` is the server-side
 *  mirror of these keys — keep the two in step.
 */
 
export type Tone =
  | "violet"
  | "blue"
  | "sky"
  | "amber"
  | "emerald"
  | "indigo"
  | "rose"
  | "slate";
 
export interface ToneClasses {
  /** Foreground for icons and emphasis text. */
  fg: string;
  /** Tinted surface behind an icon. */
  bg: string;
  /** Border for a tinted surface. */
  border: string;
  /** Solid fill for bars and chart marks. */
  solid: string;
  /** Raw hex, for SVG/recharts where a class cannot reach. */
  hex: string;
}
 
export const TONES: Record<Tone, ToneClasses> = {
  violet: {
    fg: "text-violet-600 dark:text-violet-400",
    bg: "bg-violet-50 dark:bg-violet-900/20",
    border: "border-violet-200 dark:border-violet-800/60",
    solid: "bg-violet-500",
    hex: "#8b5cf6",
  },
  blue: {
    fg: "text-blue-600 dark:text-blue-400",
    bg: "bg-blue-50 dark:bg-blue-900/20",
    border: "border-blue-200 dark:border-blue-800/60",
    solid: "bg-blue-500",
    hex: "#3b82f6",
  },
  sky: {
    fg: "text-sky-600 dark:text-sky-400",
    bg: "bg-sky-50 dark:bg-sky-900/20",
    border: "border-sky-200 dark:border-sky-800/60",
    solid: "bg-sky-500",
    hex: "#0ea5e9",
  },
  amber: {
    fg: "text-amber-600 dark:text-amber-400",
    bg: "bg-amber-50 dark:bg-amber-900/20",
    border: "border-amber-200 dark:border-amber-800/60",
    solid: "bg-amber-500",
    hex: "#f59e0b",
  },
  emerald: {
    fg: "text-emerald-600 dark:text-emerald-400",
    bg: "bg-emerald-50 dark:bg-emerald-900/20",
    border: "border-emerald-200 dark:border-emerald-800/60",
    solid: "bg-emerald-500",
    hex: "#10b981",
  },
  indigo: {
    fg: "text-indigo-600 dark:text-indigo-400",
    bg: "bg-indigo-50 dark:bg-indigo-900/20",
    border: "border-indigo-200 dark:border-indigo-800/60",
    solid: "bg-indigo-500",
    hex: "#6366f1",
  },
  rose: {
    fg: "text-rose-600 dark:text-rose-400",
    bg: "bg-rose-50 dark:bg-rose-900/20",
    border: "border-rose-200 dark:border-rose-800/60",
    solid: "bg-rose-500",
    hex: "#f43f5e",
  },
  slate: {
    fg: "text-gray-600 dark:text-gray-400",
    bg: "bg-gray-100 dark:bg-gray-700/50",
    border: "border-gray-200 dark:border-gray-700",
    solid: "bg-gray-500",
    hex: "#6b7280",
  },
};
 
export const TONE_KEYS = Object.keys(TONES) as Tone[];
 
export const toneOf = (value: string | null | undefined): Tone =>
  value && value in TONES ? (value as Tone) : "slate";
 
/** Deterministic tone for an arbitrary label — used to colour comparison
 *  subjects consistently across a refresh without storing a colour per row. */
export const toneForLabel = (label: string): Tone => {
  let hash = 0;
  for (let i = 0; i < label.length; i += 1) {
    hash = (hash * 31 + label.charCodeAt(i)) >>> 0;
  }
  return TONE_KEYS[hash % TONE_KEYS.length];
};