Adding Global CSS to an Angular Library Storybook

saulodias

Saulo Dias

Posted on September 19, 2021

Adding Global CSS to an Angular Library Storybook

This tutorial assumes you have configured an Angular Library + Storybook following this post.

Most of the time, when creating components, you'll probably want to rely on some global css style. That enables you to use generic classes (like bootstrap classes), or theming and so on. However the Storybook documentation lacks examples on how to do it.

For this example we first have to install Bootstrap. Go to your workspace root folder and run npm install bootstrap.

Once you have done that, now you can link the boostrap css to your Storybook project.

To do so, you just have to add the css path to the styles in your angular.json file, in the styles list of your storybook project like in the following example.

"styles": ["node_modules/bootstrap/dist/css/bootstrap.min.css"],
Enter fullscreen mode Exit fullscreen mode

See the entire file and example workspace on Github.

I have edited the default MyLibComponent from the Angular Library basic example and it looks like this with the Bootstrap styling.
image

You might also want to check this out:

💖 💪 🙅 🚩
saulodias
Saulo Dias

Posted on September 19, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related