To create a demo like this, add a demo.njk file to the pattern's root directory
You can add JavaScript to the demo as demonstrated below.
Refer to src/site/content/en/handbook/content-types/example-pattern/demo.njk to see how this was achieved.
src/site/content/en/handbook/content-types/example-pattern/demo.njk