import * as React from 'react'; import Transition from '../Transition'; import Flex from '../../flex/Flex'; import Button from '../../buttons/Button'; import Icon from '../../icons/Icon'; import DummyBox from './common/DummyBox'; import Stage from './common/Stage'; const colorsOrder = ['red', 'yellow', 'blue'] as const; const createSlideInEffect = (direction: 'left' | 'right') => ({ initial: { transform: { translateX: direction === 'left' ? 'm' : '-m', }, opacity: 0, }, animate: { transform: { translateX: 0, }, opacity: 1, duration: 'moderate1', easing: 'entry', }, }); /** * An effect with only the "animate" phase always * performs a transition from the current position. */ const createSlideOutEffect = (direction: 'left' | 'right') => ({ animate: { transform: { translateX: direction === 'left' ? '-m' : 'm', }, opacity: 0, duration: 'moderate1', easing: 'exit', }, }); export const SharedAxis = () => { const [effect, setEffect] = React.useState(null); const [currentViewIndex, setCurrentViewIndex] = React.useState(0); const nextTransitionCallback = React.useRef<() => void>(); const changeView = (viewIndex: number) => { if (viewIndex !== currentViewIndex) { const direction = currentViewIndex < viewIndex ? 'left' : 'right'; // hide previous view // @ts-ignore TS2345 setEffect(createSlideOutEffect(direction)); // show the next view nextTransitionCallback.current = () => { setCurrentViewIndex(viewIndex); // @ts-ignore TS2345 setEffect(createSlideInEffect(direction)); // @ts-ignore TS2322 nextTransitionCallback.current = null; }; } }; const handleTransitionEnd = () => { if (nextTransitionCallback.current) { nextTransitionCallback.current(); } }; return ( {colorsOrder.map((color, index) => (