@@ -22,26 +22,26 @@ export default defineComponent({
22
22
type: Number ,
23
23
required: true ,
24
24
},
25
+ shouldAnimate: {
26
+ type: Boolean ,
27
+ default: true ,
28
+ },
25
29
},
26
- setup(props ) {
27
- const animationProgress = ref (0 );
30
+ setup(props , { emit } ) {
31
+ const animationProgress = ref (100 ); // Start with full progress
28
32
const isFirstStepAnimated = ref (false );
29
- const ANIMATION_DURATION = 1500 ; // 1500ms = 1.5s
33
+ const ANIMATION_DURATION = 5000 ; // 5000ms = 5s (adjust as needed)
30
34
31
35
const getFillWidth = computed (() => (step : number ) => {
32
36
if (props .currentStep > step ) return ' 100%' ;
33
37
if (props .currentStep === step ) {
34
- // Apply easing function to the animation progress
35
- const easedProgress = easeOutCubic (animationProgress .value / 100 ) * 100 ;
36
- return ` ${easedProgress }% ` ;
38
+ return props .shouldAnimate ? ` ${animationProgress .value }% ` : ' 100%' ;
37
39
}
38
40
return ' 0%' ;
39
41
});
40
42
41
- // Easing function: easeOutCubic
42
- const easeOutCubic = (t : number ): number => 1 - (1 - t ) ** 3 ;
43
-
44
43
let animationFrame: number ;
44
+ let animationStartTime: number | null = null ;
45
45
46
46
const animateStep = (timestamp : number ) => {
47
47
if (! animationStartTime ) {
@@ -51,26 +51,30 @@ export default defineComponent({
51
51
const progress = Math .min (elapsed / ANIMATION_DURATION , 1 );
52
52
animationProgress .value = progress * 100 ;
53
53
54
- if (progress < 1 ) {
54
+ if (progress < 1 && props . shouldAnimate ) {
55
55
animationFrame = requestAnimationFrame (animateStep );
56
56
} else {
57
57
isFirstStepAnimated .value = true ;
58
+ emit (' stepCompleted' );
58
59
}
59
60
};
60
61
61
- let animationStartTime: number | null = null ;
62
-
63
62
const startAnimation = () => {
64
- animationStartTime = null ;
65
- cancelAnimationFrame (animationFrame );
66
- animationFrame = requestAnimationFrame (animateStep );
63
+ if (props .shouldAnimate ) {
64
+ animationStartTime = null ;
65
+ cancelAnimationFrame (animationFrame );
66
+ animationProgress .value = 0 ; // Reset progress before starting animation
67
+ animationFrame = requestAnimationFrame (animateStep );
68
+ } else {
69
+ animationProgress .value = 100 ; // Set to full progress immediately
70
+ }
67
71
};
68
72
69
73
watch (() => props .currentStep , (newStep , oldStep ) => {
70
74
if (newStep > oldStep || (newStep === 1 && ! isFirstStepAnimated .value )) {
71
75
startAnimation ();
72
76
} else if (newStep < oldStep ) {
73
- animationProgress .value = 0 ;
77
+ animationProgress .value = 100 ; // Set to full progress when going back
74
78
}
75
79
});
76
80
0 commit comments