react-component/motion

🎞️ Lifecycle-driven motion primitives for React enter, leave, and list animations.

TypeScript

179

164 commits

updated Sep 7, 2026

See the code

README

@rc-component/motion

Ant Design Part of the Ant Design ecosystem.

🎞️ Lifecycle-driven motion primitives for React enter, leave, and list animations.

NPM version npm downloads build status Codecov bundle size dumi

English | 简体中文

Highlights

  • Declarative CSSMotion component for appear, enter, and leave states.
  • CSSMotionList for keyed list transitions.
  • CSS class lifecycle hooks and inline style patching callbacks.
  • Optional deadline fallback when transition or animation events do not fire.
  • TypeScript definitions and React ref support.
  • Used by Ant Design components that need predictable motion lifecycles.

Install

npm install @rc-component/motion

Usage

import CSSMotion from '@rc-component/motion';

export default ({ visible }: { visible: boolean }) => (
  <CSSMotion visible={visible} motionName="fade">
    {({ className, style }, ref) => (
      <div ref={ref} className={className} style={style}>
        Content
      </div>
    )}
  </CSSMotion>
);
import { CSSMotionList } from '@rc-component/motion';

export default ({ keys }: { keys: string[] }) => (
  <CSSMotionList keys={keys} motionName="fade">
    {({ key, className, style }, ref) => (
      <div ref={ref} key={key} className={className} style={style}>
        {key}
      </div>
    )}
  </CSSMotionList>
);

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

CSSMotion

PropertyTypeDefaultDescription
children(props, ref) => ReactElement-Render function that receives motion class, style, and ref.
forceRenderbooleanfalseKeep the element rendered even when invisible.
leavedClassNamestring-Class name applied after leave when the element remains.
motionAppearbooleantrueEnable appear motion.
motionDeadlinenumber-Fallback timeout in milliseconds for motion completion.
motionEnterbooleantrueEnable enter motion.
motionLeavebooleantrueEnable leave motion.
motionLeaveImmediatelyboolean-Trigger leave immediately after mount.
motionNamestring | MotionName-CSS class name prefix or per-phase class names.
removeOnLeavebooleantrueRemove the element after leave. Ignored when forceRender is set.
visiblebooleantrueControls whether the element is visible.
onAppearActiveMotionEventHandler-Triggered during appear active phase.
onAppearEndMotionEndEventHandler-Triggered when appear finishes. Return false to keep waiting.
onAppearPrepareMotionPrepareEventHandler-Prepare callback before appear starts.
onAppearStartMotionEventHandler-Triggered when appear starts.
onEnterActiveMotionEventHandler-Triggered during enter active phase.
onEnterEndMotionEndEventHandler-Triggered when enter finishes. Return false to keep waiting.
onEnterPrepareMotionPrepareEventHandler-Prepare callback before enter starts.
onEnterStartMotionEventHandler-Triggered when enter starts.
onLeaveActiveMotionEventHandler-Triggered during leave active phase.
onLeaveEndMotionEndEventHandler-Triggered when leave finishes. Return false to keep waiting.
onLeavePrepareMotionPrepareEventHandler-Prepare callback before leave starts.
onLeaveStartMotionEventHandler-Triggered when leave starts.
onVisibleChanged(visible: boolean) => void-Triggered after the final visible state changes.

CSSMotionList

CSSMotionList accepts the motion props above, except children is a list render function.

PropertyTypeDefaultDescription
children(props, ref) => ReactElement-Render function for each keyed item.
componentstring | ComponentType | falsedivWrapper component. Use false for no wrapper.
keys(React.Key | { key: React.Key })[]-Keys to animate.
onAllRemoved() => void-Triggered after every leaving item is removed.
onVisibleChanged(visible, info: { key: React.Key }) => void-Triggered after an item visibility changes.

Ref

Ref methodTypeDescription
enableMotion() => booleanWhether motion is currently enabled.
inMotion() => booleanWhether the element is in a motion lifecycle.
nativeElementHTMLElementCurrent DOM element.

Development

npm install
npm start
npm test
npm run tsc
npm run compile
npm run build

The dumi site runs at http://localhost:8000 by default.

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

License

@rc-component/motion is released under the MIT license.

antd
ant-design
javascript
react
react-component

react-component/motion

🎞️ Lifecycle-driven motion primitives for React enter, leave, and list animations.

TypeScript

179

164 commits

updated Sep 7, 2026

