Skip to content

Conversation

@git-nandor
Copy link
Contributor

@git-nandor git-nandor commented Dec 4, 2025

Summary

Fixed console warnings when using direct CSS values (like 0, auto, 12px) in the margin prop of components. The calcMarginFromShorthand utility now properly recognizes valid CSS values before attempting theme token lookup, eliminating unnecessary warnings while maintaining full backward compatibility.

Changes

Added CSS value recognition logic to calcMarginFromShorthand before theme token lookup:
New helper functions:
isCSSValue(): Detects valid CSS margin values using pattern matching
normalizeCSSValue(): Normalizes values (e.g., 'none' → '0')
Execution order (unchanged, just added CSS check first):

  1. CSS value check (NEW) → if valid, return immediately
  2. Flat token lookup → spacingMap[token]
  3. Nested path lookup → spacingMap.gap.sm
  4. Warning + fallback

Recognized CSS values:
Keywords: '0', 'auto', 'none' (converted to '0')
Units: '12px', '0.5rem', '2em', '100%', etc.

Test plan

Apply different margin values to the Avatar (e.g., margin="0 small"), then verify the console warnings.

Co-Authored-By: 🤖 Claude

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

PR Preview Action v1.6.3

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

Built to branch gh-pages at 2025-12-04 15:18 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@git-nandor git-nandor self-assigned this Dec 4, 2025
@git-nandor git-nandor requested a review from matyasf December 4, 2025 15:25
@git-nandor git-nandor marked this pull request as ready for review December 4, 2025 15:25
@git-nandor git-nandor requested a review from balzss December 5, 2025 10: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.

2 participants