Skip to content

docs: document and highlight ContextToken#16

Merged
tilucasoli merged 5 commits into
mainfrom
docs/context-token
Jun 29, 2026
Merged

docs: document and highlight ContextToken#16
tilucasoli merged 5 commits into
mainfrom
docs/context-token

Conversation

@tilucasoli

Copy link
Copy Markdown
Collaborator

Summary

ContextToken<T> shipped in mix 2.1.0 (btwld/mix#938) but was completely undocumented — zero mentions anywhere in this repo, despite the docs already covering every other token type (ColorToken, RadiusToken, SpaceToken, BreakpointToken, …).

This PR closes that gap.

Changes

guides/design-token.mdx — new "Context Tokens" section

Placed after Theme Switching (its natural neighbor, since the canonical use case is deriving from Theme.of(context)). Covers:

  • Zero-config, context-derived resolution — no MixScope required
  • Fluent-chain ordering parity with other tokens (primary() behaves like any value in the chain)
  • MixScope override behavior — the resolver is a context-derived default a scope can override
  • ⚠️ Resolver-identity equality caveat → declare context tokens as top-level / static finals
  • A comparison table: scope tokens vs. ContextToken

tutorials/creating-custom-tokens.mdx — cross-link

Added an info callout so authors with a BuildContext-derived value reach for the built-in ContextToken instead of hand-rolling a custom token.

Accuracy

All examples are grounded in the actual 2.1.0 API (packages/mix/lib/src/theme/tokens/mix_token.dart) and mirror the behavior asserted in context_token_integration_test.dart (chain ordering, scope override, resolver-identity equality). No new preview blocks were added — the section is copy + code samples only.

🤖 Generated with Claude Code

ContextToken (mix 2.1.0, conceptadev/mix#938) was undocumented. Add a dedicated
"Context Tokens" section to the Design Tokens guide covering:

- zero-config, context-derived resolution (no MixScope required)
- fluent-chain ordering parity with other tokens
- MixScope override behavior (resolver as a context-derived default)
- resolver-identity equality caveat (declare as top-level/static finals)
- a comparison table vs. scope tokens

Also cross-link it from the Creating Custom Tokens tutorial so authors reach
for the built-in ContextToken instead of hand-rolling one for BuildContext-
derived values.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
mix-docs Ready Ready Preview, Comment Jun 26, 2026 5:30pm

Reframe the Context Tokens section around its primary use case: integrating
Material's ThemeData (ColorScheme, TextTheme) into the Mix token structure
without duplicating the source of truth in a MixScope. Update the comparison
table and the custom-tokens cross-link to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Introduce the two ways a token's value is sourced (MixScope vs. BuildContext)
right after the opening, calling out ContextToken and the Material theme
bridge with jump links to the section. Broaden the page description to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class documentation for ContextToken<T> so Mix docs cover context-derived token resolution (e.g., bridging Material Theme.of(context)), plus a cross-link from the custom-token tutorial to steer readers toward the built-in type when appropriate.

Changes:

  • Add a new “Context Tokens” section to the Design Tokens guide, including usage examples, scope override behavior, and an equality caveat.
  • Update the Design Tokens page description to mention BuildContext-derived tokens.
  • Add an info callout to the “Creating Custom Tokens” tutorial linking to ContextToken.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/content/documentation/mix/guides/design-token.mdx Adds Context Tokens section and updates frontmatter description to include BuildContext-derived tokens.
src/content/documentation/mix/tutorials/creating-custom-tokens.mdx Adds a callout directing readers to use ContextToken for BuildContext-derived values instead of custom tokens.

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

Comment thread src/content/documentation/mix/guides/design-token.mdx Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@leoafarias leoafarias left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’d make two wording corrections before publishing. The implementation supports the main ContextToken claims here: no MixScope is required, scope overrides work, chain order is preserved, and equality is resolver-identity based. The remaining risk is that the docs imply ContextToken works for arbitrary BuildContext-derived value types, while ContextToken.call() only has token-reference support for Mix’s supported token value set.

Comment thread src/content/documentation/mix/guides/design-token.mdx Outdated
Comment thread src/content/documentation/mix/tutorials/creating-custom-tokens.mdx Outdated
Clarify that ContextToken.call() only works for Mix's built-in token value set, per PR review feedback.

Co-authored-by: Cursor <cursoragent@cursor.com>
@tilucasoli

Copy link
Copy Markdown
Collaborator Author

Addressed the review feedback in 17774f71:

  • Qualified ContextToken scope to Mix's built-in token value types in design-token.mdx (including the comparison table).
  • Softened the custom-tokens callout to "you may not need a custom token" and documented .resolve(context) / custom-token paths for unsupported types.

Resolved the open threads — ready for another look when you have a moment.

@tilucasoli tilucasoli requested a review from leoafarias June 26, 2026 18:03

@leoafarias leoafarias left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@tilucasoli tilucasoli merged commit 49be70e into main Jun 29, 2026
4 checks passed
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