How to open and close one extention from a button click

I want to add a close button to my extention, so the user can close the extention, I tried to add one command when the extention is created and hide the extention, but when I hide the command the side pannel opend stays there while the extention got hidden. how can I make the side bar to go hidden and main window to become expanded.