简体   繁体   English

如何将 storybook 集成到 antd angular(NG-ZORRO)

[英]How to integrate storybook to antd angular(NG-ZORRO)

I'm trying to integrate the storybook to my angular project which uses and design the library.我正在尝试将故事书集成到我的 angular 项目中,该项目使用和设计该库。 Storyboook runs fine, but the antd style is not loading in stories. Storybook 运行良好,但 antd 样式没有加载到故事中。 It shows only the default elements.它仅显示默认元素。 I have googled many possibilities, there are little about and in angular.我用谷歌搜索了很多可能性,关于 angular 的内容很少。 I know that we have somehow wrap the stories with antd library.我知道我们以某种方式用 antd 库包装了这些故事。 Please show me the way.请给我指路。 If we have an example already it will be great.如果我们已经有一个例子,那就太好了。 Thanks in advance.提前致谢。

you need to add the ngzorro module into metadataModule of storybook.您需要将 ngzorro 模块添加到 storybook 的 metadataModule 中。 Here is example这是示例

export const MyComponentImpl = () => {
  return {
    moduleMetadata: {
      declarations: [MyComponent],
      imports: [
         BrowserModule,
         FormsModule,
         ReactiveFormsModule,
         BrowserAnimationsModule,
         NgZorroModule // the ngzorro modules that you want to use
     ]
    },
    template: `
        <div [ngStyle]="{'width': '100vw'}">

          <my-component></my-component>

        </div>
      `,
    props: {
    },
  };
};

When you use ng-zorro-antd in your projects, we would modify your angular.json to import styles file:当您在项目中使用 ng-zorro-antd 时,我们会修改您的 angular.json 以导入 styles 文件:

{
            "styles": [
              "node_modules/ng-zorro-antd/src/ng-zorro-antd.min.css",
              "src/styles.css"
            ],
}

So if you want to use ng-zorro-antd, you should import style files of the components you used in .story.js files.所以如果你想使用 ng-zorro-antd,你应该导入你在.story.js文件中使用的组件的样式文件。 Such as node_modules/ng-zorro-antd/src/components/select/style/entry.less .比如node_modules/ng-zorro-antd/src/components/select/style/entry.less

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM