Skip to content

Commit

Permalink
Merge pull request #8 from storybookjs/feature/support-storybook7
Browse files Browse the repository at this point in the history
Feat: Upgrade to support Storybook 7
  • Loading branch information
yannbf committed Mar 13, 2024
2 parents bd05e28 + 2d9e4a2 commit ec752a0
Show file tree
Hide file tree
Showing 25 changed files with 11,102 additions and 9,309 deletions.
7 changes: 0 additions & 7 deletions .babelrc.js

This file was deleted.

10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Prepare repository
run: git fetch --unshallow --tags

- name: Use Node.js 14.x
uses: actions/setup-node@v1
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- name: Install dependencies
uses: bahmutov/npm-install@v1
run: yarn install

- name: Create Release
env:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ node_modules/
storybook-static/
build-storybook.log
.DS_Store
.env
.env

.yarn/install-state.gz
7 changes: 0 additions & 7 deletions .storybook/main.js

This file was deleted.

15 changes: 15 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { join } from "path";
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
stories: ["../src/**/*.stories.@(js|jsx|ts|tsx)"],
addons: [join(__dirname, "..")],
framework: {
name: "@storybook/react-vite",
options: {},
},
docs: {
autodocs: "tag",
},
};
export default config;
893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.1.1.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.1.1.cjs
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Storybook contributors
Copyright (c) 2023 Storybook contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 26 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h1>Migration</h1>

