How to close widget using its own button?

One of those:

300765-annotation-2020-04-28-075353.png

Depending whether you want to get rid of the widget for good or just hide it.