UNPKG

10.5 kBTypeScriptView Raw
1import React, { type ReactElement } from 'react';
2import type { CommonProps } from '../util';
3export interface AnimateChildProps {
4 names?: {
5 appear: string | undefined;
6 appearActive: string;
7 enter: string;
8 enterActive: string;
9 leave: string;
10 leaveActive: string;
11 };
12 onAppear?: (node: HTMLElement) => void;
13 onAppeared?: (node: HTMLElement) => void;
14 onAppearing?: (node: HTMLElement) => void;
15 onEnter?: (node: HTMLElement) => void;
16 onEntering?: (node: HTMLElement) => void;
17 onEntered?: (node: HTMLElement) => void;
18 onExit?: (node: HTMLElement) => void;
19 onExiting?: (node: HTMLElement) => void;
20 onExited?: (node: HTMLElement) => void;
21}
22/**
23 * @api Animate
24 */
25export interface AnimateProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
26 /**
27 * 动画 className
28 * @en The animation className
29 */
30 animation?: string | Partial<Record<'appear' | 'enter' | 'leave', string>>;
31 /**
32 * 子元素第一次挂载时是否执行动画
33 * @en Whether to execute animation on the first mount
34 * @defaultValue true
35 */
36 animationAppear?: boolean;
37 /**
38 * 包裹子元素的标签
39 * @en The tag of the wrapper
40 * @defaultValue 'div'
41 */
42 component?: React.ElementType;
43 /**
44 * 是否只有单个子元素,如果有多个子元素,请设置为 false
45 * @en Whether to only have a single child
46 * @defaultValue true
47 */
48 singleMode?: boolean;
49 /**
50 * 执行第一次挂载动画前触发的回调函数
51 * @en Callback fired before the "entering" status of the first mount is applied
52 */
53 beforeAppear?: (node: HTMLElement) => void;
54 /**
55 * 执行第一次挂载动画,添加 xxx-appear-active 类名后触发的回调函数
56 * @en Callback fired after the "entering" status of the first mount is applied
57 */
58 onAppear?: (node: HTMLElement) => void;
59 /**
60 * 执行完第一次挂载动画后触发的函数
61 * @en Callback fired after the "entered" status of the first mount is applied
62 */
63 afterAppear?: (node: HTMLElement) => void;
64 /**
65 * 执行进场动画前触发的回调函数
66 * @en Callback fired before the "entering" status is applied
67 */
68 beforeEnter?: (node: HTMLElement) => void;
69 /**
70 * 执行进场动画,添加 xxx-enter-active 类名后触发的回调函数
71 * @en Callback fired after the "entering" status is applied
72 */
73 onEnter?: (node: HTMLElement) => void;
74 /**
75 * 执行完进场动画后触发的回调函数
76 * @en Callback fired after the "entered" status is applied
77 */
78 afterEnter?: (node: HTMLElement) => void;
79 /**
80 * 执行离场动画前触发的回调函数
81 * @en Callback fired before the "exiting" status is applied
82 */
83 beforeLeave?: (node: HTMLElement) => void;
84 /**
85 * 执行离场动画,添加 xxx-leave-active 类名后触发的回调函数
86 * @en Callback fired after the leave stage
87 */
88 onLeave?: (node: HTMLElement) => void;
89 /**
90 * 执行完离场动画后触发的回调函数
91 * @en Callback fired after the leave stage
92 */
93 afterLeave?: (node: HTMLElement) => void;
94}
95/**
96 * @api Animate.Expand
97 */
98export interface ExpandProps extends Omit<AnimateProps, 'animation' | 'beforeEnter' | 'onEnter' | 'afterEnter' | 'beforeLeave' | 'onLeave' | 'afterLeave'> {
99 /**
100 * 动画 className
101 * @en The animation className
102 */
103 animation?: string | Partial<Record<'appear' | 'enter' | 'leave', string>>;
104 /**
105 * 执行进场动画前触发的回调函数
106 * @en Callback fired before the "entering" status is applied
107 */
108 beforeEnter?: (node: HTMLElement) => void;
109 /**
110 * 执行进场动画,添加 xxx-enter-active 类名后触发的回调函数
111 * @en Callback fired after the "entering" status is applied
112 */
113 onEnter?: (node: HTMLElement) => void;
114 /**
115 * 执行完进场动画后触发的回调函数
116 * @en Callback fired after the "entered" status is applied
117 */
118 afterEnter?: (node: HTMLElement) => void;
119 /**
120 * 执行离场动画前触发的回调函数
121 * @en Callback fired before the "exiting" status is applied
122 */
123 beforeLeave?: (node: HTMLElement) => void;
124 /**
125 * 执行离场动画,添加 xxx-leave-active 类名后触发的回调函数
126 * @en Callback fired after the "exiting" status is applied
127 */
128 onLeave?: (node: HTMLElement) => void;
129 /**
130 * 执行完离场动画后触发的回调函数
131 * @en Callback fired after the "exited" status is applied
132 */
133 afterLeave?: (node: HTMLElement) => void;
134}
135/**
136 * @api Animate.OverlayAnimate
137 */
138export interface OverlayAnimateProps {
139 /**
140 * 动画 className
141 * @en The animation className
142 */
143 animation?: string | false | Record<'in' | 'out', string>;
144 /**
145 * 是否显示
146 * @en Show the component; triggers the enter or exit states
147 */
148 visible?: boolean;
149 /**
150 * 子元素
151 * @en The element to be wrapped
152 */
153 children: ReactElement;
154 /**
155 * 过渡的超时时间。
156 * @en The duration of the transition.
157 * @example
158 * 你可以为所有的过渡指定一个超时时间:
159 * ```js
160 * timeout={500}
161 * ```
162 * 或者分别设置
163 * ```js
164 * timeout={{
165 * appear: 500,
166 * enter: 300,
167 * exit: 500,
168 * }}
169 * ```
170 * appear 默认值为 `enter` 的值
171 * enter 默认值为 `0`
172 * exit 默认值为 `0`
173 * -
174 * You may specify a single timeout for all transitions:
175 * ```js
176 * timeout={500}
177 * ```
178 * or individually:
179 * ```js
180 * timeout={{
181 * appear: 500,
182 * enter: 300,
183 * exit: 500,
184 * }}
185 * ```
186 * appear defaults to the value of `enter`
187 * enter defaults to `0`
188 * exit defaults to `0`
189 */
190 timeout?: number | {
191 appear?: number | undefined;
192 enter?: number | undefined;
193 exit?: number | undefined;
194 };
195 /**
196 * 子元素样式
197 * @en The style of the child element
198 */
199 style?: React.CSSProperties;
200 /**
201 * 在第一次 `in={true}` 时“惰性”挂载组件
202 * @en "lazy mount" the component on the first `in={true}`
203 * @remarks
204 * 默认情况下,子元素会在 OverlayAnimate 组件挂载时立即挂载。如果您想在第一次 `in={true}` 时“惰性”挂载组件,
205 * 可以设置 `mountOnEnter`。在第一次进入后 OverlayAnimate 组件将保持挂载,即使在“退出”状态下也是如此,除非您也指定了 `unmountOnExit`。
206 * -
207 * By default the child component is mounted immediately along with the
208 * parent OverlayAnimate component. If you want to "lazy mount" the component on
209 * the first `in={true}` you can set `mountOnEnter`. After the first enter
210 * OverlayAnimate the component will stay mounted, even on "exited", unless you
211 * also specify `unmountOnExit`.
212 * @defaultValue false
213 */
214 mountOnEnter?: boolean;
215 /**
216 * 在第一次 `in={false}` 时“惰性”卸载组件
217 * @en "lazy unmount" the component on the first `in={false}`
218 * @remarks
219 * 默认情况下,子元素会在 OverlayAnimate 组件离开时立即卸载。如果您想在第一次 `in={false}` 时“惰性”卸载组件,
220 * 可以设置 `unmountOnExit`。在第一次离开后 OverlayAnimate 组件将保持卸载,即使在“进入”状态下也是如此,除非您也指定了 `mountOnEnter`。
221 * -
222 * By default the child component stays mounted after it reaches the
223 * 'exited' state. Set `unmountOnExit` if you'd prefer to unmount the
224 * component after it finishes exiting.
225 * @defaultValue false
226 */
227 unmountOnExit?: boolean;
228 /**
229 * 在“进入”状态被应用前触发的回调。
230 * @en Callback fired before the "entering" status is applied.
231 * @param isAppearing - 是否在初次挂载 - isAppearing
232 */
233 onEnter?: (node: HTMLElement, isAppearing: boolean) => void;
234 /**
235 * 在“进入”状态被应用后触发的回调。
236 * @en Callback fired after the "entering" status is applied.
237 * @param isAppearing - 是否在初次挂载 - isAppearing
238 */
239 onEntering?: (node: HTMLElement, isAppearing: boolean) => void;
240 /**
241 * 在“已进入”状态被应用后触发的回调。
242 * @en Callback fired after the "entered" status is applied.
243 * @param isAppearing - 是否在初次挂载 - isAppearing
244 */
245 onEntered?: (node: HTMLElement, isAppearing: boolean) => void;
246 /**
247 * 在“离开”状态被应用前触发的回调。
248 * @en Callback fired before the "exiting" status is applied.
249 */
250 onExit?: (node: HTMLElement) => void;
251 /**
252 * 在“离开”状态被应用后触发的回调。
253 * @en Callback fired after the "exiting" status is applied.
254 */
255 onExiting?: (node: HTMLElement) => void;
256 /**
257 * 在“已离开”状态被应用后触发的回调。
258 * @en Callback fired after the "exited" status is applied.
259 */
260 onExited?: (node: HTMLElement) => void;
261 /**
262 * 初次挂载时实现过渡效果
263 * @en transition on the first mount.
264 * @remarks
265 * 正常情况下,如果组件在<OverlayAnimate>组件挂载时就已经显示,那么它不会进行过渡效果。
266 * 如果你想在初次挂载时实现过渡效果,请将 appear 属性设置为 true,这样当<OverlayAnimate>挂载时,组件会立即开始过渡过程。
267 * 请注意,并没有专门的“出现”状态。“出现”属性仅会在初始挂载时增加一次进入过渡效果。
268 * -
269 * Normally a component is not transitioned if it is shown when the
270 * `<OverlayAnimate>` component mounts. If you want to transition on the first
271 * mount set appear to true, and the component will transition in as soon
272 * as the `<OverlayAnimate>` mounts. Note: there are no specific "appear" states.
273 * appear only adds an additional enter transition.
274 */
275 appear?: boolean;
276 /**
277 * 启用或禁用进场动画
278 * @en Enable or disable enter transitions.
279 */
280 enter?: boolean;
281 /**
282 * 启用或禁用离场动画
283 * @en Enable or disable exit transitions.
284 */
285 exit?: boolean;
286}