-
-
Notifications
You must be signed in to change notification settings - Fork 0
Use Storybook with Angular
Tyler Ruff edited this page Oct 25, 2022
·
3 revisions
Using Storybook to manage component design is quite simple.
- First, navigate to your project's root directory and run:
npx storybook init
This will spin up a Storybook project in the current working directory.
- Update your project's angular.json file with the following:
{
"storybook": {
"builder": "@storybook/angular:start-storybook",
"options": {
"browserTarget": "angular-cli:build",
"port": 6006
}
},
"build-storybook": {
"builder": "@storybook/angular:build-storybook",
"options": {
"browserTarget": "angular-cli:build"
}
}
}
- Next, run:
npm run storybook
Once the server has fully started up, navigate to localhost:6006.
Now you can begin to create stories for your Angular components:
import { BrowserModule } from '@angular/platform-browser';
import { HeaderComponent } from "./header.component";
import { moduleMetadata } from '@storybook/angular';
export default {
title: 'Header',
decorators: [
moduleMetadata({
declarations: [
HeaderComponent
],
imports: [
BrowserModule
]
}),
],
};
export const Main = () => ({
template: `
<app-header></app-header>
`
});
Note: If you run in to an error such as "System Limit for Number of File Watchers", follow the steps below:
sudo nano /etc/sysctl.conf
Add the following line at the bottom:
fs.inotify.max_user_watches=524288
And then save & exit.
Join the Blazed Development Group today to get involved in open source collaborative projects.
Discover our FREE learning resources, the Blazed University, Web Development School, and Blazed City.