-
-
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
Angular template support for Storybook #2690
Conversation
Let's use JS for this, don't see a compelling reason to pull lodash. Also, I don't see it in the deps and it's probably working because most projects use it but it could potentially break if it's not there. Signed-off-by: Carlos Vega <[email protected]>
Let's use JS for this, don't see a compelling reason to pull lodash. Also, I don't see it in the deps and it's probably working because most projects use it but it could potentially break if it's not there. Signed-off-by: Carlos Vega <[email protected]>
…ybook into angular-template-support
@alterx - I don't think |
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.
LGTM
@amcdnl we currently need the component for: Even if we make the user provide the bindings as a separate object we'd still need the component to add it to our inner module. |
Codecov Report
@@ Coverage Diff @@
## master #2690 +/- ##
==========================================
- Coverage 34.36% 34.35% -0.01%
==========================================
Files 390 390
Lines 8771 8772 +1
Branches 899 903 +4
==========================================
Hits 3014 3014
+ Misses 5170 5150 -20
- Partials 587 608 +21
Continue to review full report at Codecov.
|
Let's use JS for this, don't see a compelling reason to pull lodash. Also, I don't see it in the deps and it's probably working because most projects use it but it could potentially break if it's not there. Signed-off-by: Carlos Vega <[email protected]>
Let's use JS for this, don't see a compelling reason to pull lodash. Also, I don't see it in the deps and it's probably working because most projects use it but it could potentially break if it's not there. Signed-off-by: Carlos Vega <[email protected]>
…ybook into angular-template-support
@alterx , what if a template contains few components? Maybe worth adding them to the |
@igor-dv yeah, in that case we would add them to the This is an initial shot at the issue, I'd like @amcdnl to provide a real use case to see how we can implement these details |
@alterx - I think you mis-understood me. I mean't for this example:
Your example is confusing to me, seems like that would go in |
@amcdnl yeah, I know you're talking about that example, I didn't misunderstood you. The component is still there because, currently, I'm using it to get the metadata. |
This is just a contrived example, a POC. So it currently only supports creating the template using the bindings of that component we provide. That's why it has the label |
@alterx - Why do you need it? I'm confused on that part I guess. |
Because I didn't change the way this works. I just added the template parts on top of it so it still uses the component for props metadata. Hopefully it's not gonna be like that at the end. I just wanted to get it rendering a template. Long story short: if you run the code as is and remove the component it breaks. Something that I need to fix. Wanted to be sure we can render it before adding more stuff and changing how it works. |
Signed-off-by: Carlos Vega <[email protected]>
Signed-off-by: Carlos Vega <[email protected]>
Signed-off-by: Carlos Vega <[email protected]>
…-template-support
Signed-off-by: Carlos Vega <[email protected]>
With the use of *Manual metadata checks are still needed inside the knobs addon (which needs to manually deal with the change events that come from the knobs channel and send them to the angular component). |
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 so much easier and cleaner! Did you check it with v4?
const NewModule: any = function() {}; | ||
(<IModule>NewModule).annotations = [moduleMeta]; | ||
return NewModule; | ||
const DYNAMIC_COMPONENT_SELECTOR = 'storybook-dynamic-component'; |
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.
can you move it up?
const DYNAMIC_COMPONENT_SELECTOR = 'storybook-dynamic-component'; | ||
const createComponentFromTemplate = ( | ||
template: string, | ||
params?: any[], |
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.
params are not used here
import { FormsModule } from '@angular/forms'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { AppComponent } from './components/app.component'; | ||
import { ErrorComponent } from './components/error.component'; | ||
import { NoPreviewComponent } from './components/no-preview.component'; | ||
import { STORY } from './app.token'; | ||
import { getAnnotations, getParameters, getPropMetadata } from './utils'; |
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.
So, utils.ts can be deleted?
Signed-off-by: Carlos Vega <[email protected]>
…ybook into angular-template-support
Yup, checked in v4 :) |
selector?: string | ||
): IComponent => { | ||
const metadata = new Component({ | ||
selector: selector || DYNAMIC_COMPONENT_SELECTOR, |
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.
You don't have to have a selector.
params, | ||
moduleMeta, | ||
template, | ||
} = getComponentMetadata(currentStory(context)); | ||
|
||
if (!componentMeta) { |
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.
I'd add some errors like:
if (!template && (!component || typeof component !== 'function')) {
throw new Error('No valid component provided');
}
if (template && component) {
throw new Error('Component and template are mutually exclusive.');
}
…ybook into angular-template-support
Should there be documentation on this feature in https://storybook.js.org/basics/guide-angular/#write-your-stories? |
@teebszet Any chance you can contribute some docs on this? |
Docs would be real handy, like Vue for example there are 2 ways of creating a story, whereas Angular shows the same twice. Once I can wrap my head around this myself I'll be happy to update it 👍 |
Issue: #2645
What I did
Initial work to enable writing stories as follows:
How to test