UNPKG

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