Skip to content

Commit

Permalink
add migration notes
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Mar 13, 2024
1 parent 622d641 commit 2d9e4a2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
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!",
},
},
};
36 changes: 14 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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.

Expand All @@ -7,40 +7,32 @@ This Storybook addon can be helpful if your components need special query parame
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>;
};
export const WithMockedSearch = {
render: () => {
const urlParams = new URLSearchParams(document.location.search);
const mockedParam = urlParams.get("greeting");
return <div>Mocked value: {mockedParam}</div>;
}
}
```

## Credits
Expand Down

0 comments on commit 2d9e4a2

Please sign in to comment.