Skip to content

refactor(core): derive color param names from a single source of truth - #435

Merged
martin-mfg merged 1 commit into
stats-organization:media-queryfrom
marcalexiei:media-query
Aug 3, 2026
Merged

refactor(core): derive color param names from a single source of truth#435
martin-mfg merged 1 commit into
stats-organization:media-queryfrom
marcalexiei:media-query

Conversation

@marcalexiei

@marcalexiei marcalexiei commented Aug 2, 2026

Copy link
Copy Markdown

Derive the color param names from one source of truth.

They were spelled out in different places:

  1. the ColorInput interface
  2. the extractLightDarkColors mapping,
  3. 24-entry COLOR_PARAM_KEYS array,
  4. theme-exclusion literal repeated in all five api/*.js files.

Adding a param meant touching all four, with nothing to catch a miss.

Now everything derives from:

const BASE_COLOR_KEYS = [/* ... */ ] as const;

const THEME_VARIANTS = ["light", "dark"] as const;

ColorInput and LightDarkColorParams become mapped types over those keys, extractLightDarkColors maps over BASE_COLOR_KEYS, and COLOR_PARAM_KEYS is built by flat-mapping the variants.

The api files each repeated the same "theme params aren't colors" exclusion:

findInvalidColor({ ...colorParams, theme: undefined, theme_light: undefined, theme_dark: undefined })

That's now findInvalidColorParam(colorParams), with the exclusion derived in color.ts.

@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

@marcalexiei is attempting to deploy a commit to the martin-mfg's projects Team on Vercel.

A member of the Team first needs to authorize it.

@marcalexiei marcalexiei changed the title refactor(core): derive color param names from a single array refactor(core): derive color param names from a single source of truth Aug 2, 2026
type ThemeVariant = "dark" | "light";
type LightDarkColorParams = Partial<
Record<`${keyof ColorInput}_${ThemeVariant}`, string>
Record<`${BaseColorKey}_${ThemeVariant}`, string | undefined>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add | undefined here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To allow undefined to be passed explicitly:

image

@marcalexiei
marcalexiei requested a review from martin-mfg August 3, 2026 08:45
@martin-mfg
martin-mfg merged commit 3d02c3e into stats-organization:media-query Aug 3, 2026
0 of 2 checks passed
@marcalexiei
marcalexiei deleted the media-query branch August 4, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants