본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Motion

원문 보기 위키 갱신

motionProps로 프리미티브 컴포넌트의 등장/퇴장(enter/leave) 애니메이션을 구성해요.

출처: 문서

본문

사용법 (Usage)

컴포넌트의 애니메이션 대상 요소에 motionProps를 전달해 enter/leave 전환을 구성해요. 접이식(collapsible) 컴포넌트는 Root에서, 팝업 컴포넌트는 Popup에서 받아요.

motionProps={{ name: 'slide', cssVarPrefix: 'content', hideStrategy: 'none' }}

동작 (Behavior)

애니메이션 단계 (Animation Phases)

모션 시스템은 전환 주기 동안 name 접두사에 기반한 여섯 개의 CSS 클래스를 적용해요.

Enter 단계, 요소가 나타날 때 적용돼요.

Class Timing
{name}-enter-from Before enter starts
{name}-enter-active During enter
{name}-enter-to After enter ends

Leave 단계, 요소가 사라질 때 적용돼요.

Class Timing
{name}-leave-from Before leave starts
{name}-leave-active During leave
{name}-leave-to After leave ends

이 클래스들을 사용해 CSS 전환이나 키프레임 애니메이션을 정의하세요.

motionProps={{ name: 'fade' }}
.fade-enter-from {
    opacity: 0;
    transform: translateY(-10px);
}
.fade-enter-active {
    transition: all 200ms ease-out;
}
.fade-enter-to {
    opacity: 1;
    transform: translateY(0);
}

.fade-leave-from {
    opacity: 1;
    transform: translateY(0);
}
.fade-leave-active {
    transition: all 200ms ease-in;
}
.fade-leave-to {
    opacity: 0;
    transform: translateY(-10px);
}

CSS 변수 접두사 (CSS Variable Prefix)

cssVarPrefix를 사용해 애니메이션 중 요소 크기 변수를 주입해요. 모션 시스템이 요소를 측정해 이런 CSS 커스텀 프로퍼티를 설정하므로, 하드코딩된 값 없이 높이/너비 기반 전환을 가능하게 해요.

Variable Description
--{prefix}-height Set to the scroll height on enter, 0px on leave
--{prefix}-width Set to the scroll width on enter, 0px on leave
motionProps={{ name: 'expand', cssVarPrefix: 'content' }}
.expand-enter-active,
.expand-leave-active {
    transition: max-height 300ms ease;
    overflow: hidden;
}

.expand-enter-to,
.expand-leave-from {
    max-height: var(--content-height);
}

.expand-enter-from,
.expand-leave-to {
    max-height: 0;
}

숨김 전략 (Hide Strategy)

hideStrategy로 leave 애니메이션 완료 후 콘텐츠를 숨기는 방법을 제어해요.

Value Behavior
'display' Applies display: none (default)
'visibility' Applies visibility: hidden and max-height: 0
'none' No automatic hiding, CSS animations handle it entirely

접이식 콘텐츠는 보통 CSS 기반 높이 전환과 함께 'none'을 사용하고, 팝업은 기본 'display' 전략이 잘 맞아요.

Headless

기본 hook API, 명령형(imperative) 메서드, 생명주기 콜백, 마운트/언마운트 제어에 대해서는 useMotion을 참고하세요.

더 알아보기 (Learn more)