Skip to content

Consolidate button style resolution into StyleAttributeMapper#274

Merged
chubes4 merged 1 commit into
trunkfrom
refactor/button-style-consolidation
Jun 28, 2026
Merged

Consolidate button style resolution into StyleAttributeMapper#274
chubes4 merged 1 commit into
trunkfrom
refactor/button-style-consolidation

Conversation

@chubes4

@chubes4 chubes4 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Refs #242

Consolidate button style resolution into StyleAttributeMapper; behavior-preserving.

Why

ButtonStyleResolver (#241) independently re-parsed the same CSS color / typography / spacing / border declarations that the shared StyleAttributeMapper (#261) already resolves for every block. The overlap was literal, not coincidental:

  • parseBorderShorthand() was byte-for-byte identical between the two classes.
  • border(), backgroundColor(), boxSides()/padding(), and cssColor()/color() were near-duplicate CSS-parsing mechanics.

The only genuinely button-specific semantic (filled-vs-outline / is-style-outline) already lives in ButtonsPattern::hasOutlineSignal, not in ButtonStyleResolver. So ButtonStyleResolver was almost pure duplicated parsing plus a thin button presentation policy.

What

ButtonStyleResolver::nativeAttributes() now delegates the generic CSS→attribute parsing to StyleAttributeMapper::map() and keeps only the button presentation policy:

  • color shape {background, text} (background before text), never a gradient fill;
  • spacing.padding only (buttons don't carry margin — inter-button spacing rides on the parent core/buttons gap);
  • the curated typography subset (fontSize, fontWeight, lineHeight, textTransform).

The string→declarations parser stays (the mapper takes a declaration array; the button entry point takes the resolved CSS string). ButtonsPattern and StyleAttributeMapper are untouched.

Net: -178 / +50 lines in ButtonStyleResolver.php; the duplicated CSS-parsing helpers are gone.

Behavior-preserving

The emitted style object — and its key order, which the parity runner compares with strict !== — is byte-identical. Baseline and post-change:

  • composer parity: 144 fixtures pass (unchanged), filled → bg+text, ghost → is-style-outline + border+text, unstyled → default.
  • Full composer test green (canonical + parity + packaging); php -l clean.
  • No fixture edited.

🤖 Generated with Claude Code

ButtonStyleResolver independently re-parsed the same CSS color/typography/
spacing/border declarations that the shared StyleAttributeMapper (#261)
already resolves for every block (parseBorderShorthand was byte-for-byte
identical; border/backgroundColor/boxSides/cssColor were near-duplicates).

Delegate that generic CSS->attribute mechanic to StyleAttributeMapper and
keep only the button-specific presentation policy in ButtonStyleResolver:
background-before-text color shape, no gradient fill, padding-not-margin
spacing, and the curated typography subset. Behavior-preserving: the emitted
style object (and its key order) is byte-identical, so all 144 parity
fixtures pass unchanged.

Refs #242

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chubes4 chubes4 merged commit d06ed22 into trunk Jun 28, 2026
1 check passed
@chubes4 chubes4 deleted the refactor/button-style-consolidation branch June 28, 2026 11:53
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.

1 participant