Skip to content

Commit 645653d

Browse files
committed
cleanup + initial readme
1 parent 6e52ee3 commit 645653d

File tree

6 files changed

+42
-109
lines changed

6 files changed

+42
-109
lines changed

README.md

Lines changed: 35 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,48 @@
11
# Storybook Addon StackBlitz
22
Create a one-click Pull Request environment right from your component
33

4-
### Development scripts
4+
## How to use it?
55

6-
- `yarn start` runs babel in watch mode and starts Storybook
7-
- `yarn build` build and package your addon code
8-
9-
### Switch from TypeScript to JavaScript
10-
11-
Don't want to use TypeScript? We offer a handy eject command: `yarn eject-ts`
12-
13-
This will convert all code to JS. It is a destructive process, so we recommended running this before you start writing any code.
14-
15-
## What's included?
16-
17-
![Demo](https://user-images.githubusercontent.com/42671/107857205-e7044380-6dfa-11eb-8718-ad02e3ba1a3f.gif)
18-
19-
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)
20-
21-
- `src/Tool.tsx`
22-
- `src/Panel.tsx`
23-
- `src/Tab.tsx`
24-
25-
Which, along with the addon itself, are registered in `src/manager.ts`.
26-
27-
Managing State and interacting with a story:
28-
29-
- `src/withGlobals.ts` & `src/Tool.tsx` demonstrates how to use `useGlobals` to manage global state and modify the contents of a Story.
30-
- `src/withRoundTrip.ts` & `src/Panel.tsx` demonstrates two-way communication using channels.
31-
- `src/Tab.tsx` demonstrates how to use `useParameter` to access the current story's parameters.
32-
33-
Your addon might use one or more of these patterns. Feel free to delete unused code. Update `src/manager.ts` and `src/preview.ts` accordingly.
34-
35-
Lastly, configure you addon name in `src/constants.ts`.
36-
37-
### Metadata
38-
39-
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).
40-
41-
## Release Management
6+
Add the following to your `.storybook/main.ts` exports:
427

