Skip to content

feat: Include typography tokens to accept density values - #216

Merged
gethinwebster merged 6 commits into
mainfrom
dev-v3-cansua
Oct 15, 2026
Merged

gethinwebster merged 6 commits into
mainfrom
dev-v3-cansua

Conversation

@cansuaa

@cansuaa cansuaa commented Sep 22, 2026

Copy link
Copy Markdown
Member

Issue #, if available:
As part of density project, compact font-size needs to be reduced. Currently typography tokens can only accept string and this PR makes it possible to pass either strings or density values.

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov

codecov Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.69%. Comparing base (189c514) to head (dc6d785).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #216      +/-   ##
==========================================
+ Coverage   97.68%   97.69%   +0.01%     
==========================================
  Files          54       54              
  Lines        1469     1478       +9     
  Branches      273      274       +1     
==========================================
+ Hits         1435     1444       +9     
  Misses         29       29              
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The schema changes are backward-compatible and thoroughly tested across supported typography categories.

Review effort: Balanced
Findings: None

What changed in this PR

Extends theme JSON validation so typography tokens support both scalar strings and density-specific values.

Changes:

  • Adds density-aware schemas for typography tokens.
  • Improves anyOf validation diagnostics.
  • Adds comprehensive validation tests.
File Description
src/​build/​tasks/​theme-json-schema.ts Adds density schemas and expanded errors.
src/​build/​tasks/​__tests__/​theme-json-schema.test.ts Tests valid and invalid density typography values.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@gethinwebster
gethinwebster marked this pull request as ready for review October 2, 2026 10:12
@gethinwebster
gethinwebster requested a review from a team as a code owner October 2, 2026 10:12
@gethinwebster
gethinwebster requested review from amanabiy and removed request for a team October 2, 2026 10:12
Comment thread src/build/tasks/theme-json-schema.ts Outdated
patternProperties: {
'^color-': getTokenSchema(getComplexValueSchema(colorValueSchema, visualModes)),
'^font-family-': getTokenSchema(stringValueSchema),
'^font-family-': getTokenSchema({

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.

It's feels strange to see that the font-family changes between, density (comfortable, and compact), Is there a use case for density scoped font-family?

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.

there's no known use-case, but we thought it better to apply this consistently to all font-related properties for consistency

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.

Fair point on consistency. But there's no use case and this just adds unused schema surface for font-family. Widening it from string to string | density object later is backward-compatible, so we can add it whenever a real need comes up. No strong opinion though, if you'd rather keep all font-* uniform, I won't block on it.

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.

Fair point, I think it makes sense to remove it for now. Updated.


// Returns the full thrown message so assertions can check the complete
// expanded string, not just a prefix.
const getError = (tokens: Record<string, TokenJson>): string => {

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.

Instead of using getError method. Can we make sure the tests use similar behavior as the others, that would make it easier to read, and understand the test file.

something like this?

expect(() =>
  validateTokens(...),
).toThrowError(
  'Tokens validation error: instance.tokens.font-size-body.$value is not any of ' +
    '(subschema 0: instance does not match pattern "^\\d+(\\.\\d+)?(px|rem|em)$" | ' +
    'subschema 1: instance is not of a type(s) object)',
);

}),
).toThrowError(
'Tokens validation error: instance.tokens.letter-spacing-button.$value does not match pattern "^(normal|inherit|initial|revert|revert-layer|unset|-?\\\\d*\\\\.?\\\\d+(px|rem|em))$"',
'Tokens validation error: instance.tokens.letter-spacing-button.$value is not any of (subschema 0:',

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.

The new seems wrong, and also it removed the pattern it matched with.

const message = getError({
'font-size-body-m': { $value: { comfortable: 'big', compact: 'small' } },
});
// both offending modes are reported, separated by '; '

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.

Nit: for all the comments can we consider removing them? it seems like the test description, and the thrown errors give enough description.

).toThrowError(
'Tokens validation error: instance.tokens.font-size-body.$value does not match pattern "^\\\\d+(\\\\.\\\\d+)?(px|rem|em)$"',
);
).toThrowError('Tokens validation error: instance.tokens.font-size-body.$value is not any of (subschema 0:');

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.

Nit: can we also update this test to use something like this since it's matching only the initial substring right now?

.toThrowError(
  'Tokens validation error: instance.tokens.font-size-body.$value is not any of ' +
    '(subschema 0: instance does not match pattern "^\\\\d+(\\\\.\\\\d+)?(px|rem|em)$" | ' +
    'subschema 1: instance is not of a type(s) object)',
);

).toThrowError(
'Tokens validation error: instance.tokens.line-height-body.$value does not match pattern "^\\\\d+(\\\\.\\\\d+)?(px|rem|em)$"',
);
).toThrowError('Tokens validation error: instance.tokens.line-height-body.$value is not any of (subschema 0:');

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.

Same as the above, update to have the full error instead of being cut after (subschema 0:

@gethinwebster
gethinwebster added this pull request to the merge queue Oct 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Oct 14, 2026
@gethinwebster
gethinwebster added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit 1a862a5 Oct 15, 2026
44 checks passed
@gethinwebster
gethinwebster deleted the dev-v3-cansua branch October 15, 2026 06:18
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.

4 participants