Skip to content

feat(spec): support and document grouped tokens across token categories - #179

Merged
davideast merged 7 commits into
mainfrom
docs/grouped-tokens-spec
Nov 18, 2026
Merged

davideast merged 7 commits into
mainfrom
docs/grouped-tokens-spec

Conversation

@xkxx

@xkxx xkxx commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Design systems need to organize theme modes, responsive scales, and hierarchical token families across token categories without flattened naming boilerplate or raw dots leaking into exported token formats.

Approach

  • Traverse nested group sub-maps in typography through a shared token-tree helper with the existing 20-level nesting limit and flat-vs-grouped collision detection, matching colors, spacing, and rounded.
  • Report explicit errors when a typography entry is empty (lg: {}), contains a non-token child inside a group (note: compact), or mixes typography properties with nested objects, and recognize primary inside color groups in missing-primary.
  • Emit grouped tokens idiomatically across all CLI export formats - nested DTCG groups across color, spacing, rounded, and typography, nested colors objects (with DEFAULT shade promotion) plus hyphenated flat scales for Tailwind v3 theme.extend, and hyphenated custom properties for Tailwind v4 @theme and css-vars.
  • Document grouped token sub-maps, dot-path references, and non-normative example group names (light, dark, sm, md, lg, xl) in docs/spec.md and README.md, clarifying that groups are organizational only and carry no reserved behavior.

Decisions

  • Keep the existing 20-level nesting limit across all token categories so multi-level token hierarchies remain backwards compatible.
  • Nest colors in json-tailwind while hyphenating spacing, borderRadius, fontSize, and fontFamily, because Tailwind v3 only flattens nested objects on colors.

Verification

  • Added unit, PostCSS Tailwind v3 compilation, and CLI export tests across dtcg, json-tailwind, css-tailwind, and css-vars, plus grouped typography and missing-primary coverage (391 passing tests across bun test, bun run lint, and bun run build).

Closes #193

@xkxx
xkxx requested a review from davideast October 1, 2026 04:34
@xkxx
xkxx marked this pull request as ready for review October 1, 2026 04:34
# Conflicts:
#	packages/cli/src/linter/index.test.ts
@davideast

Copy link
Copy Markdown
Collaborator

Here's a few things I propose needs tweaking.

1. Keep it backwards compatible

The PR lowers max_token_nesting_depth from 20 to 1, and the model handler reports anything deeper as an error. Colors, spacing and rounded tokens already accept deeper nesting today, so a file like this lints clean now and would fail after the change:

colors:
  brand:
    primary:
      base: "#647D66"

Could we make the change additive instead?

  • Revert the limit in the spec config and its schema default.
  • Restore the tests for 3-level, 4-level and 20-level nesting.
  • Let grouped typography use the same existing limit.

2. Describe groups as naming only

The current wording suggests light, dark and sm to xl have specific meaning in the spec. We do want to recommend but we don't want to prescribe so we can offer up clarification in the spec.

Groups are organizational and carry no behavior. Names such as light, dark, sm and lg are examples, not reserved words.

3. Typography group detection

A typography entry is treated as a group based on its shape. Two cases look like they fall through to being parsed as a single token:

typography:
  sm:
    headline-lg: { fontFamily: Public Sans, fontSize: 32px }
    note: compact        # one non-object child
  lg: {}                 # empty group

An explicit error for a group with a non-token child, plus tests for both cases, would make this clearer.

4. Follow-up: exports

From reading the handlers, a grouped token is stored under a dotted key such as light.surface. The CSS-variable export converts the dot to a hyphen, but the Tailwind and DTCG exports appear to use the key as is. This already applies to grouped colors, so it does not need to block this PR. Could we add an export test per format here, or open an issue to track it? Nesting the output seems the natural fit for both formats.

Small things

  • The "no primary color" warning only looks at the top level, so a file with every color under light and dark gets it. Worth a line in the spec or a change to the rule.
  • The new typography traversal duplicates the existing one, including the depth check. A shared helper would keep them in step.

@xkxx

xkxx commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Good catches - updated all four items and both small things directly in this PR:

  • Restored the 20-level nesting limit and existing multi-level tests so this stays additive, with grouped typography sharing the same traversal helper and limit.
  • Clarified in the spec that groups are organizational only and names like light, dark, sm, and lg are examples rather than reserved words.
  • Added explicit errors and tests for empty typography maps (lg: {}) and non-token children inside a typography group (note: compact), and updated missing-primary to recognize primary inside color groups.
  • Updated export and added per-format grouped token tests across dtcg (nested groups across all categories), json-tailwind (nested colors plus hyphenated spacing, borderRadius, fontSize, and fontFamily, since Tailwind v3 only flattens nested objects on colors), css-tailwind, and css-vars.

@davideast
davideast merged commit db977b3 into main Nov 18, 2026
14 checks passed
@davideast
davideast deleted the docs/grouped-tokens-spec branch November 18, 2026 02:55
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.

feat(export): emit idiomatic nested and hyphenated grouped tokens across dtcg and tailwind formats

2 participants