Transitions
이 테마 헬퍼들은 커스텀 CSS 트랜지션을 만들 수 있게 해 주고, 지속 시간(duration), 이징(easing) 등을 원하는 대로 바꿀 수 있게 해 줘요.
출처: 문서
본문
theme.transitions.create(props, options) => transition
인자
props(string | string[]): 기본값은['all']이에요. 트랜지션할 CSS 속성 하나 또는 속성 목록을 제공해요.options(object [선택]):
options.duration(string | number [선택]): 기본값은theme.transitions.duration.standard이에요. 트랜지션의 지속 시간을 제공해요.options.easing(string [선택]): 기본값은theme.transitions.easing.easeInOut이에요. 트랜지션의 이징을 제공해요.options.delay(string | number [선택]): 기본값은0이에요. 트랜지션의 지연을 제공해요.
반환값
transition: 트랜지션할 모든 CSS 속성을 정의된 duration, easing, delay와 함께 조합한 CSS 트랜지션 값이에요.
예를 들어 theme.transitions.create(['background-color', 'transform'])를 호출하면 이런 문자열이 반환돼요.
'background-color 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,transform 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms';
theme.transitions.create() 헬퍼를 사용하면 UI 요소들 사이에 일관된 트랜지션을 만들 수 있어요.
theme.transitions.create(['background-color', 'transform']);
예시
{{"demo": "TransitionHover.js", "defaultCodeOpen": false}}
theme.transitions.getAutoHeightDuration(height) => duration
인자
height(number): 컴포넌트의 높이예요.
반환값
duration: 높이를 기반으로 계산된 지속 시간이에요.
Reduced motion
v9.1.0부터 reduced-motion(움직임 최소화) 동작을 theme.motion.reducedMotion으로 구성할 수 있어요.
const theme = createTheme({
motion: {
reducedMotion: 'system',
},
});
지원되는 값은 다음과 같아요.
never(기본값): 평소처럼 트랜지션 동작을 유지해요.system: 사용자의 운영체제가prefers-reduced-motion: reduce로 요청할 때만 움직임을 줄여요.always: 운영체제 설정과 무관하게 모든 사용자에게 움직임을 줄여요.
이 설정은 Collapse, Fade, Grow, Slide, Zoom 같은 Material UI 트랜지션 컴포넌트와 Accordion, Menu, Tabs처럼 애니메이션이 있는 컴포넌트들을 제어해요.
앱의 커스텀 CSS 트랜지션에는 theme.transitions.create()를 사용하고 reduced-motion 오버라이드를 직접 추가해 주세요.
const styles = {
transition: theme.transitions.create(['background-color', 'transform']),
...(theme.motion.reducedMotion === 'always' && {
transition: 'none',
}),
...(theme.motion.reducedMotion === 'system' && {
'@media (prefers-reduced-motion: reduce)': {
transition: 'none',
},
}),
};
테마가 system 또는 always를 사용할 때 특정 트랜지션 컴포넌트만 평소처럼 움직이게 하려면, 그 트랜지션 컴포넌트에 disablePrefersReducedMotion을 설정해 주세요.
<Fade in disablePrefersReducedMotion>
<div />
</Fade>
Durations
duration 값의 일부 또는 전체를 바꾸거나, 직접 새 값을 제공할 수도 있어요(크리에이트 헬퍼에 사용하기 위해). 아래 예시는 모든 기본값(밀리초)을 보여 주는데, 실제로는 바꾸거나 추가하고 싶은 키만 제공하면 돼요.
const theme = createTheme({
transitions: {
duration: {
shortest: 150,
shorter: 200,
short: 250,
// most basic recommended timing
standard: 300,
// this is to be used in complex animations
complex: 375,
// recommended when something is entering screen
enteringScreen: 225,
// recommended when something is leaving screen
leavingScreen: 195,
},
},
});
Easings
easing 값의 일부 또는 전체를 바꾸거나, 커스텀 CSS transition-timing-function 값을 제공해서 직접 새 값을 정의할 수 있어요.
const theme = createTheme({
transitions: {
easing: {
// This is the most common easing curve.
easeInOut: 'cubic-bezier(0.4, 0, 0.2, 1)',
// Objects enter the screen at full velocity from off-screen and
// slowly decelerate to a resting point.
easeOut: 'cubic-bezier(0.0, 0, 0.2, 1)',
// Objects leave the screen at full velocity. They do not decelerate when off-screen.
easeIn: 'cubic-bezier(0.4, 0, 1, 1)',
// The sharp curve is used by objects that may return to the screen at any time.
sharp: 'cubic-bezier(0.4, 0, 0.6, 1)',
},
},
});
참고 자료
Material UI에 포함된 트랜지션 컴포넌트들을 살펴보려면 Transitions 페이지를 확인해 보세요.