2022-06-05 18:56:42 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Transition } from '@headlessui/react';
|
|
|
|
|
|
|
|
type Duration = `duration-${number}`;
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
as?: React.ElementType;
|
2022-06-26 19:13:52 +00:00
|
|
|
duration?: Duration | [Duration, Duration];
|
2022-06-05 18:56:42 +00:00
|
|
|
show: boolean;
|
|
|
|
children: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ({ 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>
|
|
|
|
);
|
|
|
|
};
|