How to add directives to angular storybook
Asked Answered
U

2

6

I have a dropdown directive which I want to add to my storybook, its not working. When I run the button shows on the storybook but if I click on the button the template is not getting displayed.

import {moduleMetadata} from '@storybook/angular';
import {CommonModule} from '@angular/common';
import {DropdownModule} from '../../app/base-components/dropdown';

export default {
  title: 'dropdown',
  decorators: [
    moduleMetadata({
      declarations: [],
      imports: [CommonModule, DropdownModule]
    })
  ]
};

export const withDropdownTemplate = () => ({
  template: '<button dropDown></button>',
  props: {
    displayTpl: `<ng-template #dropdownTpl>
  <ul>
    Hello World
  </ul>
</ng-template>`
  }
});
Underhanded answered 7/5, 2020 at 4:30 Comment(1)
The question with half information is not much useful, provide error and demo code if possibleRms
E
2

I had the same question.

my solution: https://github.com/AnteaterCode/shatilokit/blob/master/src/stories/general/buttons.stories.ts

const modules = {
  imports: [
    ShButtonModule,
  ],
};

export default {
  title: 'general/Button',
  component: ShButton
} as Meta;


export const primary = () => ({
  moduleMetadata: modules,
  template: `
    <button shButton> Button </button>
  `,
});
Erlking answered 2/9, 2020 at 13:28 Comment(0)
P
0
    const customizable = ():StoryFn => (args) => ({
      template: `
       <button dropDown></button>
      `,
      props: args,
    });
    
    export const primary = customizable();
    primary.args = {...};
Poignant answered 20/6 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.