Skip to content

new: animation primitives for Solid 2.0#947

Open
davedbase wants to merge 9 commits into
solidjs-community:nextfrom
davedbase:v2/animation
Open

new: animation primitives for Solid 2.0#947
davedbase wants to merge 9 commits into
solidjs-community:nextfrom
davedbase:v2/animation

Conversation

@davedbase

@davedbase davedbase commented Jun 25, 2026

Copy link
Copy Markdown
Member

This introduces a new package, @solid-primitives/animation, providing reactive and imperative wrappers for the Web Animations API. All primitives follow the existing make / create convention: make* is imperative and returns immediately, create* is a reactive wrapper that re-runs on dependency change and cancels on owner disposal.

Primitives:

  • makeAnimate / createAnimate — thin wrapper around element.animate(), the reactive version re-runs whenever target, keyframes, or options change
  • makeScrollAnimation / createScrollAnimation — scroll-driven animation via ScrollTimeline; no scroll listeners or RAF loops needed
  • makeViewAnimation / createViewAnimation — viewport-driven animation via ViewTimeline; replaces the IntersectionObserver + class-toggle pattern. Includes rangeStart/rangeEnd options (defaulting to "entry 0%" / "entry 100%") to scope animation to the entry phase only
  • makeFlip — FLIP layout animation; snapshot() before the DOM change, flip() after
  • makeStagger / createStagger — staggered WAAPI animation across a list of elements with a per-element delay offset
  • makeAnimationGroup / createAnimationGroup — coordinates a list of Animation objects as a single unit; all five control methods (play, pause, cancel, reverse, finish) forwarded simultaneously. The reactive variant re-derives the group via createMemo whenever the animation list changes
  • makeMotionPath / createMotionPath — animates an element along a CSS offset-path using offsetDistance; sets offsetAnchor: center so the element center tracks the path
  • makeSequence — chains animation factories into a sequential playlist; factories are called lazily, each only when its predecessor finishes

Also includes a full Storybook stories file with interactive demos for each primitive, and a Vitest test suite covering the reactive wrappers, lifecycle cancellation, and option forwarding.

Summary by CodeRabbit

  • New Features

    • Added a new animation package with helpers for basic, scroll-driven, view-driven, FLIP, staggered, grouped, sequential, motion-path, and presence animations.
    • Added demos and Storybook examples showcasing the new animation APIs in action.
  • Documentation

    • Expanded package and repo docs with installation, usage, API overviews, and catalog entries.
    • Added licensing and changelog information for the new package.
  • Tests

    • Added automated coverage for the new animation utilities and their expected behavior.

@davedbase davedbase added this to the Solid 2.0 Migration milestone Jun 25, 2026
@davedbase davedbase marked this pull request as ready for review June 25, 2026 15:54
@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 15dcee0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solid-primitives/animation Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1253bb97-70f8-482b-acd3-7443dc590a8c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
packages/animation/README.md (1)

20-35: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the motion-path and sequence primitives here.

The package surface already exports makeMotionPath / createMotionPath and makeSequence, but this README stops at createPresenceAnimation. Please add table entries and matching sections so the shipped API is discoverable from the package landing page.

Suggested diff
 | [`makeAnimationGroup`](`#makeanimationgroup--createanimationgroup`) | Coordinate multiple animations as a unit |
 | [`createAnimationGroup`](`#makeanimationgroup--createanimationgroup`) | Reactive `makeAnimationGroup` |
+| [`makeMotionPath`](`#makemotionpath--createmotionpath`) | Animate along a CSS `offset-path` |
+| [`createMotionPath`](`#makemotionpath--createmotionpath`) | Reactive `makeMotionPath` |
+| [`makeSequence`](`#makesequence`) | Chain animation factories sequentially |
 | [`createPresenceAnimation`](`#createpresenceanimation`) | Mount/unmount lifecycle with WAAPI enter/exit animations |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/animation/README.md` around lines 20 - 35, Add the missing
documentation for the exported motion-path and sequence APIs in the animation
README: update the primitives table to include makeMotionPath/createMotionPath
and makeSequence, then add matching section anchors/details later in the
document so these symbols are discoverable alongside createPresenceAnimation.
Use the existing README entries for makeAnimate, createAnimationGroup, and
createPresenceAnimation as the pattern for naming and linking.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/animation/src/flip.ts`:
- Around line 27-34: The FLIP animation in flip() computes scale using
rect.width / next.width and rect.height / next.height without checking for
zero-sized target bounds. Add a guard before calculating sx and sy (or before
calling el.animate) to bail out when next.width or next.height is 0, and keep
the early return path in flip() so invalid transform values cannot be generated.

In `@packages/animation/src/motion-path.ts`:
- Line 28: The offset-path assignment in motion-path.ts is too aggressive
because it wraps every non-`path(...)` input into `path("...")`, which breaks
valid CSS values like `circle(...)` and `ray(...)`. Update the logic in the
motion-path setter so it preserves already-valid CSS `offset-path` values and
only normalizes raw SVG path strings when needed; use the existing `offsetPath`
handling in `motion-path.ts` as the place to make this distinction.

In `@packages/animation/src/presence-animation.ts`:
- Around line 26-30: The default exit path in reverseKeyframes and the
enter/exit handling in presence-animation.ts only reverse array-based keyframes,
so object-style PropertyIndexedKeyframes can still exit unreversed. Update
reverseKeyframes and the exit generation logic around the presence animation
flow so PropertyIndexedKeyframes are also transformed into a reversed form (or
otherwise handled equivalently) before being used for the default exit, while
preserving null and already-array behavior.

In `@README.md`:
- Line 142: The package catalog entry for the animation primitives is using the
wrong symbol name. Update the animation row in README to replace the nonexistent
createFlip reference with the actual exported primitive makeFlip, and ensure the
linked anchor points to the makeFlip documentation so the README matches the
package API.

---

Nitpick comments:
In `@packages/animation/README.md`:
- Around line 20-35: Add the missing documentation for the exported motion-path
and sequence APIs in the animation README: update the primitives table to
include makeMotionPath/createMotionPath and makeSequence, then add matching
section anchors/details later in the document so these symbols are discoverable
alongside createPresenceAnimation. Use the existing README entries for
makeAnimate, createAnimationGroup, and createPresenceAnimation as the pattern
for naming and linking.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5672af77-f390-471f-8486-aaa245192458

📥 Commits

Reviewing files that changed from the base of the PR and between 9641025 and b662ac1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (20)
  • .changeset/animation-initial.md
  • README.md
  • packages/animation/CHANGELOG.md
  • packages/animation/LICENSE
  • packages/animation/README.md
  • packages/animation/dev/index.tsx
  • packages/animation/package.json
  • packages/animation/src/animate.ts
  • packages/animation/src/animation-group.ts
  • packages/animation/src/flip.ts
  • packages/animation/src/index.ts
  • packages/animation/src/motion-path.ts
  • packages/animation/src/presence-animation.ts
  • packages/animation/src/scroll-animation.ts
  • packages/animation/src/sequence.ts
  • packages/animation/src/stagger.ts
  • packages/animation/src/view-animation.ts
  • packages/animation/stories/animation.stories.tsx
  • packages/animation/test/index.test.ts
  • packages/animation/tsconfig.json

Comment thread packages/animation/src/flip.ts Outdated
Comment thread packages/animation/src/motion-path.ts Outdated
Comment thread packages/animation/src/presence-animation.ts Outdated
Comment thread README.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant