1 | import { Component, ReactNode } from 'react';
|
2 |
|
3 | type RefHandler<
|
4 | RefElement extends undefined | HTMLElement,
|
5 | ImplicitRefHandler extends (node: HTMLElement, ...args: any[]) => void,
|
6 | ExplicitRefHandler extends (...args: any[]) => void,
|
7 | > = {
|
8 | implicit: ImplicitRefHandler;
|
9 | explicit: ExplicitRefHandler;
|
10 | }[RefElement extends undefined ? 'implicit' : 'explicit'];
|
11 |
|
12 | export type EndHandler<RefElement extends undefined | HTMLElement> = RefHandler<
|
13 | RefElement,
|
14 | (node: HTMLElement, done: () => void) => void,
|
15 | (done: () => void) => void
|
16 | >;
|
17 |
|
18 | export type EnterHandler<RefElement extends undefined | HTMLElement> = RefHandler<
|
19 | RefElement,
|
20 | (node: HTMLElement, isAppearing: boolean) => void,
|
21 | (isAppearing: boolean) => void
|
22 | >;
|
23 |
|
24 | export type ExitHandler<E extends undefined | HTMLElement> = RefHandler<E, (node: HTMLElement) => void, () => void>;
|
25 |
|
26 | export const UNMOUNTED = 'unmounted';
|
27 | export const EXITED = 'exited';
|
28 | export const ENTERING = 'entering';
|
29 | export const ENTERED = 'entered';
|
30 | export const EXITING = 'exiting';
|
31 |
|
32 | export interface TransitionActions {
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | appear?: boolean | undefined;
|
41 |
|
42 | |
43 |
|
44 |
|
45 | enter?: boolean | undefined;
|
46 |
|
47 | |
48 |
|
49 |
|
50 | exit?: boolean | undefined;
|
51 | }
|
52 |
|
53 | interface BaseTransitionProps<RefElement extends undefined | HTMLElement> {
|
54 | |
55 |
|
56 |
|
57 | in?: boolean | undefined;
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | mountOnEnter?: boolean | undefined;
|
67 |
|
68 | |
69 |
|
70 |
|
71 |
|
72 |
|
73 | unmountOnExit?: boolean | undefined;
|
74 |
|
75 | |
76 |
|
77 |
|
78 |
|
79 |
|
80 | onEnter?: EnterHandler<RefElement> | undefined;
|
81 |
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 | onEntering?: EnterHandler<RefElement> | undefined;
|
88 |
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 | onEntered?: EnterHandler<RefElement> | undefined;
|
95 |
|
96 | |
97 |
|
98 |
|
99 | onExit?: ExitHandler<RefElement> | undefined;
|
100 |
|
101 | |
102 |
|
103 |
|
104 | onExiting?: ExitHandler<RefElement> | undefined;
|
105 |
|
106 | |
107 |
|
108 |
|
109 | onExited?: ExitHandler<RefElement> | undefined;
|
110 |
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | children?: TransitionChildren | undefined;
|
125 |
|
126 | |
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | nodeRef?: React.Ref<RefElement> | undefined;
|
133 |
|
134 | [prop: string]: any;
|
135 | }
|
136 |
|
137 | export type TransitionStatus = typeof ENTERING | typeof ENTERED | typeof EXITING | typeof EXITED | typeof UNMOUNTED;
|
138 | export type TransitionChildren =
|
139 | | ReactNode
|
140 | | ((status: TransitionStatus, childProps?: Record<string, unknown>) => ReactNode);
|
141 |
|
142 | export interface TimeoutProps<RefElement extends undefined | HTMLElement> extends BaseTransitionProps<RefElement> {
|
143 | /**
|
144 | * The duration of the transition, in milliseconds. Required unless addEndListener is provided.
|
145 | *
|
146 | * You may specify a single timeout for all transitions:
|
147 | * ```js
|
148 | * timeout={500}
|
149 | * ```
|
150 | * or individually:
|
151 | * ```js
|
152 | * timeout={{
|
153 | * appear: 500,
|
154 | * enter: 300,
|
155 | * exit: 500,
|
156 | * }}
|
157 | * ```
|
158 | * - appear defaults to the value of `enter`
|
159 | * - enter defaults to `0`
|
160 | * - exit defaults to `0`
|
161 | */
|
162 | timeout: number | { appear?: number | undefined; enter?: number | undefined; exit?: number | undefined };
|
163 |
|
164 | /**
|
165 | * Add a custom transition end trigger. Called with the transitioning DOM
|
166 | * node and a done callback. Allows for more fine grained transition end
|
167 | * logic. Note: Timeouts are still used as a fallback if provided.
|
168 | */
|
169 | addEndListener?: EndHandler<RefElement> | undefined;
|
170 | }
|
171 |
|
172 | export interface EndListenerProps<Ref extends undefined | HTMLElement> extends BaseTransitionProps<Ref> {
|
173 | /**
|
174 | * The duration of the transition, in milliseconds. Required unless addEndListener is provided.
|
175 | *
|
176 | * You may specify a single timeout for all transitions:
|
177 | * ```js
|
178 | * timeout={500}
|
179 | * ```
|
180 | * or individually:
|
181 | * ```js
|
182 | * timeout={{
|
183 | * appear: 500,
|
184 | * enter: 300,
|
185 | * exit: 500,
|
186 | * }}
|
187 | * ```
|
188 | * - appear defaults to the value of `enter`
|
189 | * - enter defaults to `0`
|
190 | * - exit defaults to `0`
|
191 | */
|
192 | timeout?:
|
193 | | number
|
194 | | { appear?: number | undefined; enter?: number | undefined; exit?: number | undefined }
|
195 | | undefined;
|
196 | /**
|
197 | * Add a custom transition end trigger. Called with the transitioning DOM
|
198 | * node and a done callback. Allows for more fine grained transition end
|
199 | * logic. Note: Timeouts are still used as a fallback if provided.
|
200 | */
|
201 | addEndListener: EndHandler<Ref>;
|
202 | }
|
203 |
|
204 | export type TransitionProps<RefElement extends undefined | HTMLElement = undefined> =
|
205 | | TimeoutProps<RefElement>
|
206 | | EndListenerProps<RefElement>;
|
207 |
|
208 | /**
|
209 | * The Transition component lets you describe a transition from one component
|
210 | * state to another _over time_ with a simple declarative API. Most commonly
|
211 | * It's used to animate the mounting and unmounting of Component, but can also
|
212 | * be used to describe in-place transition states as well.
|
213 | *
|
214 | * By default the `Transition` component does not alter the behavior of the
|
215 | * component it renders, it only tracks "enter" and "exit" states for the components.
|
216 | * It's up to you to give meaning and effect to those states. For example we can
|
217 | * add styles to a component when it enters or exits:
|
218 | *
|
219 | * ```jsx
|
220 | * import Transition from 'react-transition-group/Transition';
|
221 | *
|
222 | * const duration = 300;
|
223 | *
|
224 | * const defaultStyle = {
|
225 | * transition: `opacity ${duration}ms ease-in-out`,
|
226 | * opacity: 0,
|
227 | * }
|
228 | *
|
229 | * const transitionStyles = {
|
230 | * entering: { opacity: 1 },
|
231 | * entered: { opacity: 1 },
|
232 | * };
|
233 | *
|
234 | * const Fade = ({ in: inProp }) => (
|
235 | * <Transition in={inProp} timeout={duration}>
|
236 | * {(state) => (
|
237 | * <div style={{
|
238 | * ...defaultStyle,
|
239 | * ...transitionStyles[state]
|
240 | * }}>
|
241 | * I'm A fade Transition!
|
242 | * </div>
|
243 | * )}
|
244 | * </Transition>
|
245 | * );
|
246 | * ```
|
247 | *
|
248 | */
|
249 | declare class Transition<RefElement extends HTMLElement | undefined> extends Component<TransitionProps<RefElement>> {}
|
250 |
|
251 | export default Transition;
|
252 |
|
\ | No newline at end of file |