Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(CircularProgress): the indeterminate ring turns with Spinner's rotor (#8256)

Christopher Chedeaude1be1fd93e9
diff --git a/.changeset/spinner-rotor-shared.md b/.changeset/spinner-rotor-shared.md
new file mode 100644
index 0000000000..333e4c95fe
--- /dev/null
+++ b/.changeset/spinner-rotor-shared.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[chore] Internal: Spinner's rotor (the turning arc's keyframe, timing and timeline-origin pin) moves into one internal module that Lab's indeterminate CircularProgress also uses. Spinner does not change.
+
+@vjeux
diff --git a/packages/core/package.json b/packages/core/package.json
index 4d2003defd..e25b0270e7 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -838,6 +838,11 @@
"source": "./src/internal/selectable-card.ts",
"types": "./dist/internal/selectable-card.d.ts",
"default": "./dist/internal/selectable-card.js"
+ },
+ "./internal/spinner-rotor": {
+ "source": "./src/internal/spinner-rotor.ts",
+ "types": "./dist/internal/spinner-rotor.d.ts",
+ "default": "./dist/internal/spinner-rotor.js"
}
},
"files": [
diff --git a/packages/core/src/Spinner/Spinner.test.tsx b/packages/core/src/Spinner/Spinner.test.tsx
index 63d3ac9ea0..fe5f6b2c60 100644
--- a/packages/core/src/Spinner/Spinner.test.tsx
+++ b/packages/core/src/Spinner/Spinner.test.tsx
@@ -12,6 +12,7 @@
import {describe, it, expect, vi, afterEach} from 'vitest';
import {Profiler} from 'react';
import {render, screen} from '@testing-library/react';
+import {SPINNER_ARC_FRACTION} from './spinnerRotor';
import {Spinner} from './Spinner';
import {InternationalizationProvider} from '../i18n';
import {defineTheme} from '../theme/defineTheme';
@@ -394,6 +395,15 @@ describe('Spinner ring', () => {
expect(raf).not.toHaveBeenCalled();
});
+ it('draws the arc at the shared rotor fraction', () => {
+ render(<Spinner size="xl" data-testid="spinner" />);
+ const arc = rotor().querySelector('circle');
+ const circumference = Math.PI * 28;
+ expect(arc?.getAttribute('stroke-dasharray')).toBe(
+ `${circumference * SPINNER_ARC_FRACTION} ${circumference * (1 - SPINNER_ARC_FRACTION)}`,
+ );
+ });
+
// The ring turns on the compositor: only the rotor moves, and only by
// `transform`, a property the browser animates without the main thread. A
// paint animation such as `stroke-dashoffset` would repaint the arc on the
diff --git a/packages/core/src/Spinner/Spinner.tsx b/packages/core/src/Spinner/Spinner.tsx
index b18bef2179..68fd286e73 100644
--- a/packages/core/src/Spinner/Spinner.tsx
+++ b/packages/core/src/Spinner/Spinner.tsx
@@ -18,7 +18,7 @@
import {useId, type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
-import {colorVars, durationVars, spacingVars} from '../theme/tokens.stylex';
+import {colorVars, spacingVars} from '../theme/tokens.stylex';
import type {BaseProps} from '../BaseProps';
import {Text} from '../Text/Text';
import {mergeProps} from '../utils/mergeProps';
@@ -28,6 +28,7 @@ import {
useComponentTranslator,
} from '../i18n/useComponentTranslator';
import english from '../i18n/generated-english/Spinner/Spinner.generated';
+import {spinnerRotorStyles, syncRotationPhase} from './spinnerRotor';
registerEnglishFallback(english);
@@ -36,13 +37,13 @@ registerEnglishFallback(english);
// =============================================================================
/**
- * Default fraction of the ring the moving arc covers. The canvas ring this
- * replaces swept 135deg, not the 270deg its constant's comment claimed.
+ * The fraction of the ring the arc covers: SPINNER_ARC_FRACTION. StyleX reads
+ * only a literal in this file, and a test pins the two together.
*
* Themeable via `--spinner-arc-fraction`, declared alongside the other public
* vars in `sizeStyles` below. Only the inline `strokeDasharray` attribute
- * (the pre-stylesheet render — see its own comment) still reads this
- * constant directly; the CSS side composes the dash from the live var.
+ * (the pre-stylesheet render) still reads the constant directly; the CSS side
+ * composes the dash from the live var.
*/
const ARC_FRACTION = 0.375;
@@ -152,85 +153,6 @@ function registerSpinnerVars(): void {
// elide.
registerSpinnerVars();
-/**
- * Pin every ring's rotation to the document timeline's origin instead of its
- * own start time, so spinners mounted seconds apart stay in phase.
- *
- * Setting `startTime` is exact where arithmetic on a clock read is not. A
- * negative `animation-delay` computed at mount is only as good as the gap
- * between the clock read and the frame the animation starts in. At 10x CPU
- * throttling that gap measured 116 degrees of drift.
- *
- * Rotors are collected and pinned in one frame. `getAnimations()` resolves
- * style, and `startTime` dirties it again. So pinning them one at a time makes
- * each mount re-force what the previous one invalidated: 53 style recalcs for
- * 38 spinners, against 19 batched.
- */
-const pendingRotors = new Set<HTMLSpanElement>();
-let flushScheduled = false;
-
-function pinRotorsToTimelineOrigin(): void {
- flushScheduled = false;
- const animations: Animation[] = [];
- for (const rotor of pendingRotors) {
- animations.push(...rotor.getAnimations());
- }
- pendingRotors.clear();
- for (const animation of animations) {
- animation.startTime = 0;
- }
-}
-
-/**
- * Ref callback for the rotor: the one place a mounted ring touches the DOM.
- *
- * It reads nothing back — the geometry is resolved by the cascade, not in JS.
- */
-function syncRotationPhase(
- rotor: HTMLSpanElement | null,
-): (() => void) | undefined {
- if (rotor == null) {
- return undefined;
- }
- // jsdom implements no Web Animations, and this runs in every consumer's
- // component tests.
- if (typeof rotor.getAnimations !== 'function') {
- return undefined;
- }
- pendingRotors.add(rotor);
- if (!flushScheduled) {
- flushScheduled = true;
- requestAnimationFrame(pinRotorsToTimelineOrigin);
- }
- return () => {
- pendingRotors.delete(rotor);
- };
-}
-
-// =============================================================================
-// Animation
-// =============================================================================
-
-/**
- * Full turns in one iteration of the rotation.
- *
- * Chromium wakes the main thread at each iteration boundary while the
- * document listens for `animationiteration`. React listens for it on every
- * root. One iteration holds 100 turns, so the wake comes once in 100 turns.
- * Each turn is 360 degrees, so the ring looks the same.
- */
-const TURNS_PER_ITERATION = 100;
-
-/**
- * A `transform` animation runs on the compositor, so the ring keeps turning
- * while a script runs. A `stroke-dashoffset` animation would repaint the arc
- * on the main thread every frame, so it would stop while a script runs.
- */
-const rotation = stylex.keyframes({
- '0%': {transform: 'rotate(0deg)'},
- '100%': {transform: `rotate(${360 * TURNS_PER_ITERATION}deg)`},
-});
-
// =============================================================================
// Styles
// =============================================================================
@@ -309,20 +231,6 @@ const styles = stylex.create({
gridArea: '1 / 1',
width: `var(${BOX_SIZE})`,
height: `var(${BOX_SIZE})`,
- // Mobile Safari keeps a re-timed animation off the main thread only on an
- // element with its own layer. So the rotor declares one before the start
- // time is set (see `pinRotorsToTimelineOrigin`).
- willChange: 'transform',
- // Reduced motion slows the turn but never stops it: a still ring reads as
- // broken. The status role and its name still say that work is busy.
- animationDuration: {
- // The loop reads the duration before a theme's tempo scales it.
- default: `calc(var(--_astryx-pre-tempo-duration-slow-min, ${durationVars['--duration-slow-min']}) * ${TURNS_PER_ITERATION})`,
- '@media (prefers-reduced-motion: reduce)': `calc(3s * ${TURNS_PER_ITERATION})`,
- },
- animationIterationCount: 'infinite',
- animationName: rotation,
- animationTimingFunction: 'linear',
},
circle: {
fill: 'none',
@@ -604,7 +512,7 @@ export function Spinner({
<span
ref={syncRotationPhase}
aria-hidden="true"
- {...stylex.props(styles.rotor)}>
+ {...stylex.props(styles.rotor, spinnerRotorStyles.turn)}>
<svg
width={frameSize}
height={frameSize}
diff --git a/packages/core/src/Spinner/index.ts b/packages/core/src/Spinner/index.ts
index 65d9129d31..6d2e259043 100644
--- a/packages/core/src/Spinner/index.ts
+++ b/packages/core/src/Spinner/index.ts
@@ -12,8 +12,4 @@
*/
export {Spinner} from './Spinner';
-export type {
- SpinnerProps,
- SpinnerSize,
- SpinnerShade,
-} from './Spinner';
+export type {SpinnerProps, SpinnerSize, SpinnerShade} from './Spinner';
diff --git a/packages/core/src/Spinner/spinnerRotor.test.tsx b/packages/core/src/Spinner/spinnerRotor.test.tsx
new file mode 100644
index 0000000000..6907b93680
--- /dev/null
+++ b/packages/core/src/Spinner/spinnerRotor.test.tsx
@@ -0,0 +1,95 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file spinnerRotor.test.tsx
+ * @input Uses vitest, @testing-library/react, StyleX, spinnerRotor
+ * @output Pins the shared rotor's timing: turns per iteration and both
+ * durations, the reduced-motion one included
+ * @position Testing; validates spinnerRotor.ts, which Spinner and Lab's
+ * indeterminate CircularProgress share
+ *
+ * SYNC: When spinnerRotor.ts changes, update tests to match new behavior
+ */
+
+import {describe, expect, it} from 'vitest';
+import {render, screen} from '@testing-library/react';
+import * as stylex from '@stylexjs/stylex';
+import {spinnerRotorStyles} from './spinnerRotor';
+import {getAllInjectedCss} from '../__tests__/forcedColors';
+import {declaredValue} from '../__tests__/stylexDeclarations';
+
+const REDUCED_MOTION = '(prefers-reduced-motion: reduce)';
+
+/**
+ * The value the element's StyleX classes declare for `property` inside
+ * `@media <query>`. `declaredValue` reads only the unconditional rules.
+ */
+function declaredInMedia(
+ el: Element,
+ query: string,
+ property: string,
+): string | null {
+ const classes = new Set(Array.from(el.classList));
+ let value: string | null = null;
+ for (const sheet of Array.from(document.styleSheets)) {
+ for (const rule of Array.from(sheet.cssRules)) {
+ if (!(rule instanceof CSSMediaRule) || rule.media.mediaText !== query) {
+ continue;
+ }
+ for (const inner of Array.from(rule.cssRules)) {
+ if (!(inner instanceof CSSStyleRule)) {
+ continue;
+ }
+ const owner = /^\.([\w-]+)/.exec(inner.selectorText)?.[1];
+ if (owner == null || !classes.has(owner)) {
+ continue;
+ }
+ const declared = inner.style.getPropertyValue(property);
+ if (declared !== '') {
+ value = declared;
+ }
+ }
+ }
+ }
+ return value;
+}
+
+/**
+ * Seconds in a declared duration. StyleX folds `calc(3s * 100)` into
+ * `calc(300s)`, so both forms are read.
+ */
+function seconds(value: string | null): number {
+ const product = /^calc\(([\d.]+)s \* ([\d.]+)\)$/.exec(value ?? '');
+ if (product != null) {
+ return Number(product[1]) * Number(product[2]);
+ }
+ const plain = /^(?:calc\()?([\d.]+)s\)?$/.exec(value ?? '');
+ return plain == null ? Number.NaN : Number(plain[1]);
+}
+
+describe('spinnerRotor', () => {
+ // Chromium wakes the main thread at each iteration boundary while React
+ // listens for `animationiteration`. So one iteration holds 100 turns. Each
+ // duration is 100 periods, so one turn still takes one period.
+ it('turns 100 times in one iteration, over 100 periods, with reduced motion too', () => {
+ render(
+ <span data-testid="rotor" {...stylex.props(spinnerRotorStyles.turn)} />,
+ );
+ const rotor = screen.getByTestId('rotor');
+ const name = declaredValue(rotor, 'animation-name');
+ expect(name).toBeTruthy();
+ // jsdom's CSSOM lowercases the name in the rule but not in the at-rule.
+ const keyframes =
+ new RegExp(`@keyframes ${name}\\s*\\{([\\s\\S]*?\\})\\s*\\}`, 'i').exec(
+ getAllInjectedCss(),
+ )?.[1] ?? '';
+ expect(keyframes).toMatch(/rotate\(0deg\)/);
+ expect(keyframes).toMatch(/rotate\(36000deg\)/);
+ expect(declaredValue(rotor, 'animation-duration')).toMatch(
+ /^calc\(var\(--_astryx-pre-tempo-duration-slow-min,.*\) \* 100\)$/,
+ );
+ expect(
+ seconds(declaredInMedia(rotor, REDUCED_MOTION, 'animation-duration')),
+ ).toBe(3 * 100);
+ });
+});
diff --git a/packages/core/src/Spinner/spinnerRotor.ts b/packages/core/src/Spinner/spinnerRotor.ts
new file mode 100644
index 0000000000..5b4f1e2ed9
--- /dev/null
+++ b/packages/core/src/Spinner/spinnerRotor.ts
@@ -0,0 +1,113 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @file spinnerRotor.ts
+ * @input StyleX keyframes and the slow-min duration token
+ * @output The one turning arc: SPINNER_ARC_FRACTION, spinnerRotorStyles.turn
+ * and syncRotationPhase
+ * @position Spinner's rotor, shared by Spinner and Lab's indeterminate
+ * CircularProgress (through `@astryxdesign/core/internal/spinner-rotor`), so
+ * both rings turn the same way on the compositor.
+ */
+
+import * as stylex from '@stylexjs/stylex';
+import {durationVars} from '../theme/tokens.stylex';
+
+/** The fraction of the ring the arc covers: 135°. */
+export const SPINNER_ARC_FRACTION = 0.375;
+
+/**
+ * Full turns in one iteration of the rotation.
+ *
+ * Chromium wakes the main thread at each iteration boundary while the
+ * document listens for `animationiteration`. React listens for it on every
+ * root. One iteration holds 100 turns, so the wake comes once in 100 turns.
+ * Each turn is 360 degrees, so the ring looks the same.
+ */
+const TURNS_PER_ITERATION = 100;
+
+/**
+ * A `transform` animation runs on the compositor, so the ring keeps turning
+ * while a script runs. A `stroke-dashoffset` animation would repaint the arc
+ * on the main thread every frame, so it would stop while a script runs.
+ */
+const rotation = stylex.keyframes({
+ '0%': {transform: 'rotate(0deg)'},
+ '100%': {transform: `rotate(${360 * TURNS_PER_ITERATION}deg)`},
+});
+
+export const spinnerRotorStyles = stylex.create({
+ turn: {
+ // Mobile Safari keeps a re-timed animation off the main thread only on an
+ // element with its own layer. So the rotor declares one before the start
+ // time is set (see `pinRotorsToTimelineOrigin`).
+ willChange: 'transform',
+ // Reduced motion slows the turn but never stops it: a still ring reads as
+ // broken. The ring's role and name still say that work is busy.
+ animationDuration: {
+ // The loop reads the duration before a theme's tempo scales it.
+ default: `calc(var(--_astryx-pre-tempo-duration-slow-min, ${durationVars['--duration-slow-min']}) * ${TURNS_PER_ITERATION})`,
+ '@media (prefers-reduced-motion: reduce)': `calc(3s * ${TURNS_PER_ITERATION})`,
+ },
+ animationIterationCount: 'infinite',
+ animationName: rotation,
+ animationTimingFunction: 'linear',
+ },
+});
+
+/**
+ * Pin every ring's rotation to the document timeline's origin instead of its
+ * own start time, so spinners mounted seconds apart stay in phase.
+ *
+ * Setting `startTime` is exact where arithmetic on a clock read is not. A
+ * negative `animation-delay` computed at mount is only as good as the gap
+ * between the clock read and the frame the animation starts in. At 10x CPU
+ * throttling that gap measured 116 degrees of drift.
+ *
+ * Rotors are collected and pinned in one frame. `getAnimations()` resolves
+ * style, and `startTime` dirties it again. So pinning them one at a time makes
+ * each mount re-force what the previous one invalidated: 53 style recalcs for
+ * 38 spinners, against 19 batched.
+ */
+const pendingRotors = new Set<Element>();
+let flushScheduled = false;
+
+function pinRotorsToTimelineOrigin(): void {
+ flushScheduled = false;
+ const animations: Animation[] = [];
+ for (const rotor of pendingRotors) {
+ animations.push(...rotor.getAnimations());
+ }
+ pendingRotors.clear();
+ for (const animation of animations) {
+ animation.startTime = 0;
+ }
+}
+
+/**
+ * Ref callback for a rotor: the one place a mounted ring touches the DOM.
+ *
+ * It reads nothing back — the geometry is resolved by the cascade, not in JS.
+ */
+export function syncRotationPhase(
+ rotor: Element | null,
+): (() => void) | undefined {
+ if (rotor == null) {
+ return undefined;
+ }
+ // jsdom implements no Web Animations, and this runs in every consumer's
+ // component tests.
+ if (typeof rotor.getAnimations !== 'function') {
+ return undefined;
+ }
+ pendingRotors.add(rotor);
+ if (!flushScheduled) {
+ flushScheduled = true;
+ requestAnimationFrame(pinRotorsToTimelineOrigin);
+ }
+ return () => {
+ pendingRotors.delete(rotor);
+ };
+}
diff --git a/packages/core/src/internal/spinner-rotor.ts b/packages/core/src/internal/spinner-rotor.ts
new file mode 100644
index 0000000000..e05649a04e
--- /dev/null
+++ b/packages/core/src/internal/spinner-rotor.ts
@@ -0,0 +1,20 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+/**
+ * @file spinner-rotor.ts
+ * @input Spinner's shared rotor
+ * @output `@astryxdesign/core/internal/spinner-rotor`: SPINNER_ARC_FRACTION,
+ * spinnerRotorStyles and syncRotationPhase, re-exported by name for Lab's
+ * indeterminate CircularProgress
+ * @position An internal entry reserved for Astryx's own packages. It is
+ * undocumented, outside the public API and its compatibility promise, and
+ * versioned in lockstep with Core. The `@astryx/no-core-internal-import`
+ * lint rule allows it only in Core and Lab. Core components import the
+ * same modules by relative path. Named re-exports only.
+ *
+ * SYNC: When modified, update scripts/sync-exports.js.
+ */
+export {
+ SPINNER_ARC_FRACTION,
+ spinnerRotorStyles,
+ syncRotationPhase,
+} from '../Spinner/spinnerRotor';
diff --git a/packages/core/src/theme/themeMotion.test.ts b/packages/core/src/theme/themeMotion.test.ts
index f361bdda3d..e4ff939df1 100644
--- a/packages/core/src/theme/themeMotion.test.ts
+++ b/packages/core/src/theme/themeMotion.test.ts
@@ -538,7 +538,7 @@ describe('busy loops read the duration before tempo (spec:AST-108 FR4)', () => {
it('Spinner and Skeleton read the pre-tempo duration first', () => {
const read = (file: string) =>
fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
- expect(read('Spinner/Spinner.tsx')).toContain(
+ expect(read('Spinner/spinnerRotor.ts')).toContain(
"var(--_astryx-pre-tempo-duration-slow-min, ${durationVars['--duration-slow-min']})",
);
expect(read('Skeleton/Skeleton.tsx')).toContain(
diff --git a/packages/lab/src/CircularProgress/CircularProgress.test.tsx b/packages/lab/src/CircularProgress/CircularProgress.test.tsx
index dd056066b0..8c3794e4a5 100644
--- a/packages/lab/src/CircularProgress/CircularProgress.test.tsx
+++ b/packages/lab/src/CircularProgress/CircularProgress.test.tsx
@@ -2,6 +2,11 @@
import {describe, it, expect, vi} from 'vitest';
import {render, screen} from '@testing-library/react';
+import * as stylex from '@stylexjs/stylex';
+import {
+ SPINNER_ARC_FRACTION,
+ spinnerRotorStyles,
+} from '@astryxdesign/core/internal/spinner-rotor';
import {CircularProgress} from './CircularProgress';
/**
@@ -638,6 +643,24 @@ describe('CircularProgress', () => {
});
describe('indeterminate mode', () => {
+ it("turns Spinner's arc with Spinner's rotor", () => {
+ render(<CircularProgress isIndeterminate label="Loading" size="lg" />);
+ const ring = screen.getByRole('progressbar');
+ // The rotor's own classes, so the timing is Spinner's, not a copy.
+ for (const token of (
+ stylex.props(spinnerRotorStyles.turn).className ?? ''
+ ).split(' ')) {
+ expect(ring).toHaveClass(token);
+ }
+ const circles = ring.querySelectorAll('circle');
+ const arc = circles[circles.length - 1];
+ const r = Number(arc.getAttribute('r'));
+ const circumference = 2 * Math.PI * r;
+ expect(arc.getAttribute('stroke-dasharray')).toBe(
+ `${circumference * SPINNER_ARC_FRACTION} ${circumference * (1 - SPINNER_ARC_FRACTION)}`,
+ );
+ });
+
it('renders indeterminate when isIndeterminate is true', () => {
render(<CircularProgress isIndeterminate value={50} label="Loading" />);
const progressbar = screen.getByRole('progressbar');
diff --git a/packages/lab/src/CircularProgress/CircularProgress.tsx b/packages/lab/src/CircularProgress/CircularProgress.tsx
index 1b28622da6..3df4d96340 100644
--- a/packages/lab/src/CircularProgress/CircularProgress.tsx
+++ b/packages/lab/src/CircularProgress/CircularProgress.tsx
@@ -5,7 +5,8 @@
/**
* @file CircularProgress.tsx
* @input Uses React (useId, refs, layout effects), stylex, SVG, Web
- * Animations, color/spacing/duration/ease tokens
+ * Animations, color/spacing/duration/ease tokens, and Spinner's rotor
+ * (core internal/spinner-rotor) for the indeterminate ring
* @output Exports CircularProgress component, CircularProgressProps, CircularProgressSize, CircularProgressVariant types
* @position Core implementation; consumed by index.ts
*
@@ -27,6 +28,11 @@ import {
spacingVars,
typeScaleVars,
} from '@astryxdesign/core/theme/tokens.stylex';
+import {
+ SPINNER_ARC_FRACTION,
+ spinnerRotorStyles,
+ syncRotationPhase,
+} from '@astryxdesign/core/internal/spinner-rotor';
import {mergeProps} from '@astryxdesign/core/utils';
import type {BaseProps} from '@astryxdesign/core';
import {themeProps} from '@astryxdesign/core/utils';
@@ -119,7 +125,8 @@ export interface CircularProgressProps extends BaseProps<HTMLDivElement> {
*/
variant?: CircularProgressVariant;
/**
- * When true, renders an animated indeterminate progress indicator.
+ * When true, renders an animated indeterminate progress indicator: an arc
+ * that turns as Spinner's does.
* Use when the progress amount is unknown (e.g. loading, processing).
* The `value` and `hasValueLabel` props are ignored in this mode.
* Respects `prefers-reduced-motion` by slowing the animation.
@@ -138,32 +145,6 @@ export interface CircularProgressProps extends BaseProps<HTMLDivElement> {
'data-testid'?: string;
}
-// =============================================================================
-// Indeterminate animation
-// =============================================================================
-
-const indeterminateRotation = stylex.keyframes({
- '0%': {transform: 'rotate(0deg)'},
- '100%': {transform: 'rotate(360deg)'},
-});
-
-// SVG dash percentages scale with the square viewport. A 300% gap exceeds every
-// ring circumference; shifting the 2% + 300% pattern by 302% closes the loop.
-const indeterminateDash = stylex.keyframes({
- '0%': {
- strokeDasharray: '2%, 300%',
- strokeDashoffset: '0%',
- },
- '50%': {
- strokeDasharray: '175%, 300%',
- strokeDashoffset: '-68%',
- },
- '100%': {
- strokeDasharray: '2%, 300%',
- strokeDashoffset: '-302%',
- },
-});
-
// =============================================================================
// Styles
// =============================================================================
@@ -186,13 +167,6 @@ const styles = stylex.create({
},
svgIndeterminate: {
display: 'block',
- animationName: indeterminateRotation,
- animationDuration: {
- default: '2s',
- '@media (prefers-reduced-motion: reduce)': '4s',
- },
- animationTimingFunction: 'linear',
- animationIterationCount: 'infinite',
},
track: {
fill: 'none',
@@ -270,13 +244,6 @@ const styles = stylex.create({
fillIndeterminate: {
fill: 'none',
strokeLinecap: 'round',
- animationName: indeterminateDash,
- animationDuration: {
- default: '1.5s',
- '@media (prefers-reduced-motion: reduce)': '3s',
- },
- animationTimingFunction: 'ease-in-out',
- animationIterationCount: 'infinite',
},
children: {
position: 'absolute',
@@ -687,8 +654,10 @@ export function CircularProgress({
width={diameter}
height={diameter}
viewBox={`0 0 ${diameter} ${diameter}`}
+ ref={isIndeterminate ? syncRotationPhase : undefined}
{...stylex.props(
isIndeterminate ? styles.svgIndeterminate : styles.svg,
+ isIndeterminate && spinnerRotorStyles.turn,
)}>
<circle
{...mergeProps(
@@ -713,6 +682,10 @@ export function CircularProgress({
cy={center}
r={radius}
strokeWidth={strokeWidth}
+ // Spinner's arc: the same fraction of the ring, starting at 12
+ // o'clock.
+ strokeDasharray={`${circumference * SPINNER_ARC_FRACTION} ${circumference * (1 - SPINNER_ARC_FRACTION)}`}
+ transform={`rotate(-90 ${center} ${center})`}
/>
) : null}
</svg>
diff --git a/scripts/sync-exports.js b/scripts/sync-exports.js
index ea99de61df..4277ddbe61 100644
--- a/scripts/sync-exports.js
+++ b/scripts/sync-exports.js
@@ -240,6 +240,7 @@ const FILE_MODULE_SUBPATH_EXPORTS = [
'internal/indicatorPress.stylex',
'internal/touch',
'internal/selectable-card',
+ 'internal/spinner-rotor',
];
/**