- [From version 7.x to 8.0.0](#from-version-7x-to-800)
- [`withQuery` decorator removed](#withquery-decorator-removed)

## From version 7.x to 8.0.0

### `withQuery` decorator removed

The `withQuery` decorator is not necessary anymore and therefore its export was removed from the package. It's an internally defined decorator which is automatically applied to every story you have. Please remove from your stories/preview files:

```diff
import React from "react";
import { Button } from "../Button";
-import { withQuery } from "@storybook/addon-queryparams";

export default {
title: "Button",
component: Button,
- decorators: [withQuery],
parameters: {
query: {
greeting: "Hello world!",
},
},
};
56 changes: 13 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,40 @@
# storybook-addon-queryparams
# @storybook/addon-queryparams

This storybook addon can be helpful if your components need special query parameters to work the way you want them to. It allows you to mock query params per story so that you can easily reproduce different states of your component.
This Storybook addon can be helpful if your components need special query parameters to work the way you want them to. It allows you to mock query params per story so that you can easily reproduce different states of your component.

## Getting started

First, install the addon.

```sh
$ yarn add @storybook/addon-queryparams --dev
$ npx storybook@latest add @storybook/addon-queryparams
```

Register it by adding it in the addons attribute in your `main.js` file (create this file inside your storybook config directory if needed).
In your story, define the query parameters you want to mock via the `query` special parameter:

```js
module.exports = {
addons: ["@storybook/addon-queryparams"],
};
```

In your story, add the `withQuery` decorator and define the query parameters you want to mock:

```js
```ts
import React from "react";
import { Button } from "@storybook/react/demo";
import { withQuery } from "@storybook/addon-queryparams";
import { Button } from "../Button";

export default {
title: "Button",
component: Button,
decorators: [withQuery],
parameters: {
query: {
mock: "Hello world!",
// example of mocking ?greeting="Hello world!"
greeting: "Hello world!",
},
},
};

export const WithMockedSearch = () => {
const urlParams = new URLSearchParams(document.location.search);
const mockedParam = urlParams.get("mock");
return <div>Mocked value: {mockedParam}</div>;
};
```

<details>
<summary>Example with storiesOf API</summary>

```js
import React from "react";
import { storiesOf } from "@storybook/react";

storiesOf("button", module)
.addParameters({
query: {
mock: "Hello World!",
},
})
.add("Prints the mocked parameter", () => {
export const WithMockedSearch = {
render: () => {
const urlParams = new URLSearchParams(document.location.search);
const mockedParam = urlParams.get("mock");
const mockedParam = urlParams.get("greeting");
return <div>Mocked value: {mockedParam}</div>;
});
}
}
```

</details>

## Credits

While this addon was part of the [Storybook monorepo](https://github.com/storybookjs/storybook), it received commits from the following authors:
Expand Down
23 changes: 0 additions & 23 deletions check-metadata.js

This file was deleted.

122 changes: 72 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,78 +1,100 @@
{
"name": "storybook-addon-kit",
"version": "0.0.0",
"description": "everything you need to build a Storybook addon",
"name": "@storybook/addon-queryparams",
"version": "7.0.0",
"description": "addon to mock queryparams in storybook",
"keywords": [
"storybook-addons",
"style",
"test"
"queryparams"
],
"repository": {
"type": "git",
"url": "https://github.com/storybookjs/storybook-addon-kit"
"url": "https://github.com/storybookjs/addon-queryparams"
},
"license": "MIT",
"author": "winkerVSbecks",
"main": "dist/preset",
"author": "storybook-addon-queryparams",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
},
"./preview": {
"types": "./dist/index.d.ts",
"import": "./dist/preview.js",
"require": "./dist/preview.cjs"
},
"./package.json": "./package.json"
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"README.md",
"*.js"
"*.js",
"*.d.ts"
],
"scripts": {
"buildBabel": "babel ./src --out-dir ./dist --extensions \".js,.jsx,.ts,.tsx\"",
"buildTsc": "tsc --declaration --emitDeclarationOnly --outDir ./dist",
"build": "yarn buildBabel && yarn buildTsc",
"build-storybook": "build-storybook",
"clean": "rimraf ./dist",
"prerelease": "node check-metadata.js",
"release": "yarn build && auto shipit",
"start": "concurrently \"yarn storybook --no-manager-cache --quiet\" \"yarn build --watch\"",
"storybook": "start-storybook -p 6006",
"test": "echo \"Error: no test specified\" && exit 1"
"build": "tsup",
"build-storybook": "storybook build",
"build:watch": "npm run build -- --watch",
"release": "npm run build && auto shipit",
"start": "run-p build:watch 'storybook --quiet'",
"storybook": "storybook dev -p 6006"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.5",
"@babel/preset-typescript": "^7.13.0",
"@storybook/react": "^6.1.14",
"auto": "^10.3.0",
"babel-loader": "^8.1.0",
"chalk": "^2.4.2",
"concurrently": "^5.3.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"rimraf": "^3.0.2",
"typescript": "^4.2.4"
"@storybook/manager": "^8.0.0-rc.2",
"@storybook/manager-api": "^8.0.0-rc.2",
"@storybook/preview": "^8.0.0-rc.2",
"@storybook/preview-api": "^8.0.0-rc.2",
"@storybook/react": "^8.0.0-rc.2",
"@storybook/react-vite": "^8.0.0-rc.2",
"@types/node": "^18.15.0",
"@types/react": "^18.0.34",
"@vitejs/plugin-react": "^4.2.1",
"auto": "^11.1.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"storybook": "^8.0.0-rc.2",
"tsup": "^8.0.2",
"typescript": "^5.3.3",
"vite": "^5.1.5"
},
"peerDependencies": {
"@storybook/addons": "^6.1.14",
"@storybook/api": "^6.1.14",
"@storybook/components": "^6.1.14",
"@storybook/core-events": "^6.1.14",
"@storybook/theming": "^6.1.14",
"react": "^16.8.0 || ^17.0.0",
"react-dom": "^16.8.0 || ^17.0.0"
},
"peerDependenciesMeta": {
"react": {
"optional": true
},
"react-dom": {
"optional": true
}
"@storybook/manager-api": "^7.0.0 || ^8.0.0 || ^8.0.0-rc.0",
"@storybook/preview-api": "^7.0.0 || ^8.0.0 || ^8.0.0-rc.0"
},
"publishConfig": {
"access": "public"
},
"auto": {
"plugins": [
"npm"
]
},
"bundler": {
"exportEntries": [
"src/index.ts"
],
"previewEntries": [
"src/preview.ts"
]
},
"storybook": {
"displayName": "Addon Kit",
"displayName": "storybook-addon-queryparams",
"supportedFrameworks": [
"react",
"vue",
"angular"
"angular",
"web-components",
"ember",
"html",
"svelte",
"preact",
"react-native"
],
"icon": "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png"
}
Expand Down
9 changes: 0 additions & 9 deletions preset.js

This file was deleted.

1 change: 1 addition & 0 deletions preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/preview";
3 changes: 1 addition & 2 deletions src/constants.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export const ADDON_ID = 'storybook/queryparams';
export const PANEL_ID = `${ADDON_ID}/panel`;
export const PARAM_KEY = `query`;
export const PARAM_KEY = `query`;

0 comments on commit ec752a0

Please sign in to comment.