Skip to content

Commit bf93090

Browse files
author
Hector Arce De Las Heras
committed
Deprecate numeric duration properties in CSS animations
This commit deprecates the use of numeric values for the `duration`, `enterDuration`, `exitDuration`, and `delay` properties in CSS animations. Going forward, these properties will be of type string, with the duration values including their respective units. This change standardizes the way durations are specified in CSS animations, improving readability and maintainability.
1 parent a2533ed commit bf93090

File tree

3 files changed

+68
-13
lines changed

3 files changed

+68
-13
lines changed

src/components/cssAnimation/animations/transitionMixin.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,51 @@ import { ICssAnimationStyled } from '../types/cssAnimation';
1010
* @returns {CSSProp} - The animation
1111
*
1212
*/
13+
// deprecated - props duration, enterDuration, exitDuration and delay should be of type string (props should come with the units)
1314
export const transitionMixin = (props: ICssAnimationStyled): CSSProp => css`
1415
transition:
15-
opacity ${props.options?.duration}s,
16-
transform ${props.options?.duration}s;
16+
opacity
17+
${typeof props.options?.duration === 'number'
18+
? props.options?.duration + 's'
19+
: props.options?.duration},
20+
transform
21+
${typeof props.options?.duration === 'number'
22+
? props.options?.duration + 's'
23+
: props.options?.duration};
1724
transition-timing-function: ${props.options?.timingFunction};
18-
transition-delay: ${props.options?.delay}s;
25+
transition-delay: ${typeof props.options?.delay === 'number'
26+
? props.options?.delay + 's'
27+
: props.options?.delay};
1928
`;
29+
// deprecated - props duration, enterDuration, exitDuration and delay should be of type string (props should come with the units)
2030
export const transitionMixinEnter = (props: ICssAnimationStyled): CSSProp => css`
2131
transition:
22-
opacity ${props.options?.enterDuration}s,
23-
transform ${props.options?.enterDuration}s;
32+
opacity
33+
${typeof props.options?.enterDuration === 'number'
34+
? props.options?.enterDuration + 's'
35+
: props.options?.enterDuration},
36+
transform
37+
${typeof props.options?.enterDuration === 'number'
38+
? props.options?.enterDuration + 's'
39+
: props.options?.enterDuration};
2440
transition-timing-function: ${props.options?.timingFunction};
25-
transition-delay: ${props.options?.delay}s;
41+
transition-delay: ${typeof props.options?.delay === 'number'
42+
? props.options?.delay + 's'
43+
: props.options?.delay};
2644
`;
45+
// deprecated - props duration, enterDuration, exitDuration and delay should be of type string (props should come with the units)
2746
export const transitionMixinExit = (props: ICssAnimationStyled): CSSProp => css`
2847
transition:
29-
opacity ${props.options?.exitDuration}s,
30-
transform ${props.options?.exitDuration}s;
48+
opacity
49+
${typeof props.options?.exitDuration === 'number'
50+
? props.options?.exitDuration + 's'
51+
: props.options?.exitDuration},
52+
transform
53+
${typeof props.options?.exitDuration === 'number'
54+
? props.options?.exitDuration + 's'
55+
: props.options?.exitDuration};
3156
transition-timing-function: ${props.options?.timingFunction};
32-
transition-delay: ${props.options?.delay}s;
57+
transition-delay: ${typeof props.options?.delay === 'number'
58+
? props.options?.delay + 's'
59+
: props.options?.delay};
3360
`;

src/components/cssAnimation/cssAnimation.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
} from 'react';
1111
import { CSSTransition } from 'react-transition-group';
1212

13+
import { convertDurationToNumber } from '@/utils/stringUtility/string.utility';
14+
1315
import { CssAnimationContainer } from './cssAnimation.styled';
1416
import { CssAnimationExecuteOption, ICssAnimation } from './types';
1517

@@ -26,19 +28,33 @@ const CssAnimationComponent = (
2628
const nodeRef = useRef<HTMLDivElement>();
2729
const [execute, setExecute] = useState(CssAnimationExecuteOption.HIDDEN);
2830

31+
// deprecated - Remove the condition when `enterDuration` and `duration` are type string
2932
const enterDuration = () => {
3033
if (options?.enterDuration) {
34+
if (typeof options?.enterDuration === 'string') {
35+
return convertDurationToNumber(options?.enterDuration);
36+
}
3137
return options.enterDuration * 1000;
3238
} else if (options?.duration) {
39+
if (typeof options?.duration === 'string') {
40+
return convertDurationToNumber(options?.duration);
41+
}
3342
return options.duration * 1000;
3443
}
3544
return 0;
3645
};
3746

47+
// deprecated - Remove the condition when `exitDuration` and `duration` are type string
3848
const exitDuration = () => {
3949
if (options?.exitDuration) {
50+
if (typeof options?.exitDuration === 'string') {
51+
return convertDurationToNumber(options?.exitDuration);
52+
}
4053
return options.exitDuration * 1000;
4154
} else if (options?.duration) {
55+
if (typeof options?.duration === 'string') {
56+
return convertDurationToNumber(options?.duration);
57+
}
4258
return options.duration * 1000;
4359
}
4460
return 0;

src/components/cssAnimation/types/cssAnimation.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,23 @@ export enum CssAnimationTimingFunction {
2727
* Interface for the CssAnimationOptions
2828
*/
2929
export interface ICssAnimationOptions {
30-
duration?: number;
31-
enterDuration?: number;
32-
exitDuration?: number;
30+
/**
31+
* @deprecated This property will be of type string (the duration should come with the units)
32+
*/
33+
duration?: number | string;
34+
/**
35+
* @deprecated This property will be of type string (the duration should come with the units)
36+
*/
37+
enterDuration?: number | string;
38+
/**
39+
* @deprecated This property will be of type string (the duration should come with the units)
40+
*/
41+
exitDuration?: number | string;
3342
timingFunction: CssAnimationTimingFunction;
34-
delay: number;
43+
/**
44+
* @deprecated This property will be of type string (the duration should come with the units)
45+
*/
46+
delay: number | string;
3547
iterationCount: number;
3648
animationDistanceInPx?: number;
3749
animationRotationInDeg?: number;

0 commit comments

Comments
 (0)