UNPKG

2.87 kBTypeScriptView Raw
1import { Component, ElementType, JSX, ReactElement } from "react";
2import { TransitionActions, TransitionProps } from "./Transition";
3
4export interface IntrinsicTransitionGroupProps<T extends keyof JSX.IntrinsicElements = "div">
5 extends TransitionActions
6{
7 component?: T | null | undefined;
8}
9
10export interface ComponentTransitionGroupProps<T extends ElementType> extends TransitionActions {
11 component: T;
12}
13
14export type TransitionGroupProps<T extends keyof JSX.IntrinsicElements = "div", V extends ElementType = any> =
15 | (IntrinsicTransitionGroupProps<T> & JSX.IntrinsicElements[T])
16 | (ComponentTransitionGroupProps<V>) & {
17 children?: ReactElement<TransitionProps<any>> | Array<ReactElement<TransitionProps<any>>> | undefined;
18 childFactory?(child: ReactElement): ReactElement;
19 [prop: string]: any;
20 };
21
22/**
23 * The `<TransitionGroup>` component manages a set of `<Transition>` components
24 * in a list. Like with the `<Transition>` component, `<TransitionGroup>`, is a
25 * state machine for managing the mounting and unmounting of components over
26 * time.
27 *
28 * Consider the example below using the `Fade` CSS transition from before.
29 * As items are removed or added to the TodoList the `in` prop is toggled
30 * automatically by the `<TransitionGroup>`. You can use _any_ `<Transition>`
31 * component in a `<TransitionGroup>`, not just css.
32 *
33 * ```jsx
34 * import TransitionGroup from 'react-transition-group/TransitionGroup';
35 *
36 * class TodoList extends React.Component {
37 * constructor(props) {
38 * super(props)
39 * this.state = {items: ['hello', 'world', 'click', 'me']}
40 * }
41 * handleAdd() {
42 * const newItems = this.state.items.concat([
43 * prompt('Enter some text')
44 * ]);
45 * this.setState({ items: newItems });
46 * }
47 * handleRemove(i) {
48 * let newItems = this.state.items.slice();
49 * newItems.splice(i, 1);
50 * this.setState({items: newItems});
51 * }
52 * render() {
53 * return (
54 * <div>
55 * <button onClick={() => this.handleAdd()}>Add Item</button>
56 * <TransitionGroup>
57 * {this.state.items.map((item, i) => (
58 * <FadeTransition key={item}>
59 * <div>
60 * {item}{' '}
61 * <button onClick={() => this.handleRemove(i)}>
62 * remove
63 * </button>
64 * </div>
65 * </FadeTransition>
66 * ))}
67 * </TransitionGroup>
68 * </div>
69 * );
70 * }
71 * }
72 * ```
73 *
74 * Note that `<TransitionGroup>` does not define any animation behavior!
75 * Exactly _how_ a list item animates is up to the individual `<Transition>`
76 * components. This means you can mix and match animations across different
77 * list items.
78 */
79declare class TransitionGroup extends Component<TransitionGroupProps> {}
80
81export default TransitionGroup;