See the code

README

@rc-component/motion

Ant Design Part of the Ant Design ecosystem.

🎞️ Lifecycle-driven motion primitives for React enter, leave, and list animations.

NPM version npm downloads build status Codecov bundle size dumi

English | 简体中文

Highlights

  • Declarative CSSMotion component for appear, enter, and leave states.
  • CSSMotionList for keyed list transitions.
  • CSS class lifecycle hooks and inline style patching callbacks.
  • Optional deadline fallback when transition or animation events do not fire.
  • TypeScript definitions and React ref support.
  • Used by Ant Design components that need predictable motion lifecycles.

Install

npm install @rc-component/motion

Usage

import CSSMotion from '@rc-component/motion';

export default ({ visible }: { visible: boolean }) => (
  <CSSMotion visible={visible} motionName="fade">
    {({ className, style }, ref) => (
      <div ref={ref} className={className} style={style}>
        Content
      </div>
    )}
  </CSSMotion>
);
import { CSSMotionList } from '@rc-component/motion';

export default ({ keys }: { keys: string[] }) => (
  <CSSMotionList keys={keys} motionName="fade">
    {({ key, className, style }, ref) => (
      <div ref={ref} key={key} className={className} style={style}>
        {key}
      </div>
    )}
  </CSSMotionList>
);

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

CSSMotion

PropertyTypeDefaultDescription
children(props, ref) => ReactElement-Render function that receives motion class, style, and ref.
forceRenderbooleanfalseKeep the element rendered even when invisible.
leavedClassNamestring-Class name applied after leave when the element remains.
motionAppearbooleantrueEnable appear motion.
motionDeadlinenumber-Fallback timeout in milliseconds for motion completion.
motionEnterbooleantrueEnable enter motion.
motionLeavebooleantrueEnable leave motion.
motionLeaveImmediatelyboolean-Trigger leave immediately after mount.
motionNamestring | MotionName-CSS class name prefix or per-phase class names.
removeOnLeavebooleantrueRemove the element after leave. Ignored when forceRender is set.
visiblebooleantrueControls whether the element is visible.
onAppearActiveMotionEventHandler-Triggered during appear active phase.
onAppearEndMotionEndEventHandler-Triggered when appear finishes. Return false to keep waiting.
onAppearPrepareMotionPrepareEventHandler-Prepare callback before appear starts.
onAppearStartMotionEventHandler-Triggered when appear starts.
onEnterActiveMotionEventHandler-Triggered during enter active phase.
onEnterEndMotionEndEventHandler-Triggered when enter finishes. Return false to keep waiting.
onEnterPrepareMotionPrepareEventHandler-Prepare callback before enter starts.
onEnterStartMotionEventHandler-Triggered when enter starts.
onLeaveActiveMotionEventHandler-Triggered during leave active phase.
onLeaveEndMotionEndEventHandler-Triggered when leave finishes. Return false to keep waiting.
onLeavePrepareMotionPrepareEventHandler-Prepare callback before leave starts.
onLeaveStartMotionEventHandler-Triggered when leave starts.
onVisibleChanged(visible: boolean) => void-Triggered after the final visible state changes.

CSSMotionList

CSSMotionList accepts the motion props above, except children is a list render function.

PropertyTypeDefaultDescription
children(props, ref) => ReactElement-Render function for each keyed item.
componentstring | ComponentType | falsedivWrapper component. Use false for no wrapper.
keys(React.Key | { key: React.Key })[]-Keys to animate.
onAllRemoved() => void-Triggered after every leaving item is removed.
onVisibleChanged(visible, info: { key: React.Key }) => void-Triggered after an item visibility changes.

Ref

Ref methodTypeDescription
enableMotion() => booleanWhether motion is currently enabled.
inMotion() => booleanWhether the element is in a motion lifecycle.
nativeElementHTMLElementCurrent DOM element.

Development

npm install
npm start
npm test
npm run tsc
npm run compile
npm run build

The dumi site runs at http://localhost:8000 by default.

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

License

@rc-component/motion is released under the MIT license.

antd
ant-design
javascript
react
react-component

Project health

Overall

4.7/10

Maintained

1/10

Code review

2/10
OpenSSF Scorecard

Latest release

1.3.3 · Jun 6, 2026

Releases this year

2

Significant stargazers

白雾三语

823 followers · starred May 2026

贺喜

51 followers · starred May 2025

XMH

91 followers · starred Mar 2025