Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/storybookjs/addon-styling

A base addon for configuring popular styling tools
https://github.com/storybookjs/addon-styling

addon css postcss scss storybook styling theme-switcher

Last synced: about 8 hours ago
JSON representation

A base addon for configuring popular styling tools

Awesome Lists containing this project

README

        

⚠️ **This addon is officially deprecated** ⚠️

Since it's release, addon-styling has been a great way to get your styles configured in Storybook. However, as the addon quickly evolved, it became clear that it was trying to do too much. It was trying to be a configuration tool, a theming tool, and a housed bulky code mods as well. This made it difficult to maintain and added a lot of dependencies that most users didn't need.

To address this, I've split the addon into two separate addons, [`@storybook/addon-styling-webpack`](https://github.com/storybookjs/addon-styling-webpack) and [`@storybook/addon-themes`](https://github.com/storybookjs/storybook/tree/next/code/addons/themes). These addons are much more focused and will allow us to iterate on them more quickly.

`@storybook/addon-styling-webpack` will be specifically for configuring your **Webpack based Storybooks** with popular tools like Tailwind, Post CSS, SCSS, Less, and Vanilla-extract.

`@storybook/addon-themes` will be focused on providing and switching between multiple themes in Storybook regardless of what building tool that you use.

I've also moved the codemods to a separate package so that they can be used through `npx`/ `yarn dlx` / `pnpm dlx` without having a bulky codemod staying in your `node_modules`.

I've added a [migration guide](https://github.com/storybookjs/addon-styling/blob/main/MIGRATION.md) to help you migrate to the new addons. If you have any questions, please feel free to reach out to me on [Twitter](https://twitter.com/integrayshaun) or the support channel in the [Storybook Discord](https://discord.com/channels/486522875931656193/1035683992684478534).

All the best,
Shaun Evening

---

# `@storybook/addon-styling`

Get started in Storybook 7 faster with popular styling tools.

**Using Storybook 6?** Check out the [`release-0-3` branch](https://github.com/storybookjs/addon-styling/tree/release-0-3)

![Toggling between themes](./.github/media/styles-addon.gif)

## ✨ Features

- 🤖 Zero-config for popular tools through codemods. [Read more](https://github.com/storybookjs/addon-styling/tree/main/docs/auto-configuration.md).
- 🧩 Configuration templates for popular tools
- ⚡️ Options for css modules, postCss, Sass, and Less
- 🎨 Provide themes
- 🔄 Toggle between multiple themes when more than one is provided
- ❗️ Override theme at the component and story level through parameters

## 🏁 Getting Started

To get started, **install the package** as a dev dependency

yarn:

```zsh
yarn add -D @storybook/addon-styling
```

npm:

```zsh
npm install -D @storybook/addon-styling
```

pnpm:

```zsh
pnpm add -D @storybook/addon-styling
```

Then, **include the addon** in your `.storybook/main.js` file

```diff
module.exports = {
stories: [
"../stories/**/*.stories.mdx",
"../stories/**/*.stories.@(js|jsx|ts|tsx)",
],
addons: [
"@storybook/addon-essentials",
+ "@storybook/addon-styling"
],
};
```

### 👇 Tool specific configuration

For tool-specific setup, check out the recipes below

- [`@emotion/styled`](https://github.com/storybookjs/addon-styling/tree/main/docs/getting-started/emotion.md)
- [`@mui/material`](https://github.com/storybookjs/addon-styling/tree/main/docs/getting-started/material-ui.md)
- [`bootstrap`](https://github.com/storybookjs/addon-styling/tree/main/docs/getting-started/bootstrap.md)
- [`cssModules`](https://github.com/storybookjs/addon-styling/blob/main/docs/api.md#optionscssmodules)
- [`less`](https://github.com/storybookjs/addon-styling/blob/main/docs/api.md#optionsless)
- [`postcss`](https://github.com/storybookjs/addon-styling/blob/main/docs/api.md#optionspostcss)
- [`sass`](https://github.com/storybookjs/addon-styling/blob/main/docs/api.md#optionssass)
- [`styled-components`](https://github.com/storybookjs/addon-styling/tree/main/docs/getting-started/styled-components.md)
- [`tailwind`](https://github.com/storybookjs/addon-styling/tree/main/docs/getting-started/tailwind.md)
- [`[email protected]`](./docs/api.md#writing-a-custom-decorator)

Don't see your favorite tool listed? Don't worry! That doesn't mean this addon isn't for you. Check out the ["Writing a custom decorator"](https://github.com/storybookjs/addon-styling/blob/main/docs/api.md#writing-a-custom-decorator) section of the [api reference](https://github.com/storybookjs/addon-styling/blob/main/docs/api.md).

### ❗️ Overriding theme

If you want to override your theme for a particular component or story, you can use the `theming.themeOverride` parameter.

```js
import React from "react";
import { Button } from "./Button";

export default {
title: "Example/Button",
component: Button,
parameters: {
theming: {
themeOverride: "light", // component level override
},
},
};

const Template = (args) => ;

export const Primary = Template.bind({});
Primary.args = {
primary: true,
label: "Button",
};

export const PrimaryDark = Template.bind({});
PrimaryDark.args = {
primary: true,
label: "Button",
};
PrimaryDark.parameters = {
theming: {
themeOverride: "dark", // Story level override
},
};
```

## 🤝 Contributing

If you'd like to contribute to this addon, **THANK YOU**, I'd love your help 🙏

### 📝 Development scripts

- `yarn start` runs babel in watch mode and starts Storybook
- `yarn build` build and package your addon code

### 🌲 Branch structure

- **next** - the `next` version on npm, and the development branch where most work occurs
- **main** - the `latest` version on npm and the stable version that most users use

### 🚀 Release process

1. All PRs should target the `next` branch, which depends on the `next` version of Storybook.
2. When merged, a new version of this package will be released on the `next` NPM tag.
3. If the change contains a bugfix that needs to be patched back to the stable version, please note that in PR description.
4. PRs labeled `pick` will get cherry-picked back to the `main` branch and will generate a release on the `latest` npm tag.