After developing a component that changes its className based on the state, I discovered that animations only function properly when placed within the "style" attribute.
In my Codesandbox project, by uncommenting line 15 in the code snippet provided, the animation works as intended. Interestingly, even though I have applied the same CSS properties in Button.css file, it does not trigger the animation.