@cleartrip/ct-design-transition 4.0.0-TEST.3 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/type.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TransitionProps as _TransitionProps, TransitionActions } from 'react-transition-group/Transition';
2
2
  import * as React from 'react';
3
- import { CSSProperties } from 'styled-components';
3
+ import { CSSProperties } from 'react';
4
4
  export type TransitionHandlerKeys = 'onEnter' | 'onEntering' | 'onEntered' | 'onExit' | 'onExiting' | 'onExited';
5
5
  export type TransitionHandlerProps = Pick<_TransitionProps, TransitionHandlerKeys>;
6
6
  export type Direction = 'left' | 'right' | 'up' | 'down';
@@ -15,21 +15,21 @@ export interface TransitionProps extends TransitionActions, Partial<Pick<_Transi
15
15
  }
16
16
  export interface TransitionProps {
17
17
  appear?: boolean;
18
- children: React.ReactElement<any, any>;
18
+ children: React.ReactElement;
19
19
  in?: boolean;
20
20
  type: 'fade' | 'zoom' | 'slide' | 'grow' | 'collapse' | 'grow_from_container' | 'slide_fade';
21
21
  css?: CSSProperties;
22
- containerRef?: any;
22
+ containerRef?: React.MutableRefObject<HTMLElement | null>;
23
23
  slideDirection?: Direction;
24
24
  }
25
25
  export interface IGrowFromContainerProps {
26
- containerRef?: React.MutableRefObject<HTMLDivElement | undefined>;
27
- node: HTMLDivElement;
26
+ containerRef?: React.MutableRefObject<HTMLElement | null>;
27
+ node: HTMLElement;
28
28
  transitionProps?: ITransitionProps;
29
29
  }
30
30
  export interface ITransitionProps {
31
- duration: number;
32
- easing: string;
33
- delay: number;
31
+ duration?: number | string;
32
+ easing?: string;
33
+ delay?: number | string;
34
34
  }
35
35
  //# sourceMappingURL=type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../packages/components/Transition/src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,gBAAgB,EAAE,iBAAiB,EA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;IAK9B,MAAM,CAAC,EAAE,OAAO,CAAC;IAIjB,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC;IAI7B,EAAE,CAAC,EAAE,OAAO,CAAC;IAKb,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,qBAAqB,GAAG,YAAY,CAAC;IAI7F,GAAG,CAAC,EAAE,aAAa,CAAC;IACpB,YAAY,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC1D,cAAc,CAAC,EAAE,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACtC,YAAY,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC1D,IAAI,EAAE,WAAW,CAAC;IAClB,eAAe,CAAC,EAAE,gBAAgB,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleartrip/ct-design-transition",
3
- "version": "4.0.0-TEST.3",
3
+ "version": "5.0.0",
4
4
  "description": "Transition Component",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/ct-design-transition.cjs.js",
@@ -12,19 +12,19 @@
12
12
  "./dist/ct-design-transition.cjs.js": "./dist/ct-design-transition.browser.cjs.js"
13
13
  },
14
14
  "files": [
15
- "dist"
15
+ "dist",
16
+ "src"
16
17
  ],
17
18
  "dependencies": {
18
19
  "react-transition-group": "^4.4.5",
19
- "@cleartrip/ct-design-theme": "3.20.0",
20
- "@cleartrip/ct-design-use-merge-refs": "3.20.0",
21
- "@cleartrip/ct-design-common-utils": "4.0.0-TEST.3"
20
+ "@cleartrip/ct-design-theme": "5.0.0",
21
+ "@cleartrip/ct-design-use-merge-refs": "5.0.0",
22
+ "@cleartrip/ct-design-common-utils": "5.0.0"
22
23
  },
23
24
  "devDependencies": {},
24
25
  "peerDependencies": {
25
26
  "react": ">=16.8.0",
26
- "react-dom": ">=16.8.0",
27
- "styled-components": "^5.3.6"
27
+ "react-dom": ">=16.8.0"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"
@@ -35,6 +35,8 @@
35
35
  "test": "echo \"Error: no test specified\" && exit 1",
36
36
  "watch-package": "rollup -c -w",
37
37
  "build-package": "rollup -c",
38
- "build-package:clean": "rm -rf dist && rollup -c"
38
+ "build-package:clean": "rm -rf dist && rollup -c",
39
+ "publish-package:local": "yalc publish --no-scripts",
40
+ "publish-package:local:registry": "pnpm publish --registry http://localhost:4873 --no-git-checks --access public"
39
41
  }
