Skip to content

feat(Spinner): add --spinner-arc-fraction public var - #5845

Open
HelloOjasMutreja wants to merge 1 commit into
facebook:mainfrom
HelloOjasMutreja:feat/spinner-arc-fraction-var
Open

feat(Spinner): add --spinner-arc-fraction public var#5845
HelloOjasMutreja wants to merge 1 commit into
facebook:mainfrom
HelloOjasMutreja:feat/spinner-arc-fraction-var

Conversation

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor

Fixes #5819.

What's missing

Spinner exposes four public vars on the spinner target (--spinner-diameter, --spinner-stroke-width, --spinner-color, --spinner-track-color) so a theme can change size, stroke, and color. It cannot change how much of the circle the moving arc covers — that was a compiled-in constant (ARC_FRACTION = 0.375, a 135deg sweep).

Why this was an issue and not immediately a PR

The catch the issue raised: the CSS side (styles.arc.strokeDasharray) already composes its dash from a calc(), so making it themeable there is close to free. But there's also an inline strokeDasharray SVG attribute — the pre-stylesheet render, for SSR / no-JS — computed in JS, which can't read a CSS custom property. A themed sweep would draw the default 135deg in that frame and snap to the themed value once the stylesheet lands.

Why this is safe: precedent already set

Checked how --spinner-diameter (the var this issue explicitly compares itself to) already handles this exact split, since it's used in both places too:

  • CSS side (styles.arc, styles.circle.r, etc.): reads the live, themeable RESOLVED_DIAMETER var.
  • Inline attributes (the <circle r={diameter / 2}> presentation attributes, and the pre-CSS strokeDasharray): const {diameter} = SIZES[size] — the hardcoded default, not the themed value.

So a themed diameter already only takes visual effect once the stylesheet loads, and the pre-CSS frame already renders at the unthemed default. This isn't a new kind of box-vs-paint disagreement (the class of bug #5214 and #5484 dealt with) — it's applying the one this component already ships, to one more property.

Change

  • styles.arc.strokeDasharray now composes the dash from var(--spinner-arc-fraction) (a live number multiplier) instead of the pre-multiplied ARC_DASH/ARC_GAP constants.
  • --spinner-arc-fraction declares alongside --spinner-diameter/--spinner-stroke-width in sizeStyles, same default (0.375) for every size, unregistered like the other three public vars (no length-arithmetic ambiguity to guard against — it's a pure multiplier, not summed with anything).
  • The inline strokeDasharray attribute (the pre-stylesheet render) is untouched — still ARC_FRACTION, matching how the inline diameter attributes stay at their default too.

Testing

  • npx vitest run packages/core/src/Spinner/Spinner.test.tsx — 48/48 pass, including a new test confirming a themed size:xl target scopes --spinner-arc-fraction correctly (mirroring the existing diameter/color scoping tests).
  • Built @astryxdesign/core and inspected the compiled dist/astryx.css directly: confirmed --spinner-arc-fraction:.375 declares on the size-variant rule and strokeDasharray composes from var(--spinner-arc-fraction) in the compiled calc(), not just in source.
  • Typecheck and lint clean.

Posted the precedent-based reasoning on the issue first; given how directly it settles the ambiguity the issue raised (and the reporter's own "happy to implement whichever"), opening this as the concrete proposal rather than waiting further — happy to adjust based on any maintainer feedback.

@vercel

vercel Bot commented Sep 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 2, 2026 11:55am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 1, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Sep 1, 2026
github-actions Bot added a commit that referenced this pull request Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview availability: CI did not succeed, so no preview was published.

Modified Components

Spinner (@astryxdesign/core)
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 293 -
Complexity N/A High (25) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

Status: No visual change across 14 compared shot(s).


Generated by PR Enrichment workflow | View full report

The four existing public vars (diameter, stroke-width, color,
track-color) all reach the ring's geometry or paint except one: how
much of the circle the moving arc covers. That's the most visually
distinctive property at a given size, and it looks explicitly
permitted rather than excluded by the theming contract facebook#5771 is
recording (ring geometry through the spinner target, no new target).

Applies the exact precedent this component already sets for diameter:
the CSS-side strokeDasharray composes the dash from the live var, and
the inline attribute (the pre-stylesheet render) keeps using the
compiled-in default, unchanged. A themed sweep applies once the
stylesheet lands, the same way a themed diameter already does.

Fixes facebook#5819.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spinner: arc sweep is the one ring geometry a theme cannot change

1 participant