-
-
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
Addon-docs/Angular: Inline rendering support with angular-elements #13525
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great and will make a lot of people happy. I don't understand enough about the Angular/Web components story to comment on the high-level approach, but I believe @stupidawesome suggested this in a previous conversation with @kroeder and me back when we were discussing Ivy rendering.
@kroeder @stupidawesome @costalvaro @petermikitsh @manuelmeister can you please take a look at this PR and give feedback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work so far 🙂
Your plan is to solve the issues with Storybooks docs mode, right?
I tried to add them in the addon-docs but it adds more angular dependency. I figure it's better if they're all in @storybook/angular?
What do you think about it?
@shilman Something you might be able to give feedback to.
app/angular/src/client/preview/angular-beta/StorybookWrapperComponent.ts
Outdated
Show resolved
Hide resolved
thanks :)
yes to propose an "inline" alternative to avoid iframe (adapts to the size of the component, changes in line with docs. can change theme with toolbar dynamically, ...) |
cc @mandarini |
bac1218
to
95b4524
Compare
2f3b47b
to
81a9c4e
Compare
39aab49
to
24be443
Compare
I'm not sure how to test. :/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working great! One small change.
@@ -1,9 +1,8 @@ | |||
import { DocButtonComponent } from './doc-button.component'; | |||
|
|||
export default { | |||
title: 'DocButton', | |||
title: 'Addons/Docs/DocButton', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the other angular-cli
examples are in Addon/x
. I think "addons" is better, but I suggest making the switch in a separate PR and updating all the other examples at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaa you have unmasked me
I would like to rework all stories example. group them, sort them,..., in order to see quickly their goals
I will do it in another PR
I do a final manual test : And then it will seem good to me |
Let me know when you're ready. Super excited about this!!! |
1b5722c
to
226564a
Compare
@shilman My test was useful and I had to make a change : add a specific file so that the whole code branch (with element import) is not used if the user does not use |
The configuration has to be set up in each angular project to avoid forcing dependencies to `@angular/elements` ans `@webcomponents/custom-elements`
226564a
to
53248ca
Compare
@ThibaudAV are we good to go now after the tests pass? |
yes it's ok for me |
There's an e2e failure but it's related to a different PR that I merged and @phated is following up on that. So I'm merging this since everything else looks great. ❤️ |
@ThibaudAV Hi iam testing the new inline feature in our component library (Angular 10) but iam discovered a strange behavior in my project. I have to compile my library with the ngcc compiler after each build, otherwise i get the following error message:
Does this mean storybook need a compiled ivy library to run? |
Issue: #8153 #12264 #13480
Another PR : #11339
TODO / Question :
Optimization with change of props (avoids refresh the whole component if props change)(if necessary in another PR)What I did
Uses angular element to transform story component into customElements (web-component).
The custom element is then added in React.
Add optional
@storybook/angular
dependency to@storybook/addon-docs
.Add optional
@angular/elements
&@webcomponents/custom-elements
dependencies in@storybook/angular
.Only one file (
ElementRendererService
) uses these dependencies, so if it is not called these depeandace still optional. It seems to me 🤔:not-sure:
User has to specify these dependencies if he uses
prepareForInline
I tried to add them in the addon-docs but it adds more angular dependency. I figure it's better if they're all in
@storybook/angular
?What do you think about it?
How it work
Add :
yarn add -D @angular/elements @webcomponents/custom-elements
Then update
.storybook/preview.js
:A special rendering is made by
prepareForInline
:prepareForInline
useElementRendererService
from@storybook/angular
ElementRendererService
use singleton instance of angular platform fromRendererService
ElementRendererService
generate customElementsModule
fromstoryInput
("main component" is generated in the same way as the "classic render")ElementsModule
is bootstrap by angular in<div id="root">
ElementsModule
usecreateCustomElement
from@angular/elements
to extract the main component (the one of the story) and return them toprepareForInline
as customElementprepareForInline
define incustomElements
new customElementNote: as it is not possible to delete defined customElements. An "increment" allows to make each new generation unique.
How to test
If your answer is yes to any of these, please make sure to include it in your PR.