Skip to content
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] Add moduleMetadata once #2694

Closed
scottkipfer opened this issue Jan 9, 2018 · 4 comments
Closed

[Angular] Add moduleMetadata once #2694

scottkipfer opened this issue Jan 9, 2018 · 4 comments

Comments

@scottkipfer
Copy link

scottkipfer commented Jan 9, 2018

Issue details

Feature Request: It can get tedious adding the same moduleMetadata for every story. Could it be possible to add it once at the parent level? I added a code snippet bellow to help clarify my request.

Screenshots / Screencast / Code Snippets (Optional)

Current: AppMoudle must be provided for each story.

import { storiesOf } from '@storybook/angular';
import {AppModule} from "../src/app/app.module";

import {ButtonComponent} from "../src/app/button/button.component";

storiesOf('Buttons', module).add('Button', () => ({
  component: ButtonComponent,
  props: {
    buttonText: 'Button',
    buttonColor: 'primary'
  },
  moduleMetadata: {
    imports: [AppModule]
  }
})).add('Button With Icon',() => ({
  component: ButtonComponent,
  props: {
    buttonText: 'Button',
    buttonIcon: 'account_circle',
    buttonColor: 'warn'
  },
  moduleMetadata: {
    imports: [AppModule]
  }
})).add('Disabled Button', () => ({
  component: ButtonComponent,
  props: {
    buttonText: 'Disabled',
    disabled: true
  },
  moduleMetadata: {
    imports: [AppModule]
  }
}));

Example: AppMoudle is imported before any stories are added.

import { storiesOf } from '@storybook/angular';
import {AppModule} from "../src/app/app.module";

import {ButtonComponent} from "../src/app/button/button.component";

storiesOf('Buttons', module).imports([AppModule]).add('Button', () => ({
  component: ButtonComponent,
  props: {
    buttonText: 'Button',
    buttonColor: 'primary'
  }
})).add('Button With Icon',() => ({
  component: ButtonComponent,
  props: {
    buttonText: 'Button',
    buttonIcon: 'account_circle',
    buttonColor: 'warn'
  }
})).add('Disabled Button', () => ({
  component: ButtonComponent,
  props: {
    buttonText: 'Disabled',
    disabled: true
  }
}));```

  
  
@amcdnl
Copy link
Member

amcdnl commented Jan 9, 2018

I agree with the use case but I think something like:

storiesOf('Buttons', module)
   .addDecorator(moduleMetadata({ inputs: [MyModule] }))
   .add(...)

would be more in line with the API.

@scottkipfer scottkipfer changed the title Add moduleMetadata once [Angular] Add moduleMetadata once Jan 12, 2018
@jonrimmer
Copy link
Contributor

We had the same requirement. I created this decorator, which can be used as @amcdnl suggested:

import { NgModuleMetadata } from '@storybook/angular/dist/client/preview/angular/types';

export const moduleMetadata = (metadata: Partial<NgModuleMetadata>) =>
  (context: () => any) => ({
    moduleMetadata: metadata,
    ...context()
  });

Individual stories should be able to override the default metadata with their own. A more robust implementation could try to merge the two.

@amcdnl
Copy link
Member

amcdnl commented Feb 5, 2018

@jonrimmer - Very nice! You should PR this.

@stale
Copy link

stale bot commented Mar 22, 2018

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!

@stale stale bot added the inactive label Mar 22, 2018
@igor-dv igor-dv closed this as completed Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants