DefinitelyTyped/types/react-transition-group/SwitchTransition.d.ts
Setsun cdc97f0f4e feat(react-transition-group): types for v4.2 (SwitchTransition) (#37061)
* feat(switchtransition): types for switchtransition

* fix(lint): fix linting errors

* fix(tests): add tests for switchtransition

* Update types/react-transition-group/SwitchTransition.d.ts

Co-Authored-By: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
2019-07-23 12:35:02 -07:00

52 lines
1.8 KiB
TypeScript

import { Component } from "react";
export enum modes {
out = 'out-in',
in = 'in-out'
}
declare namespace SwitchTransition {
interface SwitchTransitionProps {
/**
* Transition modes.
* `out-in`: Current element transitions out first, then when complete, the new element transitions in.
* `in-out`: New element transitions in first, then when complete, the current element transitions out.
*/
mode?: 'out-in' | 'in-out';
/**
* Any `Transition` or `CSSTransition` component
*/
children: React.ReactElement;
}
}
/**
* A transition component inspired by the [vue transition modes](https://vuejs.org/v2/guide/transitions.html#Transition-Modes).
* You can use it when you want to control the render between state transitions.
* Based on the selected mode and the child's key which is the `Transition` or `CSSTransition` component, the `SwitchTransition` makes a consistent transition between them.
*
* If the `out-in` mode is selected, the `SwitchTransition` waits until the old child leaves and then inserts a new child.
* If the `in-out` mode is selected, the `SwitchTransition` inserts a new child first, waits for the new child to enter and then removes the old child
*
* ```jsx
* function App() {
* const [state, setState] = useState(false);
* return (
* <SwitchTransition>
* <FadeTransition key={state ? "Goodbye, world!" : "Hello, world!"}
* addEndListener={(node, done) => node.addEventListener("transitionend", done, false)}
* classNames='fade' >
* <button onClick={() => setState(state => !state)}>
* {state ? "Goodbye, world!" : "Hello, world!"}
* </button>
* </FadeTransition>
* </SwitchTransition>
* )
* }
* ```
*/
declare class SwitchTransition extends Component<SwitchTransition.SwitchTransitionProps> {}
export default SwitchTransition;