2022-06-05 18:56:42 +00:00
|
|
|
import { Transition } from '@headlessui/react';
|
2022-11-25 20:25:03 +00:00
|
|
|
import type { ElementType, ReactNode } from 'react';
|
2022-06-05 18:56:42 +00:00
|
|
|
|
|
|
|
type Duration = `duration-${number}`;
|
|
|
|
|
|
|
|
interface Props {
|
2022-11-25 20:25:03 +00:00
|
|
|
as?: ElementType;
|
2022-06-26 19:13:52 +00:00
|
|
|
duration?: Duration | [Duration, Duration];
|
2022-11-25 20:25:03 +00:00
|
|
|
appear?: boolean;
|
|
|
|
unmount?: boolean;
|
2022-06-05 18:56:42 +00:00
|
|
|
show: boolean;
|
2022-11-25 20:25:03 +00:00
|
|
|
children: ReactNode;
|
2022-06-05 18:56:42 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 20:25:03 +00:00
|
|
|
function FadeTransition({ children, duration, ...props }: Props) {
|
2022-06-26 19:13:52 +00:00
|
|
|
const [enterDuration, exitDuration] = Array.isArray(duration)
|
2022-06-05 18:56:42 +00:00
|
|
|
? duration
|
2022-06-26 19:13:52 +00:00
|
|
|
: !duration
|
|
|
|
? ['duration-200', 'duration-100']
|
|
|
|
: [duration, duration];
|
2022-06-05 18:56:42 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Transition
|
|
|
|
{...props}
|
|
|
|
enter={`ease-out ${enterDuration}`}
|
|
|
|
enterFrom={'opacity-0'}
|
|
|
|
enterTo={'opacity-100'}
|
|
|
|
leave={`ease-in ${exitDuration}`}
|
|
|
|
leaveFrom={'opacity-100'}
|
|
|
|
leaveTo={'opacity-0'}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Transition>
|
|
|
|
);
|
2022-11-25 20:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default FadeTransition;
|