-
Notifications
You must be signed in to change notification settings - Fork 3
Description
By default, Storybook displays the JavaScript source for stories when you click the "show code" button on story previews in docs mode:
This is not particularly useful for this project, where most of the patterns are Twig templates. There's never a place where that code would be copied and pasted anywhere.
We recently updated Storybook to 6.x, which included a few improvements to the customization of source previews. Unfortunately these don't seem to be capable of full automation, but it would allow us to do something like this...
import { Story, Canvas, Meta } from '@storybook/addon-docs/blocks';
import template from './example/template.twig';
import templateSrc from '!!raw-loader!./example/template.twig;
// ...
<Canvas>
<Story name="Example" parameters={{
docs: { source: { code: templateSrc } }
}}>
{(args) => template(args)}
</Story>
</Canvas>This would get us a lot closer, but it does call into question our current way of keeping things DRY through demos. Consider these two examples, a default and a prose container:
Notice that the examples are the same, and aren't really indicative of how things would work in the wild. That's because the demos were written from the point of view of the maintainer keeping things DRY and not as a point of reference for the viewer. Does this mean rewriting all of the demos so far to keep them more relevant?
Alternatively, we could manually include an additional example for each pattern:
<Source
language="twig"
code={`{% embed '@cloudfour/objects/container/container.twig' %}
{% block content %}
Hello world
{% endblock %}
{% endembed %}`}
></Source>Which would display outside the story:
This would give us a lot more freedom, but is it too much extra work? And can we disable the normal "show code" buttons to reduce noise of the docs?



