Skip to content

refactor: add color role table and buildScheme#4916

Open
adrcotfas wants to merge 1 commit into@adrcotfas/refactor/structurefrom
@adrcotfas/refactor/tokens_colors
Open

refactor: add color role table and buildScheme#4916
adrcotfas wants to merge 1 commit into@adrcotfas/refactor/structurefrom
@adrcotfas/refactor/tokens_colors

Conversation

@adrcotfas
Copy link
Copy Markdown
Collaborator

@adrcotfas adrcotfas commented May 5, 2026

Motivation

LightTheme and DarkTheme each contained ~70 lines of hand-duplicated palette look-ups. Because the mapping between color roles (e.g. primary) and palette tones (e.g. primary40) is
defined by the Material Design 3 spec, keeping it as inlined object literals meant every future scheme (high-contrast, dynamic) would require copy-pasting the same structure again with no single source of truth to audit against the spec.

This extracts that spec knowledge into a roleToTone table in src/theme/tokens/sys/color/roles.ts, keyed by (mode, contrast). A buildScheme() function walks the table, resolves palette
values, and derives the computed fields (stateLayerPressed, elevation). LightTheme and DarkTheme now each call buildScheme() with a single argument instead of listing ~60 literals.

No behavior changes: the output shape is identical and every tone value matches the previous hand-written spec.

Related issue

See https://www.notion.so/callstack/React-Native-Paper-Foundation-for-MD3-Expressive-34c5d027c0f880edba3df107cd35946f?source=copy_link

#### Merge order:

Adds src/theme/tokens/sys/color/roles.ts with a roleToTone table keyed
by (mode, contrast) and a buildScheme() function. LightTheme and
DarkTheme replace their hand-duplicated color literals with a single
buildScheme() call each. Output shape is identical; tone values match
the existing hand-written spec.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

The mobile version of example app from this branch is ready! You can see it here.

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.

1 participant