Skip to content

refactor: add color role table and buildScheme#4916

Merged
adrcotfas merged 1 commit into
v6from
@adrcotfas/refactor/tokens_colors
May 11, 2026
Merged

refactor: add color role table and buildScheme#4916
adrcotfas merged 1 commit into
v6from
@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:

@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.

@adrcotfas adrcotfas force-pushed the @adrcotfas/refactor/structure branch from 61df1ab to 9ef3329 Compare May 11, 2026 06:02
Base automatically changed from @adrcotfas/refactor/structure to v6 May 11, 2026 06:10
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.
@adrcotfas adrcotfas force-pushed the @adrcotfas/refactor/tokens_colors branch from fdb6702 to e74e6cc Compare May 11, 2026 06:49
@callstack-bot
Copy link
Copy Markdown

Hey @adrcotfas, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

@adrcotfas adrcotfas merged commit 1f1102d into v6 May 11, 2026
3 checks passed
@adrcotfas adrcotfas deleted the @adrcotfas/refactor/tokens_colors branch May 11, 2026 06:54
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.

3 participants