Motion

Motion is a convenient component that extends the Yamada UI Style Props to Motion.

Usage

import { Motion } from "@yamada-ui/react"
  • initial: The initial state of the component.
  • animate: The animation executed when the component is mounted or updated.
  • exit: The animation executed when the component is unmounted.
  • transition: The object that sets the duration and delay.

Variants

Variants are useful for implementing dynamic animations. You can also orchestrate animations.

Look at me!

Use AnimatePresence

In React, when a component is unmounted, the animation is not maintained. By using AnimatePresence, the component is not unmounted until the animation ends.

Keyframes

By setting the value to an array, you can set the keyframes. Each frame is processed at equal intervals. You can override this by setting an array of intervals to transition's times.

Gestures

Hover・Click/Tap・Focus to detect and execute animations.

Hover

  • whileHover: The animation executed when the pointer is moved over the component.
  • onHoverStart: The callback function executed when the pointer is moved over the component.
  • onHoverEnd: The callback function executed when the pointer is moved away from the component.
Hover me!

Click/Tap

  • whileTap: The animation executed when the pointer is clicked or tapped on the component.
  • onTapStart: The callback function executed when the pointer starts pressing the component.
  • onTap: The callback function executed when the pointer is released inside the component.
  • onTapCancel: The callback function executed when the pointer is released outside the component.
Click and Tap me!

Focus

  • whileFocus: The animation executed when the component is focused.
Focus me!

Drag

To enable the dragging of the component, set drag to true. Or set "x" or "y" to follow only the x-axis or y-axis.

  • whileDrag: The animation executed when the component is dragged.
  • onDrag: The callback function executed when the component is dragged.
  • onDragStart: The callback function executed when the component starts dragging.
  • onDragEnd: The callback function executed when the component ends dragging.
Drag me!
Only X
Only Y

Limit the possible area

To limit the possible area, set the value (pixels) to top・bottom・left・right of dragConstraints.

Only Right & Bottom

Or, you can limit the possible area by setting ref.

Drag me!

Set elasticity

To set elasticity, set the object with the value (pixels) set to top・bottom・left・right of dragElastic to true or a number.

Drag me!

Set momentum

To set momentum, set the boolean value to dragMomentum.

Drag me!

Limit the direction

To limit the direction, set dragDirectionLock to true.

Drag me!

Scroll

  • whileInView: The animation executed when the component is in the viewport.
  • viewport: The object that sets the detection method of the viewport.
    • once: If true, the animation is executed when the component enters the viewport for the first time.
    • root: If you set the scrollable element (ref), the element is used as the viewport instead of window.
    • margin: The margin to add to the viewport.
    • amount: "some"・"all"・number to set the height of the element that needs to intersect with the viewport.
  • onViewportEnter: The callback function executed when the component enters the viewport.
  • onViewportLeave: The callback function executed when the component leaves the viewport.

Scroll me!

You found me!
Once me!

Configuration

To set the common settings for Motion throughout the project, use MotionConfig.

import { MotionConfig } from "motion/react"
import { UIProvider } from "@yamada-ui/react"

const App = () => {
  return (
    <MotionConfig transition={{ duration: 1 }}>
      <UIProvider>
        <YourApplication />
      </UIProvider>
    </MotionConfig>
  )
}