Whats the right design pattern for: Universal cancel button

I’ve found a good example that appears to be using similar idea. it’s free too: