@storybook/angular 8.0.0-rc.3 → 8.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,324 +1,3 @@
1
1
  # Storybook for Angular
2
2
 
3
- - [Storybook for Angular](#storybook-for-angular)
4
- - [Getting Started](#getting-started)
5
- - [Setup Storybook for your Angular projects](#setup-storybook-for-your-angular-projects)
6
- - [Run Storybook](#run-storybook)
7
- - [Setup Compodoc](#setup-compodoc)
8
- - [Automatic setup](#automatic-setup)
9
- - [Manual setup](#manual-setup)
10
- - [moduleMetadata decorator](#modulemetadata-decorator)
11
- - [applicationConfig decorator](#applicationconfig-decorator)
12
- - [FAQ](#faq)
13
- - [How do I migrate to an Angular Storybook builder?](#how-do-i-migrate-to-an-angular-storybook-builder)
14
- - [Do you have only one Angular project in your workspace?](#do-you-have-only-one-angular-project-in-your-workspace)
15
- - [Adjust your `package.json`](#adjust-your-packagejson)
16
- - [I have multiple projects in my Angular workspace](#i-have-multiple-projects-in-my-angular-workspace)
17
-
18
- Storybook for Angular is a UI development environment for your Angular components.
19
- With it, you can visualize different states of your UI components and develop them interactively.
20
-
21
- ![Storybook Screenshot](https://github.com/storybookjs/storybook/blob/main/media/storybook-intro.gif)
22
-
23
- Storybook runs outside of your app.
24
- So you can develop UI components in isolation without worrying about app specific dependencies and requirements.
25
-
26
- ## Getting Started
27
-
28
- ```sh
29
- cd my-angular-app
30
- npx storybook@latest init
31
- ```
32
-
33
- ## Setup Storybook for your Angular projects
34
-
35
- Storybook supports Angular multi-project workspace. You can setup Storybook for each project in the workspace. When running `npx storybook@latest init` you will be asked for which project Storybook should be set up. Essentially, during initialization, the `.storybook` folder will be created and the `angular.json` will be edited to add the Storybook configuration for the selected project. The configuration looks approximately like this:
36
-
37
- ```json
38
- // angular.json
39
- {
40
- ...
41
- "projects": {
42
- ...
43
- "your-project": {
44
- ...
45
- "architect": {
46
- ...
47
- "storybook": {
48
- "builder": "@storybook/angular:start-storybook",
49
- "options": {
50
- // the path to the storybook config directory
51
- "configDir": ".storybook",
52
- // the build target of your project
53
- "browserTarget": "your-project:build",
54
- // the port you want to start Storybook on
55
- "port": 6006
56
- // further options are available and can be found in
57
- // https://github.com/storybookjs/storybook/tree/next/code/frameworks/angular/src/builders/start-storybook/schema.json
58
- }
59
- },
60
- "build-storybook": {
61
- "builder": "@storybook/angular:build-storybook",
62
- "options": {
63
- "configDir": ".storybook",
64
- "browserTarget": "your-project:build",
65
- "outputDir": "dist/storybook/your-project"
66
- // further options are available and can be found in
67
- // https://github.com/storybookjs/storybook/tree/next/code/frameworks/angular/src/builders/build-storybook/schema.json
68
- }
69
- }
70
- }
71
- }
72
- }
73
- }
74
- ```
75
-
76
- ## Run Storybook
77
-
78
- To run Storybook for a particular project, please run:
79
-
80
- ```sh
81
- ng run <your-project>:storybook
82
- ```
83
-
84
- To build Storybook, run:
85
-
86
- ```sh
87
- ng run <your-project>:build-storybook
88
- ```
89
-
90
- You will find the output in `dist/storybook/your-project`.
91
-
92
- For more information visit: [storybook.js.org](https://storybook.js.org)
93
-
94
- ## Setup Compodoc
95
-
96
- You can include JSDoc comments above components, directives, and other parts of your Angular code to include documentation for those elements. Compodoc uses these comments to generate documentation for your application. In Storybook, it is useful to add explanatory comments above @Inputs and @Outputs, since these are the main elements that Storybook displays in its user interface. The @Inputs and @Outputs are the elements that you can interact with in Storybook, such as controls.
97
-
98
- ### Automatic setup
99
-
100
- When installing Storybook via `sb init`, you will be given the option to set up Compodoc automatically.
101
-
102
- ### Manual setup
103
-
104
- If you have already installed Storybook, you can set up Compodoc manually.
105
-
106
- Install the following dependencies:
107
-
108
- ```sh
109
- npm i -D @compodoc/compodoc
110
- ```
111
-
112
- Add the following option to your to the Storybook Builder:
113
-
114
- ```json
115
- {
116
- ...
117
- "projects": {
118
- ...
119
- "your-project": {
120
- ...
121
- "architect": {
122
- ...
123
- "storybook": {
124
- "builder": "@storybook/angular:start-storybook",
125
- "options": {
126
- ...
127
- "compodoc": true,
128
- "compodocArgs": [
129
- "-e",
130
- "json",
131
- "-d",
132
- // Where to store the generated documentation. It's usually the root of your Angular project. It's not necessarily the root of your Angular Workspace!
133
- "."
134
- ],
135
- }
136
- },
137
- "build-storybook": {
138
- "builder": "@storybook/angular:build-storybook",
139
- "options": {
140
- ...
141
- "compodoc": true,
142
- "compodocArgs": [
143
- "-e",
144
- "json",
145
- "-d",
146
- "."
147
- ],
148
- }
149
- }
150
- }
151
- }
152
- }
153
- }
154
- ```
155
-
156
- Go to your `.storybook/preview.js` and add the following:
157
-
158
- ```js
159
- import { setCompodocJson } from '@storybook/addon-docs/angular';
160
- import docJson from '../documentation.json';
161
- setCompodocJson(docJson);
162
-
163
- const preview: Preview = {
164
- ...
165
- };
166
-
167
- export default preview;
168
- ```
169
-
170
- ## moduleMetadata decorator
171
-
172
- If your component has dependencies on other Angular directives and modules, these can be supplied using the moduleMetadata decorator either for all stories or for individual stories.
173
-
174
- ```js
175
- import { StoryFn, Meta, moduleMetadata } from '@storybook/angular';
176
- import { SomeComponent } from './some.component';
177
-
178
- export default {
179
- component: SomeComponent,
180
- decorators: [
181
- // Apply metadata to all stories
182
- moduleMetadata({
183
- // import necessary ngModules or standalone components
184
- imports: [...],
185
- // declare components that are used in the template
186
- declarations: [...],
187
- // List of providers that should be available to the root component and all its children.
188
- providers: [...],
189
- }),
190
- ],
191
- } as Meta;
192
-
193
- const Template = (): StoryFn => (args) => ({
194
- props: args,
195
- });
196
-
197
- export const Base = Template();
198
-
199
- export const WithCustomProvider = Template();
200
- WithCustomProvider.decorators = [
201
- // Apply metadata to a specific story
202
- moduleMetadata({
203
- imports: [...],
204
- declarations: [...],
205
- providers: [...]
206
- }),
207
- ];
208
- ```
209
-
210
- ## applicationConfig decorator
211
-
212
- If your component relies on application-wide providers, like the ones defined by BrowserAnimationsModule or any other modules which use the forRoot pattern to provide a ModuleWithProviders, you can use the applicationConfig decorator on the meta default export to provide them to the [bootstrapApplication function](https://angular.io/guide/standalone-components#configuring-dependency-injection), which we use to bootstrap the component in Storybook.
213
-
214
- ```js
215
-
216
- import { StoryObj, Meta, applicationConfig } from '@storybook/angular';
217
- import { BrowserAnimationsModule, provideAnimations } from '@angular/platform-browser/animations';
218
- import { importProvidersFrom } from '@angular/core';
219
- import { ChipsModule } from './angular-src/chips.module';
220
-
221
- const meta: Meta = {
222
- component: ChipsGroupComponent,
223
- decorators: [
224
- // Apply application config to all stories
225
- applicationConfig({
226
- // List of providers and environment providers that should be available to the root component and all its children.
227
- providers: [
228
- ...
229
- // Import application-wide providers from a module
230
- importProvidersFrom(BrowserAnimationsModule)
231
- // Or use provide-style functions if available instead, e.g.
232
- provideAnimations()
233
- ],
234
- }),
235
- ],
236
- };
237
-
238
- export default meta;
239
-
240
- type Story = StoryObj<typeof ChipsGroupComponent>;
241
-
242
- export const WithCustomApplicationProvider: Story = {
243
- render: () => ({
244
- // Apply application config to a specific story
245
- applicationConfig: {
246
- // The providers will be merged with the ones defined in the applicationConfig decorators providers array of the global meta object
247
- providers: [...]
248
- }
249
- })
250
- }
251
- ```
252
-
253
- ## FAQ
254
-
255
- ### How do I migrate to an Angular Storybook builder?
256
-
257
- The Storybook [Angular builder](https://angular.io/guide/glossary#builder) is a new way to run Storybook in an Angular workspace. It is a drop-in replacement for running `storybook dev` and `storybook build` directly.
258
-
259
- You can run `npx storybook@next automigrate` to try let Storybook detect and automatically fix your configuration. Otherwise, you can follow the next steps to manually adjust your configuration.
260
-
261
- #### Do you have only one Angular project in your workspace?
262
-
263
- In this case go to your `angular.json` and add `storybook` and `build-storybook` entries in `architect` section of your project like shown above.
264
-
265
- ##### Adjust your `package.json`
266
-
267
- Go to your `package.json` and adjust your script section. Usually, it will look like this:
268
-
269
- ```json
270
- {
271
- "scripts": {
272
- "storybook": "start-storybook -p 6006", // or `storybook dev -p 6006`
273
- "build-storybook": "build-storybook" // or `storybook build`
274
- }
275
- }
276
- ```
277
-
278
- Now, you can run Storybook with `ng run <your-project>:storybook` and build it with `ng run <your-project>:build-storybook`. Adjust the scripts in your `package.json` accordingly.
279
-
280
- ```json
281
- {
282
- "scripts": {
283
- "storybook": "ng run <project-name>:storybook", // or `storybook dev -p 6006`
284
- "build-storybook": "ng run <project-name>:build-storybook" // or `storybook build`
285
- }
286
- }
287
- ```
288
-
289
- Also remove the compodoc part in your script section if you have set it up previously.
290
- It is now built-in in `@storybook/angular` and you don't have to call it explicitly:
291
-
292
- ```json
293
- {
294
- "scripts": {
295
- "docs:json": "compodoc -p tsconfig.json -e json -d ./documentation",
296
- "storybook": "npm run docs:json && start-storybook -p 6006",
297
- "build-storybook": "npm run docs:json && build-storybook"
298
- }
299
- }
300
- ```
301
-
302
- Change it to:
303
-
304
- ```json
305
- {
306
- "scripts": {
307
- "storybook": "ng run <project-name>:storybook",
308
- "build-storybook": "ng run <project-name>:build-storybook"
309
- }
310
- }
311
- ```
312
-
313
- #### I have multiple projects in my Angular workspace
314
-
315
- In this case you have to adjust your `angular.json` and `package.json` as described above for each project in which you want to use Storybook. Please note, that each project should have a dedicated `.storybook` folder, which should be placed in the root of the project.
316
-
317
- You can run `npx sb init` sequentially for each project to setup Storybook for each of them to automatically create the `.storybook` folder and create the necessary configuration in your `angular.json`.
318
-
319
- You can then use [Storybook composition](https://storybook.js.org/docs/angular/sharing/storybook-composition) to composite multiple Storybooks into one.
320
-
321
- ---
322
-
323
- Storybook also comes with a lot of [addons](https://storybook.js.org/addons) and a great API to customize as you wish.
324
- You can also build a [static version](https://storybook.js.org/docs/angular/sharing/publish-storybook) of your Storybook and deploy it anywhere you want.
3
+ See [documentation](https://storybook.js.org/docs/8.0/get-started/angular?renderer=angular) for installation instructions, usage examples, APIs, and more.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/angular",
3
- "version": "8.0.0-rc.3",
3
+ "version": "8.0.0-rc.4",
4
4
  "description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -37,18 +37,18 @@
37
37
  "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/tsc.ts"
38
38
  },
39
39
  "dependencies": {
40
- "@storybook/builder-webpack5": "8.0.0-rc.3",
41
- "@storybook/client-logger": "8.0.0-rc.3",
42
- "@storybook/core-common": "8.0.0-rc.3",
43
- "@storybook/core-events": "8.0.0-rc.3",
44
- "@storybook/core-server": "8.0.0-rc.3",
45
- "@storybook/core-webpack": "8.0.0-rc.3",
46
- "@storybook/docs-tools": "8.0.0-rc.3",
40
+ "@storybook/builder-webpack5": "8.0.0-rc.4",
41
+ "@storybook/client-logger": "8.0.0-rc.4",
42
+ "@storybook/core-common": "8.0.0-rc.4",
43
+ "@storybook/core-events": "8.0.0-rc.4",
44
+ "@storybook/core-server": "8.0.0-rc.4",
45
+ "@storybook/core-webpack": "8.0.0-rc.4",
46
+ "@storybook/docs-tools": "8.0.0-rc.4",
47
47
  "@storybook/global": "^5.0.0",
48
- "@storybook/node-logger": "8.0.0-rc.3",
49
- "@storybook/preview-api": "8.0.0-rc.3",
50
- "@storybook/telemetry": "8.0.0-rc.3",
51
- "@storybook/types": "8.0.0-rc.3",
48
+ "@storybook/node-logger": "8.0.0-rc.4",
49
+ "@storybook/preview-api": "8.0.0-rc.4",
50
+ "@storybook/telemetry": "8.0.0-rc.4",
51
+ "@storybook/types": "8.0.0-rc.4",
52
52
  "@types/node": "^18.0.0",
53
53
  "@types/react": "^18.0.37",
54
54
  "@types/react-dom": "^18.0.11",
@@ -1,6 +1,7 @@
1
1
  import type { Meta, StoryObj } from '@storybook/angular';
2
2
 
3
3
  import { HeaderComponent } from './header.component';
4
+ import { fn } from '@storybook/test';
4
5
 
5
6
  const meta: Meta<HeaderComponent> = {
6
7
  title: 'Example/Header',
@@ -11,6 +12,11 @@ const meta: Meta<HeaderComponent> = {
11
12
  // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
12
13
  layout: 'fullscreen',
13
14
  },
15
+ args: {
16
+ onLogin: fn(),
17
+ onLogout: fn(),
18
+ onCreateAccount: fn(),
19
+ },
14
20
  };
15
21
 
16
22
  export default meta;