43-
### Setup
44-
45-
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:
46-
47-
- [`NPM_TOKEN`](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-access-tokens) Create a token with both _Read and Publish_ permissions.
48-
- [`GH_TOKEN`](https://github.com/settings/tokens) Create a token with the `repo` scope.
49-
50-
Then open your `package.json` and edit the following fields:
51-
52-
- `name`
53-
- `author`
54-
- `repository`
55-
56-
#### Local
57-
58-
To use `auto` locally create a `.env` file at the root of your project and add your tokens to it:
59-
60-
```bash
61-
GH_TOKEN=<value you just got from GitHub>
62-
NPM_TOKEN=<value you just got from npm>
8+
```typescript
9+
export default {
10+
addons: ['@storybook/addon-storysource'],
11+
};
6312
```
6413

65-
Lastly, **create labels on GitHub**. You’ll use these labels in the future when making changes to the package.
66-
67-
```bash
68-
npx auto create-labels
14+
Configure the repository URL in the `.storybook/preview.ts`:
15+
```typescript
16+
export default {
17+
parameters: {
18+
repositoryUrl: 'https://github.com/[username]/[reponame]'
19+
},
20+
};
6921
```
7022

71-
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.
72-
73-
#### GitHub Actions
74-
75-
This template comes with GitHub actions already set up to publish your addon anytime someone pushes to your repository.
76-
77-
Go to `Settings > Secrets`, click `New repository secret`, and add your `NPM_TOKEN`.
78-
79-
### Creating a release
80-
81-
To create a release locally you can run the following command, otherwise the GitHub action will make the release for you.
23+
In your story files set the file path for the specific story, for instance:
24+
```typescript
25+
export const Primary: Story = {
26+
args: {/* ... */},
27+
parameters: {
28+
filePath: 'src/stories/Button.tsx'
29+
}
30+
};
31+
```
8232

83-
```sh
84-
yarn release
33+
If your components are placed in multiple repositories, you can also define the repository URL per the specific story:
34+
```typescript
35+
export const Primary: Story = {
36+
args: {/* ... */},
37+
parameters: {
38+
filePath: 'src/stories/Button.tsx',
39+
repositoryUrl: 'https://github.com/[username]/[reponame]'
40+
}
41+
};
8542
```
8643

87-
That will:
8844

89-
- Build and package the addon code
90-
- Bump the version
91-
- Push a release to GitHub and npm
92-
- Push a changelog to GitHub
45+
## Development scripts
46+
47+
- `yarn start` runs babel in watch mode and starts Storybook
48+
- `yarn build` build and package your addon code

assets/icon.png

135 KB
Loading

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"version": "0.0.0",
44
"description": "Create a one-click Pull Request environment right from your component",
55
"keywords": [
6+
"storybook-addons",
67
"stackblitz",
78
"pull-request",
89
"ide",
9-
"code",
10-
"storybook-addons"
10+
"code"
1111
],
1212
"repository": {
1313
"type": "git",

src/Tool.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { PARAM_KEY, TOOL_ID } from "./constants";
55
import CodeflowLogo from "./components/CodeflowLogo";
66

77
export const Tool = function MyAddonSelector() {
8-
const repositoryUrl = useParameter<string>(PARAM_KEY.REPO, null);
8+
const repositoryUrl = useParameter<string>(PARAM_KEY.REPO);
99
const branch = useParameter<string>(PARAM_KEY.BRANCH, 'main');
10-
const filePath = useParameter<string>(PARAM_KEY.FILE_PATH, null);
10+
const filePath = useParameter<string>(PARAM_KEY.FILE_PATH);
1111

1212
const api = useStorybookApi();
1313
const [disabled, setDisabled] = useState(false)
@@ -42,7 +42,7 @@ export const Tool = function MyAddonSelector() {
4242
href={stackblitzUrl}
4343
onClick={(e: MouseEvent) => disabled && e.preventDefault()}
4444
target="_blank"
45-
title="Open in StackBlitz and make a pull request"
45+
title="Open in StackBlitz instant dev environment"
4646
>
4747
<CodeflowLogo style={{width: 18, margin: '0 -2px'}} />
4848
</IconButton>

src/manager.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@ import { addons, types } from "@storybook/manager-api";
22
import { ADDON_ID, TOOL_ID } from "./constants";
33
import { Tool } from "./Tool";
44

5-
/**
6-
* Note: if you want to use JSX in this file, rename it to `manager.tsx`
7-
* and update the entry prop in tsup.config.ts to use "src/manager.tsx",
8-
*/
9-
10-
// Register the addon
115
addons.register(ADDON_ID, () => {
12-
// Register the tool
136
addons.add(TOOL_ID, {
147
type: types.TOOL,
15-
title: "My addon",
8+
title: "StackBlitz",
169
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
1710
render: Tool
1811
});
19-
2012
});

src/preview.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
/**
2-
* A decorator is a way to wrap a story in extra “rendering” functionality. Many addons define decorators
3-
* in order to augment stories:
4-
* - with extra rendering
5-
* - gather details about how a story is rendered
6-
*
7-
* When writing stories, decorators are typically used to wrap stories with extra markup or context mocking.
8-
*
9-
* https://storybook.js.org/docs/react/writing-stories/decorators
10-
*/
111
import type { Renderer, ProjectAnnotations } from "@storybook/types";
122
import { PARAM_KEY } from "./constants";
133

14-
/**
15-
* Note: if you want to use JSX in this file, rename it to `preview.tsx`
16-
* and update the entry prop in tsup.config.ts to use "src/preview.tsx",
17-
*/
18-
194
const preview: ProjectAnnotations<Renderer> = {
205
parameters: {
21-
repositoryUrl: 'https://github.com/sulco/viteconf-storybook-demo',
6+
// [PARAM_KEY.REPO]: 'https://github.com/[username]/[reponame]',
227
}
238
};
249

0 commit comments

Comments
 (0)