40
42
  }
@@ -0,0 +1,502 @@
1
+ import * as React from 'react';
2
+ import { Transition as ReactTransition } from 'react-transition-group';
3
+ import { useTheme } from '@cleartrip/ct-design-theme';
4
+ import useMergeRefs from '@cleartrip/ct-design-use-merge-refs';
5
+ import { Direction, IGrowFromContainerProps, TransitionProps } from './type';
6
+ import { styles } from './style';
7
+ import { debounce } from '@cleartrip/ct-design-common-utils';
8
+
9
+ const defaultTransform: Record<string, string | undefined> = {
10
+ grow: 'scale(0.75, 0.5625)',
11
+ zoom: 'scale(0)',
12
+ };
13
+
14
+ const reflow = (node: Element) => node.scrollTop;
15
+ interface TransitionOptions {
16
+ mode: 'enter' | 'exit';
17
+ }
18
+
19
+ interface TransitionPropsInput {
20
+ timeout?: number | { enter?: number; exit?: number };
21
+ easing?: string | { enter?: string; exit?: string };
22
+ style?: React.CSSProperties;
23
+ }
24
+
25
+ function getTransitionProps(props: TransitionPropsInput, options: TransitionOptions) {
26
+ const { timeout, easing, style = {} } = props;
27
+
28
+ return {
29
+ duration: style.transitionDuration ?? (typeof timeout === 'number' ? timeout : timeout?.[options.mode] || 0),
30
+ easing: style.transitionTimingFunction ?? (typeof easing === 'object' ? easing[options.mode] : easing),
31
+ delay: style.transitionDelay,
32
+ };
33
+ }
34
+
35
+ function getTranslateValue(direction: Direction, node: HTMLElement, containerRef: HTMLElement | null) {
36
+ const rect = node.getBoundingClientRect();
37
+ const containerRect = containerRef && containerRef.getBoundingClientRect();
38
+
39
+ const computedStyle = window.getComputedStyle(node);
40
+ const transform = computedStyle.getPropertyValue('-webkit-transform') || computedStyle.getPropertyValue('transform');
41
+
42
+ let offsetX = 0;
43
+ let offsetY = 0;
44
+
45
+ if (transform && transform !== 'none' && typeof transform === 'string') {
46
+ const transformValues = transform.split('(')[1].split(')')[0].split(',');
47
+ offsetX = parseInt(transformValues[4], 10);
48
+ offsetY = parseInt(transformValues[5], 10);
49
+ }
50
+
51
+ if (direction === 'left') {
52
+ if (containerRect) {
53
+ return `translateX(${containerRect.right + offsetX - rect.left}px)`;
54
+ }
55
+
56
+ return `translateX(${window.innerWidth + offsetX - rect.left}px)`;
57
+ }
58
+
59
+ if (direction === 'right') {
60
+ if (containerRect) {
61
+ return `translateX(-${rect.right - containerRect.left - offsetX}px)`;
62
+ }
63
+
64
+ return `translateX(-${rect.left + rect.width - offsetX}px)`;
65
+ }
66
+
67
+ if (direction === 'up') {
68
+ if (containerRect) {
69
+ return `translateY(${containerRect.bottom + offsetY - rect.top}px)`;
70
+ }
71
+ return `translateY(${window.innerHeight + offsetY - rect.top}px)`;
72
+ }
73
+
74
+ // direction === 'down'
75
+ if (containerRect) {
76
+ return `translateY(-${rect.top - containerRect.top + rect.height - offsetY}px)`;
77
+ }
78
+ return `translateY(-${rect.top + rect.height - offsetY}px)`;
79
+ }
80
+
81
+ export function setTranslateValue(direction: Direction, node: HTMLElement, containerRef: HTMLElement | null) {
82
+ const transform = getTranslateValue(direction, node, containerRef);
83
+
84
+ if (transform) {
85
+ node.style.webkitTransform = transform;
86
+ node.style.transform = transform;
87
+ }
88
+ }
89
+
90
+ export function getGrowFromContainerStyles({ containerRef, node, transitionProps }: IGrowFromContainerProps) {
91
+ const { delay = 0, duration = 300, easing = '' } = transitionProps ?? {};
92
+
93
+ requestAnimationFrame(() => {
94
+ if (!containerRef?.current) return;
95
+
96
+ const { width, height, top, left } = containerRef.current.getBoundingClientRect() ?? {};
97
+
98
+ node.style.transition = '';
99
+ node.style.opacity = '0';
100
+
101
+ const { height: realHeight, width: realWidth } = node.getBoundingClientRect();
102
+
103
+ requestAnimationFrame(() => {
104
+ node.style.transformOrigin = 'top left';
105
+ node.style.top = top + 'px';
106
+ node.style.left = left + 'px';
107
+
108
+ node.style.opacity = '0';
109
+ node.style.height = height + 'px';
110
+ node.style.width = width + 'px';
111
+ node.style.transform = 'translate(0, 0)';
112
+
113
+ requestAnimationFrame(() => {
114
+ node.style.transition = `opacity ${
115
+ (typeof duration === 'number' ? duration : 300) / 3
116
+ }ms ${delay || 0}ms ${easing}, width ${duration || 300}ms ${delay || 0}ms ${easing}, height ${duration || 300}ms ${delay || 0}ms ${easing}, transform ${duration || 300}ms ${delay || 0}ms ${easing}`;
117
+ node.style.height = realHeight + 'px';
118
+ node.style.width = realWidth + 'px';
119
+ node.style.opacity = '1';
120
+ node.style.transform = `translate(${-left}px, ${-top}px)`;
121
+ });
122
+ });
123
+ });
124
+ }
125
+
126
+ export function getExitGrowFromContainerStyles({ containerRef, node, transitionProps }: IGrowFromContainerProps) {
127
+ const { delay = 0, duration = 300, easing = '' } = transitionProps ?? {};
128
+
129
+ const resizingTime = (6 * (typeof duration === 'number' ? duration : 300)) / 10;
130
+ const fadingDelay = (5 * (typeof duration === 'number' ? duration : 300)) / 10;
131
+
132
+ requestAnimationFrame(() => {
133
+ if (!containerRef?.current) return;
134
+
135
+ const { width, height, top, left } = containerRef.current.getBoundingClientRect() ?? {};
136
+
137
+ node.style.transition = `opacity ${duration}ms ${fadingDelay}ms ${easing}, width ${resizingTime}ms ${delay}ms ${easing}, height ${resizingTime}ms ${delay}ms ${easing}, transform ${resizingTime}ms ${delay}ms ${easing}`;
138
+ node.style.transformOrigin = 'top left';
139
+ node.style.top = top + 'px';
140
+ node.style.left = left + 'px';
141
+ node.style.opacity = '0';
142
+
143
+ node.style.height = height + 'px';
144
+ node.style.width = width + 'px';
145
+ node.style.transform = 'translate(0, 0)';
146
+ });
147
+ }
148
+
149
+ /***
150
+ * Transition component
151
+ * it is based on type
152
+ */
153
+ const Transition = React.forwardRef<HTMLElement, TransitionProps>(
154
+ (
155
+ {
156
+ appear = true,
157
+ in: inProp,
158
+ css: _css,
159
+ style,
160
+ type,
161
+ children,
162
+ timeout,
163
+ easing,
164
+ containerRef,
165
+ slideDirection = 'down',
166
+ onEnter,
167
+ onEntered,
168
+ onEntering,
169
+ onExit,
170
+ onExited,
171
+ onExiting,
172
+ addEndListener,
173
+ ...other
174
+ },
175
+ forwardedRef,
176
+ ) => {
177
+ const theme = useTheme();
178
+ const defaultTimeout = {
179
+ enter: theme.transitions.duration.enteringScreen,
180
+ exit: theme.transitions.duration.leavingScreen,
181
+ };
182
+
183
+ timeout = timeout || defaultTimeout;
184
+
185
+ const nodeRef = React.useRef<HTMLElement>(null);
186
+ const handleRef = useMergeRefs(
187
+ nodeRef,
188
+ (children as React.ReactElement & { ref?: React.Ref<HTMLElement> })?.ref,
189
+ forwardedRef,
190
+ );
191
+
192
+ const normalizedTransitionCallback =
193
+ (callback?: ((node: HTMLElement, isAppearing?: boolean) => void) | ((node: HTMLElement) => void)) =>
194
+ (maybeIsAppearing?: boolean) => {
195
+ if (callback && nodeRef.current) {
196
+ const node = nodeRef.current;
197
+
198
+ // onEnterXxx and onExitXxx callbacks have a different arguments.length value.
199
+ if (maybeIsAppearing === undefined) {
200
+ callback(node);
201
+ } else {
202
+ callback(node, maybeIsAppearing);
203
+ }
204
+ }
205
+ };
206
+
207
+ // const handleEntering = normalizedTransitionCallback(onEntering);
208
+
209
+ const handleEnter = normalizedTransitionCallback((node: HTMLElement, isAppearing?: boolean) => {
210
+ if (type === 'slide') {
211
+ setTranslateValue(slideDirection, node, containerRef?.current || null);
212
+ }
213
+ reflow(node); // So the animation always start from the start.
214
+
215
+ const transitionProps = getTransitionProps(
216
+ { style, timeout, easing },
217
+ {
218
+ mode: 'enter',
219
+ },
220
+ );
221
+
222
+ /**
223
+ * implementation for fade
224
+ */
225
+ if (type === 'fade') {
226
+ // @ts-expect-error - theme.transitions.create is of type unknown
227
+ node.style.webkitTransition = theme.transitions.create('opacity', transitionProps);
228
+ // @ts-expect-error - theme.transitions.create is of type unknown
229
+ node.style.transition = theme.transitions.create('opacity', transitionProps);
230
+ }
231
+
232
+ if (type === 'slide_fade') {
233
+ node.style.webkitTransition = [
234
+ // @ts-expect-error - theme.transitions.create is of type unknown
235
+ theme.transitions.create('opacity', transitionProps),
236
+ // @ts-expect-error - theme.transitions.create is of type unknown
237
+ theme.transitions.create('transform', transitionProps),
238
+ ].join(',');
239
+
240
+ node.style.transition = [
241
+ // @ts-expect-error - theme.transitions.create is of type unknown
242
+ theme.transitions.create('opacity', transitionProps),
243
+ // @ts-expect-error - theme.transitions.create is of type unknown
244
+ theme.transitions.create('transform', transitionProps),
245
+ ].join(',');
246
+ }
247
+
248
+ if (type === 'grow_from_container') {
249
+ getGrowFromContainerStyles({
250
+ node,
251
+ containerRef,
252
+ transitionProps,
253
+ });
254
+ }
255
+
256
+ /**
257
+ * implementation for grow
258
+ */
259
+ if (type === 'grow') {
260
+ const duration = transitionProps.duration;
261
+ // if (timeout === 'auto') {
262
+ // duration = theme.transitions.getAutoHeightDuration(node.clientHeight);
263
+ // autoTimeout.current = duration;
264
+ // } else {
265
+ // duration = transitionProps.duration;
266
+ // }
267
+
268
+ node.style.transition = [
269
+ // @ts-expect-error - theme.transitions.create is of type unknown
270
+ theme.transitions.create('opacity', {
271
+ duration: transitionProps.duration,
272
+ delay: transitionProps.delay,
273
+ }),
274
+ // @ts-expect-error - theme.transitions.create is of type unknown
275
+ theme.transitions.create('transform', {
276
+ duration,
277
+ delay: transitionProps.delay,
278
+ easing: transitionProps.easing,
279
+ }),
280
+ ].join(',');
281
+ }
282
+ /**
283
+ * implementation for zoom
284
+ */
285
+ if (type === 'zoom') {
286
+ // @ts-expect-error - theme.transitions.create is of type unknown
287
+ node.style.webkitTransition = theme.transitions.create('transform', transitionProps);
288
+ // @ts-expect-error - theme.transitions.create is of type unknown
289
+ node.style.transition = theme.transitions.create('transform', transitionProps);
290
+ }
291
+
292
+ if (onEnter) {
293
+ onEnter(node, isAppearing || false);
294
+ }
295
+ });
296
+
297
+ const handleEntering = normalizedTransitionCallback((node: HTMLElement, isAppearing?: boolean) => {
298
+ if (type === 'slide') {
299
+ const easingValue = easing || {
300
+ enter: theme.transitions.easing.easeOut,
301
+ exit: theme.transitions.easing.sharp,
302
+ };
303
+ const transitionProps = getTransitionProps(
304
+ { timeout, style, easing: easingValue },
305
+ {
306
+ mode: 'enter',
307
+ },
308
+ );
309
+
310
+ // @ts-expect-error - theme.transitions.create is of type unknown
311
+ node.style.webkitTransition = theme.transitions.create('-webkit-transform', {
312
+ ...transitionProps,
313
+ });
314
+
315
+ // @ts-expect-error - theme.transitions.create is of type unknown
316
+ node.style.transition = theme.transitions.create('transform', {
317
+ ...transitionProps,
318
+ });
319
+
320
+ node.style.webkitTransform = '';
321
+ node.style.transform = '';
322
+ }
323
+ if (onEntering) {
324
+ onEntering(node, isAppearing || false);
325
+ }
326
+ });
327
+
328
+ const handleEntered = normalizedTransitionCallback(
329
+ onEntered ? (node: HTMLElement, isAppearing?: boolean) => onEntered(node, isAppearing || false) : undefined,
330
+ );
331
+
332
+ const handleExiting = normalizedTransitionCallback(onExiting);
333
+
334
+ const handleExit = normalizedTransitionCallback((node: HTMLElement) => {
335
+ const transitionProps = getTransitionProps(
336
+ { style, timeout, easing },
337
+ {
338
+ mode: 'exit',
339
+ },
340
+ );
341
+ /**
342
+ * implementation for fade
343
+ */
344
+ if (type == 'fade') {
345
+ // @ts-expect-error - theme.transitions.create is of type unknown
346
+ node.style.webkitTransition = theme.transitions.create('opacity', transitionProps);
347
+ // @ts-expect-error - theme.transitions.create is of type unknown
348
+ node.style.transition = theme.transitions.create('opacity', transitionProps);
349
+ }
350
+
351
+ if (type === 'slide_fade') {
352
+ node.style.transition = '';
353
+ node.style.webkitTransition = '';
354
+ }
355
+
356
+ if (type === 'grow_from_container') {
357
+ getExitGrowFromContainerStyles({
358
+ node,
359
+ containerRef,
360
+ transitionProps,
361
+ });
362
+ }
363
+
364
+ /**
365
+ * implementation for grow
366
+ */
367
+ if (type === 'grow') {
368
+ node.style.transition = [
369
+ // @ts-expect-error - theme.transitions.create is of type unknown
370
+ theme.transitions.create('opacity', {
371
+ duration: transitionProps.duration,
372
+ delay: transitionProps.delay,
373
+ }),
374
+ // @ts-expect-error - theme.transitions.create is of type unknown
375
+ theme.transitions.create('transform', {
376
+ duration: transitionProps.duration,
377
+ delay: transitionProps.delay,
378
+ easing: transitionProps.easing,
379
+ }),
380
+ ].join(',');
381
+
382
+ node.style.opacity = '0';
383
+ node.style.transform = 'scale(0.75, 0.5625)';
384
+ }
385
+ /**
386
+ * implementation for zoom
387
+ */
388
+ if (type === 'zoom') {
389
+ // @ts-expect-error - theme.transitions.create is of type unknown
390
+ node.style.webkitTransition = theme.transitions.create('transform', transitionProps);
391
+ // @ts-expect-error - theme.transitions.create is of type unknown
392
+ node.style.transition = theme.transitions.create('transform', transitionProps);
393
+ }
394
+ /**
395
+ * TODO
396
+ * implementation for slide
397
+ */
398
+ if (type === 'slide') {
399
+ // @ts-expect-error - theme.transitions.create is of type unknown
400
+ node.style.webkitTransition = theme.transitions.create('-webkit-transform', transitionProps);
401
+ // @ts-expect-error - theme.transitions.create is of type unknown
402
+ node.style.transition = theme.transitions.create('transform', transitionProps);
403
+
404
+ setTranslateValue(slideDirection, node, containerRef?.current || null);
405
+ }
406
+
407
+ if (onExit) {
408
+ onExit(node);
409
+ }
410
+ });
411
+
412
+ const handleExited = normalizedTransitionCallback((node: HTMLElement) => {
413
+ if (type === 'slide') {
414
+ node.style.webkitTransition = '';
415
+ node.style.transition = '';
416
+ }
417
+
418
+ if (onExited) {
419
+ onExited(node);
420
+ }
421
+ });
422
+
423
+ const handleAddEndListener = (next: () => void) => {
424
+ if (addEndListener && nodeRef.current) {
425
+ // Old call signature before `react-transition-group` implemented `nodeRef`
426
+ addEndListener(nodeRef.current, next);
427
+ }
428
+ };
429
+
430
+ const updatePosition = React.useCallback(() => {
431
+ if (nodeRef.current) {
432
+ setTranslateValue(slideDirection, nodeRef.current, containerRef?.current || null);
433
+ }
434
+ }, [slideDirection, containerRef]);
435
+
436
+ React.useEffect(() => {
437
+ // Skip configuration where the position is screen size invariant.
438
+ if (inProp || slideDirection === 'down' || slideDirection === 'right') {
439
+ return undefined;
440
+ }
441
+
442
+ const handleResize = debounce(() => {
443
+ if (nodeRef.current) {
444
+ setTranslateValue(slideDirection, nodeRef.current, containerRef?.current || null);
445
+ }
446
+ });
447
+
448
+ window.addEventListener('resize', handleResize);
449
+ return () => {
450
+ // handleResize.clear();
451
+ window.removeEventListener('resize', handleResize);
452
+ };
453
+ }, [slideDirection, inProp, containerRef]);
454
+
455
+ React.useEffect(() => {
456
+ if (type === 'slide' && !inProp) {
457
+ // We need to update the position of the drawer when the direction change and
458
+ // when it's hidden.
459
+ updatePosition();
460
+ }
461
+ }, [type, inProp, updatePosition]);
462
+
463
+ return (
464
+ <ReactTransition
465
+ appear={appear}
466
+ in={inProp}
467
+ nodeRef={nodeRef}
468
+ onEnter={handleEnter}
469
+ onEntered={handleEntered}
470
+ onEntering={handleEntering}
471
+ onExit={handleExit}
472
+ onExited={handleExited}
473
+ onExiting={handleExiting}
474
+ addEndListener={handleAddEndListener}
475
+ timeout={timeout}
476
+ {...other}
477
+ >
478
+ {(state) => {
479
+ const childrenProps = (children as React.ReactElement<{ style?: React.CSSProperties }>).props;
480
+ let childProp = {
481
+ style: {
482
+ opacity: type === 'fade' || type === 'grow' ? 0 : undefined,
483
+ transform: defaultTransform[type],
484
+ visibility: state === 'exited' && !inProp ? 'hidden' : undefined,
485
+ ...((styles as Record<string, Record<string, React.CSSProperties>>)[type]?.[state] || {}),
486
+ ...style,
487
+ ...childrenProps.style,
488
+ } as React.CSSProperties,
489
+ ref: handleRef,
490
+ };
491
+ if (type === 'slide') {
492
+ childProp = { ...childProp, ...childrenProps };
493
+ }
494
+ return React.cloneElement(children, childProp);
495
+ }}
496
+ </ReactTransition>
497
+ );
498
+ },
499
+ );
500
+
501
+ Transition.displayName = 'Transition';
502
+ export default Transition;
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default as Transition } from './Transition';
2
+ export type * from './type';
package/src/style.ts ADDED
@@ -0,0 +1,45 @@
1
+ export const styles = {
2
+ zoom: {
3
+ entering: {
4
+ transform: 'none',
5
+ },
6
+ entered: {
7
+ transform: 'none',
8
+ },
9
+ },
10
+ fade: {
11
+ entering: {
12
+ opacity: 1,
13
+ },
14
+ entered: {
15
+ opacity: 1,
16
+ },
17
+ },
18
+ grow: {
19
+ entering: {
20
+ opacity: 1,
21
+ transform: 'scale(1, 1)',
22
+ },
23
+ entered: {
24
+ opacity: 1,
25
+ transform: 'none',
26
+ },
27
+ },
28
+ slide_fade: {
29
+ entering: {
30
+ opacity: 0,
31
+ transform: 'translateY(4px)',
32
+ },
33
+ entered: {
34
+ opacity: 1,
35
+ transform: '',
36
+ },
37
+ exited: {
38
+ opacity: 0,
39
+ transform: 'translateY(4px)',
40
+ },
41
+ },
42
+ grow_from_container: {},
43
+ collapse: {},
44
+ slide: {},
45
+ };