Skip to content

feat: add mapped token source support#854

Open
leoafarias wants to merge 5 commits intomainfrom
feat/mapped-token-source
Open

feat: add mapped token source support#854
leoafarias wants to merge 5 commits intomainfrom
feat/mapped-token-source

Conversation

@leoafarias
Copy link
Copy Markdown
Collaborator

Related issue

Adds mapped token source functionality to the Mix styling system.

Description

This PR introduces mapped token source support, enabling more flexible token handling in the styling system. It includes error message improvements and comprehensive test coverage for the new functionality.

Changes

  • Core: Added mapped token source support in prop.dart and prop_source.dart (71 new lines)
  • Extensions: Updated prop_number_ext.dart to support new token source
  • Theme: Enhanced token_refs.dart with token mapping capabilities
  • Tests: Added comprehensive test coverage for mapped token sources with utility helpers
  • Error Handling: Simplified unsupported source error message for better clarity

Review Checklist

  • Testing: Comprehensive unit tests added for mapped token source functionality
  • Breaking Changes: No breaking changes - additive feature
  • Documentation Updates: Feature integrates with existing token reference system
  • Website Updates: Updates to documentation on design tokens may be needed for full coverage

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Feb 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mix-docs Ready Ready Preview, Comment Feb 25, 2026 1:59am

@docs-page
Copy link
Copy Markdown

docs-page bot commented Feb 24, 2026

To view this pull requests documentation preview, visit the following URL:

docs.page/btwld/mix~854

Documentation is deployed and generated using docs.page.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds mapped token source support to the Mix styling system, enabling more flexible token handling through the new Prop.tokenWith API. This feature allows tokens to be resolved and transformed to different output types, supporting both plain value returns and Mix accumulation merging strategies.

Changes:

  • Introduced MappedTokenSource<V, T> class to handle token-to-value mapping with type transformation
  • Added Prop.tokenWith<V, T>() factory method for creating mapped token properties
  • Extended test matchers and utilities to support mapped token validation
  • Updated token reference detection to include mapped tokens
  • Improved error messages for unsupported source types

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/mix/lib/src/core/prop_source.dart Adds MappedTokenSource class with token resolution and transformation logic
packages/mix/lib/src/core/prop.dart Implements Prop.tokenWith factory method and resolution handling for mapped tokens
packages/mix/lib/src/core/extensions/prop_number_ext.dart Improves error message specificity for unsupported source types
packages/mix/lib/src/theme/tokens/token_refs.dart Updates isAnyTokenRef to detect mapped token sources
packages/mix/test/src/core/prop_test.dart Adds comprehensive test coverage for mapped token functionality (165 new lines)
packages/mix/test/src/core/prop_source_test.dart Tests MappedTokenSource equality, resolution, and toString behavior
packages/mix/test/helpers/testing_utils.dart Adds PropMatcher.isMappedToken matcher and updates hasTokens matcher
packages/mix/test/helpers/testing_utils_test.dart Validates new test matchers for mapped tokens
examples/lib/components/custom_scaffold.dart Refactors to use Dart 3.0 if-null element syntax (unrelated to main feature)
melos.yaml Adds sdkPath configuration for FVM support (unrelated to main feature)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

style: scaffoldContainer,
children: [
if (appBar != null) appBar!,
?appBar,
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

This change from if (appBar != null) appBar! to ?appBar uses Dart 3.0's if-null element syntax, which is more concise. However, this change appears unrelated to the mapped token source feature described in the PR. Consider grouping unrelated refactoring changes separately from feature additions for clearer change history.

Suggested change
?appBar,
if (appBar != null) appBar!,

Copilot uses AI. Check for mistakes.
Comment on lines 162 to 169
final Prop<num> base = source is ValueSource<T>
? Prop.value<num>((source).value)
: source is TokenSource<T>
? Prop.token((source).token as MixToken<num>)
: throw UnimplementedError(
'Source type ${source.runtimeType} not supported',
'Source type ${source.runtimeType} not supported for number '
'directives.',
);
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

The _asPropNum method doesn't handle MappedTokenSource, which means numeric directives (multiply, add, clamp, etc.) cannot be used with Props created via Prop.tokenWith. Consider adding support for MappedTokenSource similar to how TokenSource is handled, or document this limitation if it's intentional. Example failing case: Prop.tokenWith<num, Color>(token, (c) => c.value).multiply(2)

Copilot uses AI. Check for mistakes.
Comment thread melos.yaml
api-check:
run: dart scripts/api_check.dart
description: "Check API compatibility for mix packages (usage: melos run api-check -- [package] [version])"
sdkPath: .fvm/flutter_sdk
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

This sdkPath configuration appears unrelated to the mapped token source feature described in the PR. Consider moving FVM/SDK configuration changes to a separate commit or PR for better change tracking and easier rollback if needed.

Suggested change
sdkPath: .fvm/flutter_sdk

Copilot uses AI. Check for mistakes.
Add useToken<U> method on MixStyler base class, enabling all stylers
to resolve design tokens inline with correct merge ordering.

Token refs flow through the builder callback and preserve identity
via the existing PropSource pipeline, ensuring last-in-chain wins.
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation examples mix repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants