✨ Allow interactive react examples#153
Conversation
# Conflicts: # site/_shortcodes/Example.js
sebastianbenz
left a comment
There was a problem hiding this comment.
Nice! I really like the approach of using next.js to build the examples. Left a few comments regarding style/structure, but in general looks good.
| } | ||
|
|
||
| if (this.parsed.react) { | ||
| previews.react = this.renderer.render('site/_includes/files/componentExample.js.njk', { |
There was a problem hiding this comment.
Why are the example templates in different directories?
There was a problem hiding this comment.
I wanted to make clear that this template doesn't make sense in the 11ty/HTML context by putting it in a different directory.
There was a problem hiding this comment.
Hm. Not sure if that is needed. I'd prefer to keep all templates in the same hierachy, but maybe add a comment in the template.
|
|
||
| _renderPreviews() { | ||
| const previews = {}; | ||
| if (this.parsed.webComponents) { |
There was a problem hiding this comment.
It feels like it'd be better to extract the JS and wc parsing/rendering logic into separate classes to avoid these repeated if statements. Or is there a case when both are valid at the same time?
There was a problem hiding this comment.
Yes that would be cleaner. When building I always had in mind that at some point one might want to extend this to be able to power a widget where you are able to toggle between web component and react sample like we had in mind for the hero example. That's when you would have both a js and a html snippet in one {% example %}. But that's probably not a valid use case anymore...?
There was a problem hiding this comment.
The hero examples are standalone anyway.
This allows interactive examples for the Bento React components like the following:
Some remarks: I added a copy of markdown-it-container to the project as the NPM package is esm only. Its only purpose though is to pass through parsed markdown tokens unaltered so markdown-it doesn't throw random
<p>in our example widgets. That could also be achieved with a much more lighter custom markdown-it plugin but I wanted to move quickly.For this to work JS examples need to be ensured working. Example: the bento-accordion example I used for testing purposes is actually broken upstream. It misses to import
BentoAccordionSection,BentoAccordionHeaderandBentoAccordionContent.Broken examples would kill the whole build process as next.js has no option to ignore broken pages. I could find none at least.
So far:
npm run developand http://localhost:8080/components/bento-accordion/#preact%2Freact-component