Skip to content

Commit 81efbcc

Browse files
committed
Extract from monorepo
1 parent c5dc049 commit 81efbcc

35 files changed

+9656
-28882
lines changed

README.md

Lines changed: 36 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,50 @@
1-
# Storybook Addon Kit
1+
# Storybook Addon Cssresources
22

3-
Simplify the creation of Storybook addons
3+
Storybook Addon Cssresources to switch between css resources at runtime for your story [Storybook](https://storybook.js.org).
44

5-
- 📝 Live-editing in development
6-
- ⚛️ React/JSX support
7-
- 📦 Transpiling and bundling with Babel
8-
- 🏷 Plugin metadata
9-
- 🚢 Release management with [Auto](https://github.com/intuit/auto)
10-
- 🧺 Boilerplate and sample code
5+
[Framework Support](https://github.com/storybookjs/storybook/blob/master/ADDONS_SUPPORT.md)
116

12-
## Getting Started
7+
![Storybook Addon Cssresources Demo](docs/demo.gif)
138

14-
Click the **Use this template** button to get started.
15-
16-
![](https://user-images.githubusercontent.com/42671/106809879-35b32000-663a-11eb-9cdc-89f178b5273f.gif)
17-
18-
Clone your repository and install dependencies.
9+
## Installation
1910

2011
```sh
21-
npm install
12+
yarn add -D @storybook/addon-cssresources
2213
```
2314

24-
### Development scripts
25-
26-
- `npm run start` runs babel in watch mode and starts Storybook
27-
- `npm run build` build and package your addon code
28-
29-
## What's included?
30-
31-
![Demo](https://user-images.githubusercontent.com/42671/107857205-e7044380-6dfa-11eb-8718-ad02e3ba1a3f.gif)
32-
33-
The addon code lives in `src`. It demonstrates all core addon related concepts. The three [UI paradigms](https://storybook.js.org/docs/react/addons/addon-types#ui-based-addons)
34-
35-
- `src/Tool.js`
36-
- `src/Panel.js`
37-
- `src/Tab.js`
38-
39-
Which, along with the addon itself, are registered in `src/preset/manager.js`.
40-
41-
Managing State and interacting with a story:
42-
43-
- `src/withGlobals.js` & `src/Tool.js` demonstrates how to use `useGlobals` to manage global state and modify the contents of a Story.
44-
- `src/withRoundTrip.js` & `src/Panel.js` demonstrates two-way communication using channels.
45-
- `src/Tab.js` demonstrates how to use `useParameter` to access the current story's parameters.
46-
47-
Your addon might use one or more of these patterns. Feel free to delete unused code. Update `src/preset/manager.js` and `src/preset/preview.js` accordingly.
48-
49-
Lastly, configure you addon name in `src/constants.js`.
50-
51-
### Metadata
52-
53-
Storybook addons are listed in the [catalog](https://storybook.js.org/addons) and distributed via npm. The catalog is populated by querying npm's registry for Storybook-specific metadata in `package.json`. This project has been configured with sample data. Learn more about available options in the [Addon metadata docs](https://storybook.js.org/docs/react/addons/addon-catalog#addon-metadata).
54-
55-
## Release Management
56-
57-
### Setup
15+
## Configuration
5816

59-
This project is configured to use [auto](https://github.com/intuit/auto) for release management. It generates a changelog and pushes it to both GitHub and npm. Therefore, you need to configure access to both:
17+
Then create a file called `main.js` in your storybook config.
6018

61-
- [`NPM_TOKEN`](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-access-tokens) Create a token with both _Read and Publish_ permissions.
62-
- [`GH_TOKEN`](https://github.com/settings/tokens) Create a token with the `repo` scope.
19+
Add following content to it:
6320

64-
Then open your `package.json` and edit the following fields:
65-
66-
- `name`
67-
- `author`
68-
- `repository`
69-
70-
#### Local
71-
72-
To use `auto` locally create a `.env` file at the root of your project and add your tokens to it:
73-
74-
```bash
75-
GH_TOKEN=<value you just got from GitHub>
76-
NPM_TOKEN=<value you just got from npm>
21+
```js
22+
module.exports = {
23+
addons: ['@storybook/addon-cssresources'],
24+
};
7725
```
7826

79-
Lastly, **create labels on GitHub**. You’ll use these labels in the future when making changes to the package.
80-
81-
```bash
82-
npx auto create-labels
83-
```
84-
85-
If you check on GitHub, you’ll now see a set of labels that `auto` would like you to use. Use these to tag future pull requests.
86-
87-
#### GitHub Actions
88-
89-
This template comes with GitHub actions already set up to publish your addon anytime someone pushes to your repository.
90-
91-
Go to `Settings > Secrets`, click `New repository secret`, and add your `NPM_TOKEN`.
92-
93-
### Creating a releasing
94-
95-
To create a release locally you can run the following command, otherwise the GitHub action will make the release for you.
96-
97-
```sh
98-
npm run release
27+
## Usage
28+
29+
You need add the all the css resources at compile time using the `withCssResources` decorator. They can be added globally or per story. You can then choose which ones to load from the cssresources addon UI:
30+
31+
```js
32+
import { withCssResources } from '@storybook/addon-cssresources';
33+
34+
export default {
35+
title: 'CssResources',
36+
parameters: {
37+
cssresources: [
38+
{
39+
id: `bluetheme`,
40+
code: `<style>body { background-color: lightblue; }</style>`,
41+
picked: false,
42+
hideCode: false, // Defaults to false, this enables you to hide the code snippet and only displays the style selector
43+
},
44+
],
45+
},
46+
decorators: [withCssResources],
47+
};
48+
49+
export const defaultView = () => <div />;
9950
```
100-
101-
That will:
102-
103-
- Build and package the addon code
104-
- Bump the version
105-
- Push a release to GitHub and npm
106-
- Push a changelog to GitHub

0 commit comments

Comments
 (0)