Skip to content

feat(many): support current spacing tokens in the margin prop for v2 components#2587

Open
balzss wants to merge 1 commit into
masterfrom
new-margin-spacing
Open

feat(many): support current spacing tokens in the margin prop for v2 components#2587
balzss wants to merge 1 commit into
masterfrom
new-margin-spacing

Conversation

@balzss

@balzss balzss commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

What & why

The current (era-3) spacing tokensgeneral.*, gap.*, padding.card.* (dot-path notation, e.g. margin="general.spaceMd") — already resolved at runtime in View v2, but the Spacing prop type and the docs only advertised the two older token eras. So the new tokens had no autocomplete, no type hints, and weren't documented.

This PR makes them first-class on the margin prop of v2 components. Non-breaking — the older tokens still resolve at runtime and are only marked @deprecated.

What changed

Area Change
Types (emotion) Add CurrentSpacingValues (era-3 dot-paths) to the Spacing union; mark era-1 / era-2 unions @deprecated.
v2 components Sync the margin JSDoc across all v2 props.ts files — link to the spacing guide + current-token example.
v2 READMEs Convert legacy spacing keywords in margin examples to general.* tokens (value-preserving mapping).
Docs guide Re-add the Layout Spacing page (removed on master during the docs rework) as a v11.7+ version-gated page, following the theme-overrides version-banner pattern.
Tests era-3 dot-path resolution in calcSpacingFromShorthand; View v2 integration test (general.spaceMd0.75rem); regression-test page examples.

Reviewer notes

  • Legacy → era-3 example mapping is value-preserving where an equivalent exists (smallgeneral.spaceMd, mediumgeneral.spaceXl, …). large/x-large have no general equivalent (scale tops out at 2rem) and compress to general.space2xl — the only intentional visual change, limited to doc examples.
  • Live doc examples use margin/padding only. These resolve era-3 dot-paths via calcSpacingFromShorthand. The Flex gap prop uses a separate flat-key resolver that doesn't understand dot-paths, so it's intentionally not shown with them.
  • Scope: v2 components only; the dot-path resolver / token-merge logic is unchanged.

Testing

  • pnpm run test:vitest emotion → 78 passed
  • pnpm run test:vitest ui-view → 16 passed
  • Visual regression (Cypress/Chromatic) not run; doc/regression page examples added for it.

Follow-ups (not in this PR)

  • padding prop examples still use legacy tokens (kept out of scope; easy identical sweep).
  • Misspelled tokens compile (type ends in (string & {})) and only warn at runtime — a louder dev-mode warning could be added later.

…components

Surface the current (era-3) spacing tokens (general.*, gap.*, padding.card.*
dot-paths) on the `margin` prop of v2 components. View v2 already resolved them
at runtime, but the `Spacing` type and component docs only advertised the older
token eras.

- emotion: add CurrentSpacingValues dot-path literals to the Spacing union and
  mark the legacy (era-1) and phased-out (era-2) unions as @deprecated
- v2 components: sync the margin JSDoc to point at the spacing guide and use a
  current-token example
- docs: rewrite the Layout Spacing guide to lead with the current tokens and
  demote the older eras to a "Deprecated tokens" section; update View/Flex/Tag
  README examples
- tests: cover era-3 dot-path resolution in calcSpacingFromShorthand and add
  View v2 integration tests; add regression-test examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://instructure.design/pr-preview/pr-2587/

Built to branch gh-pages at 2026-06-10 12:37 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

github-actions Bot pushed a commit that referenced this pull request Jun 10, 2026
@github-actions

Copy link
Copy Markdown

Visual regression report

⚠️ Changes detected.

Status Count
Unchanged 31
Changed 1
New 0
Removed 0

📊 View full report

Diff images (1)

view.png — 5306 pixels differ

Baselines come from the visual-baselines branch. They refresh on every merge to master.

@balzss balzss self-assigned this Jun 10, 2026
@balzss balzss marked this pull request as ready for review June 11, 2026 11:44

@ToMESSKa ToMESSKa 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 haven't checked all, but some of the v2 examples still use older spacing values in the margin prop (e.g. Alert, Badge), those should be updated too.

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

See my comment

* familiar CSS-like shorthand. For example: `margin="small auto large"`.
* Valid values are `0`, `none`, `auto`, and Spacing token values,
* see https://instructure.design/layout-spacing. Apply these values via
* familiar CSS-like shorthand. For example, `margin="general.spaceMd auto"`.

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.

In v2 Avatar, Flex, FormFieldLayout, Link still recommend the legacy margin="small auto large"

@HerrTopi HerrTopi removed their request for review June 23, 2026 09:59
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