Is it possible to make a toggle button on/off to open an overlay?

Hey guys!

I really liked a toggle button I saw in the community:

And I am wondering if I can incorporate it into my prototype. The thing is - I would like for it to open an overlay when toggled “on” and to close that overlay when toggled “off” ; I’ve been researching for a few hours now but it seems pretty “not straightforward”, what am I missing?