Rewrite styles to scss and use i respective components
This commit is contained in:
27
src/components/Fadeable/Fadeable.tsx
Normal file
27
src/components/Fadeable/Fadeable.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import './fadeable.scss';
|
||||
type FadeableProps = {
|
||||
leaving: boolean;
|
||||
onLeave: () => void;
|
||||
};
|
||||
|
||||
export default function Fadeable({ leaving, onLeave, children }: React.PropsWithChildren<FadeableProps>) {
|
||||
const [faded, setFaded] = useState(leaving);
|
||||
|
||||
useEffect(() => {
|
||||
setFaded(leaving);
|
||||
}, [leaving]);
|
||||
|
||||
const handleTransitionEnd = () => {
|
||||
if (faded) {
|
||||
onLeave();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={classNames('fadable', { 'is-faded': faded })} onTransitionEnd={handleTransitionEnd}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
8
src/components/Fadeable/fadeable.scss
Normal file
8
src/components/Fadeable/fadeable.scss
Normal file
@@ -0,0 +1,8 @@
|
||||
.fadable {
|
||||
opacity: 1;
|
||||
transition: opacity 0.2s cubic-bezier(0.54, 0, 0.28, 1);
|
||||
|
||||
&.is-faded {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user