Motion
모션 프로필
stable모든 모션 훅의 기본값을 한 곳에서 관리하는 테마 시스템
@hua-labs/motion-corev2.0.0
Import
import {
MotionProfileProvider,
useMotionProfile,
resolveProfile,
mergeProfileOverrides,
neutral,
hua,
} from '@hua-labs/motion-core'MotionProfile 타입
interface MotionProfile {
name: string
base: MotionProfileBase
entrance: MotionProfileEntrance
stagger: MotionProfileStagger
interaction: MotionProfileInteraction
spring: MotionProfileSpring
reducedMotion: ReducedMotionStrategy
}
interface MotionProfileBase {
duration: number // 기본 지속 시간 (ms)
easing: string // 기본 CSS 이징
threshold: number // IntersectionObserver 임계값
triggerOnce: boolean // 한 번만 트리거
}
interface MotionProfileEntrance {
slide: { distance: number; easing: string }
fade: { initialOpacity: number }
scale: { from: number }
bounce: { intensity: number; easing: string }
}
interface MotionProfileStagger {
perItem: number // 아이템 간 딜레이 (ms)
baseDelay: number // 첫 아이템 전 딜레이 (ms)
}
interface MotionProfileInteraction {
hover: {
scale: number
y: number
duration: number
easing: string
}
}
interface MotionProfileSpring {
mass: number
stiffness: number
damping: number
restDelta: number
restSpeed: number
}
type ReducedMotionStrategy = 'skip' | 'fade-only' | 'minimal'내장 프로필
neutral
기본 프로필. 차분하고 안정적인 모션을 적용한다. MotionProfileProvider 없이도 이 프로필이 기본으로 동작한다.
import { neutral } from '@hua-labs/motion-core'hua
HUA 브랜드 특성이 반영된 프로필. neutral보다 약간 더 활기찬 모션을 제공한다.
import { hua } from '@hua-labs/motion-core'MotionProfileProvider
하위 트리의 모든 모션 훅에 프로필을 적용하는 Context Provider다.
Signature
function MotionProfileProvider(props: MotionProfileProviderProps): JSX.Element
interface MotionProfileProviderProps {
profile?: BuiltInProfileName | MotionProfile // 기본값: 'neutral'
overrides?: DeepPartial<MotionProfile> // 프로필 부분 오버라이드
children: React.ReactNode
}
type BuiltInProfileName = 'neutral' | 'hua'Parameters
| 파라미터 | 타입 | 기본값 | 설명 | |
|---|---|---|---|---|
profile | `BuiltInProfileName \ | MotionProfile` | 'neutral' | 사용할 프로필 |
overrides | DeepPartial<MotionProfile> | — | 특정 값만 오버라이드 |
Usage — 내장 프로필 사용
import { MotionProfileProvider } from '@hua-labs/motion-core'
function App() {
return (
<MotionProfileProvider profile="hua">
<MyPage />
</MotionProfileProvider>
)
}Usage — 부분 오버라이드
import { MotionProfileProvider } from '@hua-labs/motion-core'
function App() {
return (
<MotionProfileProvider
profile="neutral"
overrides={{
base: { duration: 400, triggerOnce: false },
entrance: { slide: { distance: 30 } }
}}
>
<MyPage />
</MotionProfileProvider>
)
}Usage — 커스텀 프로필 객체
import { MotionProfileProvider, neutral } from '@hua-labs/motion-core'
const myProfile = {
...neutral,
name: 'my-brand',
base: { ...neutral.base, duration: 500 },
interaction: {
hover: { scale: 1.08, y: -6, duration: 150, easing: 'ease-out' }
}
}
function App() {
return (
<MotionProfileProvider profile={myProfile}>
<MyPage />
</MotionProfileProvider>
)
}useMotionProfile()
현재 활성화된 MotionProfile을 반환한다. 훅 내부에서 기본값을 참조할 때 사용한다. Provider 외부에서 호출하면 neutral 프로필을 반환한다.
Signature
function useMotionProfile(): MotionProfileUsage
import { useMotionProfile } from '@hua-labs/motion-core'
function CustomMotion() {
const profile = useMotionProfile()
const style = {
transition: `all ${profile.base.duration}ms ${profile.base.easing}`
}
return <div style={style}>커스텀 모션</div>
}resolveProfile()
이름 또는 객체에서 MotionProfile을 resolve한다.
Signature
function resolveProfile(
profile: BuiltInProfileName | MotionProfile
): MotionProfileUsage
import { resolveProfile } from '@hua-labs/motion-core'
const profile = resolveProfile('hua')
const sameProfile = resolveProfile(customProfileObject)mergeProfileOverrides()
기준 프로필에 부분 오버라이드를 깊은 병합(deep merge)으로 적용한다.
Signature
function mergeProfileOverrides(
base: MotionProfile,
overrides: DeepPartial<MotionProfile>
): MotionProfile
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]
}Usage
import { mergeProfileOverrides, neutral } from '@hua-labs/motion-core'
const customProfile = mergeProfileOverrides(neutral, {
base: { duration: 300 },
spring: { stiffness: 200 }
})Notes
MotionProfileProvider는 중첩 사용이 가능하다. 가장 가까운 Provider의 프로필이 적용된다.- 배열 값은 deep merge에서 교체(replace)된다. 병합되지 않는다.
reducedMotion: 'skip'이면 모션을 완전히 건너뛰고 즉시 최종 상태를 표시한다.