refactor: centralise color maps, org color fallback, and motion-safe transitions
Create src/lib/theme-colors.ts with DOT_COLORS, KPI_COLORS, PROJECT_STATUS_COLORS, and DEFAULT_ORG_COLOR constants. Add motionSafeTransition() utility to src/lib/utils.ts. Removes 6 duplicate color map definitions across Card, DetailPanel, PatientSummaryTile, KPIDetail, ProjectsTile, and ProjectDetail. Replaces 9 hardcoded '#0D6E6E' fallbacks and 7 inline motion ternaries. Fixes project status color inconsistency between ProjectsTile and ProjectDetail (Ongoing was teal in tile, amber in detail).
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/** Semantic dot/accent colors used across Card, DetailPanel, KPIs */
|
||||
export const DOT_COLORS = {
|
||||
teal: '#0D6E6E',
|
||||
amber: '#D97706',
|
||||
green: '#059669',
|
||||
alert: '#DC2626',
|
||||
purple: '#7C3AED',
|
||||
} as const
|
||||
|
||||
export type DotColorName = keyof typeof DOT_COLORS
|
||||
|
||||
/** KPI color variants (subset of DOT_COLORS) */
|
||||
export const KPI_COLORS: Record<'green' | 'amber' | 'teal', string> = {
|
||||
green: DOT_COLORS.green,
|
||||
amber: DOT_COLORS.amber,
|
||||
teal: DOT_COLORS.teal,
|
||||
}
|
||||
|
||||
/** Project/investigation status colors */
|
||||
export const PROJECT_STATUS_COLORS: Record<'Complete' | 'Ongoing' | 'Live', string> = {
|
||||
Complete: '#059669',
|
||||
Ongoing: '#D97706',
|
||||
Live: '#0D6E6E',
|
||||
}
|
||||
|
||||
/** Default org color fallback when consultation.orgColor is undefined */
|
||||
export const DEFAULT_ORG_COLOR = '#0D6E6E'
|
||||
@@ -15,3 +15,13 @@ export function hexToRgba(hex: string, opacity: number): string {
|
||||
}
|
||||
|
||||
export const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
||||
|
||||
/** Returns a framer-motion transition that respects prefers-reduced-motion */
|
||||
export function motionSafeTransition(
|
||||
duration: number,
|
||||
ease: string = 'easeOut',
|
||||
delay: number = 0
|
||||
): { duration: number; ease?: string; delay?: number } {
|
||||
if (prefersReducedMotion) return { duration: 0 }
|
||||
return { duration, ease, ...(delay ? { delay } : {}) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user