Better Tailwind, Live Components, Args Processors and Component Mock #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add ability to mock Twig Components for Storybook rendering.
Add (better) ability to process story's args in the userland.
Add support for Live Components.
Add support for TailwindBundle.
Add more tests!
Here are new features descriptions:
More on the LAST stack
TailwindBundle integration
If you use TailwindBundle to manage your CSS, it will
work by default with this bundle thanks to a built-in integration. Everytime your Storybook is recompiled, Tailwind
will also recompile your CSS.
However, each Tailwind build is executed in a one-shot process (without the
--watch
option). It may lead to errorsbecause the TailwindBundle will always try to download the latest version of the Tailwind binary. After a few builds
you could encounter an error trying to get the latest binary, because you requested the GitHub API too much in a short
period of time.
A good workaround for this is to specify the binary path in the TailwindBundle configuration after you initialized
Tailwind with
bin/console tailwind:init
:Live Components integration
To make Live Components work in Storybook, you have to enable proxy for live component requests in the
Storybook
main.ts|js
configuration:Thanks to this configuration, all requests made by live components to re-render themselves will be sent to the
Symfony server.
Twig Component Mock
One of the powerful features of Twig components is to use dependency injection to inject services (like Doctrine repositories) and consume them in property getters and other methods. Let's take the
FeaturedProducts
component from the official documentation:That's pretty cool, but in your Storybook you probably don't want to use the real
getProducts
implementation, which relies onProductRepository
. To bypass the original property resolution, you can create a Component Mock:As Component Mocks are regular services, you can inject whatever you need, for example to delegate your fixtures management to an external service:
If you need to access the original arguments passed to the method, or the original component instance, you can use the
MockInvocationContext
:Args Processors
Story's args are passed a JSON-encoded query parameters to the render request. By default, they are only decoded and injected in the Twig context on template rendering. You can customize these args before they are injected in the context with Args Processors:
You can also restrict your processor to a specific subset of stories: