misc_pterodactyl-panel/resources/scripts/components/elements/transitions/FadeTransition.tsx

38 lines
959 B
TypeScript
Raw Normal View History

import { Transition } from '@headlessui/react';
2022-11-25 20:25:03 +00:00
import type { ElementType, ReactNode } from 'react';
type Duration = `duration-${number}`;
interface Props {
2022-11-25 20:25:03 +00:00
as?: ElementType;
duration?: Duration | [Duration, Duration];
2022-11-25 20:25:03 +00:00
appear?: boolean;
unmount?: boolean;
show: boolean;
2022-11-25 20:25:03 +00:00
children: ReactNode;
}
2022-11-25 20:25:03 +00:00
function FadeTransition({ children, duration, ...props }: Props) {
const [enterDuration, exitDuration] = Array.isArray(duration)
? duration
: !duration
? ['duration-200', 'duration-100']
: [duration, duration];
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;