The wallet component is made up of three different states: Default, Expanded and Collapsed.
The key aspect of this animation is assigning a unique layoutId to each component that needs to transition between states. In this animation, these components include the card base, icon, wallet name, and ETH value. This approach helps Motion identify which elements should transition together.
If all components shared the same layoutId Motion wouldn't be able to distinguish them, resulting in incorrect components being animated.
With the wallet states defined, we assemble the animation by tracking which card is currently expanded and toggling between expanded and collapsed states upon clicking a card.
The useOnClickOutside hook resets the expanded state when the user clicks outside the wallet.
Additionally, an event listener for the Escape key resets the component state when pressed.