0.0.3 • Published 5 months ago
@kcuf-ui/rc-transition v0.0.3
@kcuf-ui/rc-transition
A fork rewritten of https://www.npmjs.com/package/react-transition-group using TS and hooks.
It's NOT designed to be a drop-in replacement of react-transition-group, however some APIs are learned from it.
Why
react-transition-grouphas not been updated for over 2 years (version 4.4.5 till 2025/01/03)react-transition-groupis written in JSreact-transition-groupdepends onprop-typeswhich TS react coders might hatereact-transition-groupis in class component formatreact-transition-groupuses deprecated findDOMNode which can only be used in class componentreact-transition-groupcannot start its own dev environment now, a bunch of errors
How to Use
Using Render Props
import Transition from '@kcuf-ui/rc-transition';
const transitionStyles = {
entering: {
opacity: 1
},
entered: {
opacity: 1
},
exiting: {
opacity: 0
},
exited: {
opacity: 0
}
};
<Transition {...props}>
{(status: 'entering' | 'entered' | 'exiting' | 'exited') => <Child style={transitionStyles[status]} />}
</Transition>Using data-transition
import styled from 'styled-components';
import Transition from '@kcuf-ui/rc-transition';
const ScChild = styled.div`
&[data-transition='entering'] {
opacity: 1;
}
&[data-transition='entered'] {
opacity: 1;
}
&[data-transition='exiting'] {
opacity: 0;
text-decoration: line-through;
}
&[data-transition='exited'] {
opacity: 0;
}
`;
<Transition {...props}>
<ScChild />
</Transition>Using useTransitionStatus hook
import {
ReactElement
} from 'react';
import styled from 'styled-components';
import Transition, {
useTransitionStatus
} from '@kcuf-ui/rc-transition';
function Child(): ReactElement {
const transitionStatus = useTransitionStatus(); // however you would like to use it
return <div>...</div>;
}
<Transition {...props}>
<Child />
</Transition>APIs
Exports
- Removed
CSSTransition→Transition+data-transitionis enough
- Renamed
SwitchTransition→TransitionSwitchTODOReplaceTransition→TransitionReplaceTODO
TransitionProps
| prop | Description |
|---|---|
nodeRef | Needed when mountOnEnter \|\| unmountOnExit to force reflow. |
in | Same as react-transition-grpup. |
durationEnter?: number | Default 400ms |
durationExit?: number | Default to durationEnter |
onEnter() | No parameters. |
onEntered() | No parameters. |
onExit() | No parameters. |
onExited() | No parameters. |
These props are removed:
onEntering()onExiting()→ There is noappearappearnow, treated the same asenter.→enterdurationEnter: 0→exitdurationExit: 0→timeout?: number \| { apear?: number; enter?: number; exit: number; }durationEnter?: number+durationExit?: numberaddEventListener