mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
Adds requiresComponentDeclaration option
This commit is contained in:
parent
a27a523c7a
commit
24b98d9fc4
@ -34,9 +34,24 @@ const createComponentFromTemplate = (template: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const initModuleData = (storyObj: NgStory): any => {
|
export const initModuleData = (storyObj: NgStory): any => {
|
||||||
const { component, template, props, moduleMetadata = {} } = storyObj;
|
const {
|
||||||
|
component,
|
||||||
|
template,
|
||||||
|
props,
|
||||||
|
moduleMetadata = {},
|
||||||
|
requiresComponentDeclaration: componentRequiresDeclaration = true,
|
||||||
|
} = storyObj;
|
||||||
|
|
||||||
const AnnotatedComponent = template ? createComponentFromTemplate(template) : component;
|
const isCreatingComponentFromTemplate = Boolean(template);
|
||||||
|
|
||||||
|
const AnnotatedComponent = isCreatingComponentFromTemplate
|
||||||
|
? createComponentFromTemplate(template)
|
||||||
|
: component;
|
||||||
|
|
||||||
|
const componentDeclarations =
|
||||||
|
isCreatingComponentFromTemplate || componentRequiresDeclaration
|
||||||
|
? [AppComponent, AnnotatedComponent]
|
||||||
|
: [AppComponent];
|
||||||
|
|
||||||
const story = {
|
const story = {
|
||||||
component: AnnotatedComponent,
|
component: AnnotatedComponent,
|
||||||
@ -44,7 +59,7 @@ export const initModuleData = (storyObj: NgStory): any => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const moduleMeta = getModuleMeta(
|
const moduleMeta = getModuleMeta(
|
||||||
[AppComponent, AnnotatedComponent],
|
componentDeclarations,
|
||||||
[AnnotatedComponent],
|
[AnnotatedComponent],
|
||||||
[AppComponent],
|
[AppComponent],
|
||||||
story,
|
story,
|
||||||
|
@ -12,6 +12,7 @@ export interface ICollection {
|
|||||||
|
|
||||||
export interface NgStory {
|
export interface NgStory {
|
||||||
component?: any;
|
component?: any;
|
||||||
|
requiresComponentDeclaration?: boolean;
|
||||||
props: ICollection;
|
props: ICollection;
|
||||||
propsMeta?: ICollection;
|
propsMeta?: ICollection;
|
||||||
moduleMetadata?: NgModuleMetadata;
|
moduleMetadata?: NgModuleMetadata;
|
||||||
|
1
app/angular/index.d.ts
vendored
1
app/angular/index.d.ts
vendored
@ -22,6 +22,7 @@ export interface IStory {
|
|||||||
props?: ICollection;
|
props?: ICollection;
|
||||||
moduleMetadata?: Partial<NgModuleMetadata>;
|
moduleMetadata?: Partial<NgModuleMetadata>;
|
||||||
component?: any;
|
component?: any;
|
||||||
|
requiresComponentDeclaration?: boolean;
|
||||||
template?: string;
|
template?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,9 +47,25 @@ const createComponentFromTemplate = (template: string, styles: string[]) => {
|
|||||||
|
|
||||||
const initModule = (storyFn: IStoryFn) => {
|
const initModule = (storyFn: IStoryFn) => {
|
||||||
const storyObj = storyFn();
|
const storyObj = storyFn();
|
||||||
const { component, template, props, styles, moduleMetadata = {} } = storyObj;
|
const {
|
||||||
|
component,
|
||||||
|
template,
|
||||||
|
props,
|
||||||
|
styles,
|
||||||
|
moduleMetadata = {},
|
||||||
|
requiresComponentDeclaration: componentRequiresDeclaration = true,
|
||||||
|
} = storyObj;
|
||||||
|
|
||||||
let AnnotatedComponent = template ? createComponentFromTemplate(template, styles) : component;
|
const isCreatingComponentFromTemplate = Boolean(template);
|
||||||
|
|
||||||
|
const AnnotatedComponent = isCreatingComponentFromTemplate
|
||||||
|
? createComponentFromTemplate(template, styles)
|
||||||
|
: component;
|
||||||
|
|
||||||
|
const componentDeclarations =
|
||||||
|
isCreatingComponentFromTemplate || componentRequiresDeclaration
|
||||||
|
? [AppComponent, AnnotatedComponent]
|
||||||
|
: [AppComponent];
|
||||||
|
|
||||||
const story = {
|
const story = {
|
||||||
component: AnnotatedComponent,
|
component: AnnotatedComponent,
|
||||||
@ -57,7 +73,7 @@ const initModule = (storyFn: IStoryFn) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return getModule(
|
return getModule(
|
||||||
[AppComponent, AnnotatedComponent],
|
componentDeclarations,
|
||||||
[AnnotatedComponent],
|
[AnnotatedComponent],
|
||||||
[AppComponent],
|
[AppComponent],
|
||||||
story,
|
story,
|
||||||
|
@ -12,6 +12,7 @@ export interface ICollection {
|
|||||||
|
|
||||||
export interface NgStory {
|
export interface NgStory {
|
||||||
component?: any;
|
component?: any;
|
||||||
|
requiresComponentDeclaration?: boolean;
|
||||||
props: ICollection;
|
props: ICollection;
|
||||||
propsMeta?: ICollection;
|
propsMeta?: ICollection;
|
||||||
moduleMetadata?: NgModuleMetadata;
|
moduleMetadata?: NgModuleMetadata;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user