Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
marcolink committed Feb 11, 2024
1 parent 4e4e88c commit cd17211
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const config: StorybookConfig = {
],
framework: {
name: "@storybook/react-vite",
options: {},
options: {
},
},
docs: {
autodocs: "tag",
Expand Down
6 changes: 3 additions & 3 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const preview: Preview = {
},
globals: {
contentfulPreview: {
space: "621006g5gybw",
accessToken: "UaqOlFCYE6lFHd_Cmvp2xD__UBceBcKA4j8KkFoCdac",
host: 'preview.contentful.com',
space: process.env.STORYBOOK_SPACE_ID,
accessToken: process.env.STORYBOOK_PREVIEW_TOKEN,
host: process.env.STORYBOOK_HOST,
// debugMode: true,
}
}
Expand Down
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,41 @@ This addon contributes the following parameters to Storybook, under the `content
| `livePreview` | `boolean` | Enables the live preview sdk | No |
| `argsMutator` | `function` | Mutator for the loaded entry data. By default, all fields will be populated as top-level args to the story | No |

#### Define Parameters
You can set the parameters globally, by adding the `contentfulPreview` parameter to the `globals` object of your `.storybook/preview.js` file.

```ts
import type {Preview} from "@storybook/react";

const preview: Preview = {
parameters: {
globals: {
contentfulPreview: {
space: "<space-id>",
accessToken: "<access-token>",
host: 'preview.contentful.com',
}
}
},
};

export default preview;
```

You can also set the parameters per story, by adding the `contentfulPreview` parameter to the story.

```ts
export default {
title: 'Button',
parameters: {
contentfulPreview: {
spaceId: 'your-space',
}
}
}
```
> The parameters set on the [story level will override the global](https://storybook.js.org/docs/writing-stories/parameters#rules-of-parameter-inheritance) parameters.
### Decorators

#### `withContentful`
Expand All @@ -57,7 +92,7 @@ export default {
title: 'Button',
decorators: [withContentful],
parameters: {
contentful: {
contentfulPreview: {
spaceId: 'your-space',
accessToken: 'your-access-token',
entryId: 'your-entry-id',
Expand All @@ -76,7 +111,7 @@ export default {
title: 'Button',
decorators: [withLivePreview, withContentful],
parameters: {
contentful: {
contentfulPreview: {
spaceId: 'your-space',
accessToken: 'your-access-token',
entryId: 'your-entry-id',
Expand All @@ -100,7 +135,7 @@ export default {
title: 'Button',
decorators: [withEntryArgMutator, withContentful],
parameters: {
contentful: {
contentfulPreview: {
spaceId: 'your-space',
accessToken: 'your-access-token',
entryId: 'your-entry-id',
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"tsup": "^8.0.1",
"typescript": "^5.2.2",
"vite": "^5.1.1",
"vite-plugin-environment": "^1.1.3",
"zx": "^7.2.3"
},
"publishConfig": {
Expand Down
12 changes: 10 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { defineConfig } from "vite";
import {defineConfig} from "vite";
import react from "@vitejs/plugin-react";
import EnvironmentPlugin from 'vite-plugin-environment'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [
react(),
EnvironmentPlugin([
'STORYBOOK_SPACE_ID',
'STORYBOOK_PREVIEW_TOKEN',
'STORYBOOK_HOST'
]),
],
});

0 comments on commit cd17211

Please sign in to comment.