-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow optional component declaration #6346
Allow optional component declaration #6346
Conversation
Sorry, as with my other PR, snapshots were missing. Should be good now. |
This pull request is automatically deployed with Now. Latest deployment for this branch: https://monorepo-git-fork-maximsagan-angular-dont-enforce-a45397.storybook.now.sh |
@kroeder @gaetanmaisse @amcdnl Would you be able to review this possibly? Sounds useful. |
# Conflicts: # app/angular/src/client/preview/angular/helpers.ts
Codecov Report
@@ Coverage Diff @@
## next #6346 +/- ##
==========================================
- Coverage 40.44% 38.21% -2.24%
==========================================
Files 637 648 +11
Lines 8759 9862 +1103
Branches 639 393 -246
==========================================
+ Hits 3543 3769 +226
- Misses 5118 6033 +915
+ Partials 98 60 -38
Continue to review full report at Codecov.
|
Issue: #5542
Typically, when developing features in Angular, it is advantageous to use "feature modules" which provide a "context" for declared components including required imports, declarations, and providers.
To simulate this context in Storybook, we may want to use the component that has already been declared in its FeatureModule, rather than having to recreate this context manually (with imports, providers, and additional declarations) just to get the component to perform its basic functionality.
However, currently, the only way to display a component declared in its feature module is to refer to it indirectly in the template property (e.g.
template: '<my-component [prop1]="prop1"></my-component>'
) which is used by Storybook to dynamically create a component called DynamicComponent. While this works, we lose the following benefits:If we want to get the above benefits, we need to specify the component by its class (e.g.
component: MyComponent
). Unfortunately, the default behavior of Storybook for Angular is to declare specified components in a dynamic module, which prevents us from using the version of the component declared in our feature module (with its appropriate context), due to the fact that a component can only be declared in one module (else Angular will error out).What I did
I added an optional flag called
requiresComponentDeclartion
to the NgStory object that the user specifies in the ".add()" method. When this flag is set to false, Storybook will not declare the specified component in the DynamicModule. This flag is set to true by default, which leaves the existing behavior (hence this is not a breaking change).How to test
Maybe? Please advise.
Yes, added.
The Storybook for Angular documentation does not seem to go very deep into specific configuration options.