From 116fd4acd4a86e49d528644e6a375e2984da4007 Mon Sep 17 00:00:00 2001 From: Kyle Gach Date: Thu, 29 Feb 2024 10:32:34 -0700 Subject: [PATCH 1/2] Add react-vite framework doc --- code/frameworks/react-vite/README.md | 4 +- docs/get-started/react-vite.md | 140 ++++++++++++++++++ .../react/react-vite-add-framework.js.mdx | 8 + .../react/react-vite-add-framework.ts.mdx | 12 ++ .../react/react-vite-install.npm.js.mdx | 3 + .../react/react-vite-install.pnpm.js.mdx | 3 + .../react/react-vite-install.yarn.js.mdx | 3 + docs/toc.js | 5 + 8 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 docs/get-started/react-vite.md create mode 100644 docs/snippets/react/react-vite-add-framework.js.mdx create mode 100644 docs/snippets/react/react-vite-add-framework.ts.mdx create mode 100644 docs/snippets/react/react-vite-install.npm.js.mdx create mode 100644 docs/snippets/react/react-vite-install.pnpm.js.mdx create mode 100644 docs/snippets/react/react-vite-install.yarn.js.mdx diff --git a/code/frameworks/react-vite/README.md b/code/frameworks/react-vite/README.md index e8a35450aec9..272f8f50d55f 100644 --- a/code/frameworks/react-vite/README.md +++ b/code/frameworks/react-vite/README.md @@ -1 +1,3 @@ -# Storybook for React +# Storybook for React & Vite + +See [documentation](https://storybook.js.org/docs/8.0/get-started/react-vite?renderer=react) for installation instructions, usage examples, APIs, and more. \ No newline at end of file diff --git a/docs/get-started/react-vite.md b/docs/get-started/react-vite.md new file mode 100644 index 000000000000..edb6db8a9de3 --- /dev/null +++ b/docs/get-started/react-vite.md @@ -0,0 +1,140 @@ +--- +title: Storybook for React & Vite +--- + +export const SUPPORTED_RENDERER = 'react'; + +Storybook for React & Vite is a [framework](../contribute/framework.md) that makes it easy to develop and test UI components in isolation for [React](https://react.dev/) applications built with [Vite](https://vitejs.dev/). It includes: + +- 🏎️ Pre-bundled for performance +- πŸͺ„ Zero config +- πŸ’« and more! + + + + + +Storybook for React & Vite is only supported in [React](?renderer=react) projects. + + + + + + + + + +## Requirements + +- React β‰₯ 16.8 +- Vite β‰₯ 3.0 (4+ recommended) +- Storybook β‰₯ 7.0 + +## Getting started + +### In a project without Storybook + +Follow the prompts after running this command in your React project's root directory: + + + + + + + +[More on getting started with Storybook.](./install.md) + +### In a project with Storybook + +This framework is designed to work with Storybook 7+. If you’re not already using v7, upgrade with this command: + + + + + + + +#### Automatic migration + +When running the `upgrade` command above, you should get a prompt asking you to migrate to `@storybook/react-vite`, which should handle everything for you. In case that auto-migration does not work for your project, refer to the manual migration below. + +#### Manual migration + +First, install the framework: + + + + + + + +Then, update your `.storybook/main.js|ts` to change the framework property: + + + + + + + +## Run the Setup Wizard + +If all goes well, you should see a setup wizard that will help you get started with Storybook introducing you to the main concepts and features, including how the UI is organized, how to write your first story, and how to test your components' response to various inputs utilizing [controls](../essentials/controls). + +![Storybook onboarding](./example-onboarding-wizard.png) + +If you skipped the wizard, you can always run it again by adding the `?path=/onboarding` query parameter to the URL of your Storybook instance, provided that the example stories are still available. + +## API + +### Options + +You can pass an options object for additional configuration if needed: + +```ts +// .storybook/main.ts +import type { StorybookConfig } from '@storybook/react-vite'; + +const config: StorybookConfig = { + framework: { + name: '@storybook/react-vite', + options: { + // ... + }, + }, +}; + +export default config; +``` + +#### `builder` + +Type: `Record` + +Configure options for the [framework's builder](../api/main-config-framework.md#optionsbuilder). For this framework, available options can be found in the [Vite builder docs](../builders/vite.md). + + + + diff --git a/docs/snippets/react/react-vite-add-framework.js.mdx b/docs/snippets/react/react-vite-add-framework.js.mdx new file mode 100644 index 000000000000..7a268b5768f0 --- /dev/null +++ b/docs/snippets/react/react-vite-add-framework.js.mdx @@ -0,0 +1,8 @@ +```js +// .storybook/main.js +export default { + // ... + // framework: '@storybook/react-webpack5', πŸ‘ˆ Remove this + framework: '@storybook/react-vite', // πŸ‘ˆ Add this +}; +``` diff --git a/docs/snippets/react/react-vite-add-framework.ts.mdx b/docs/snippets/react/react-vite-add-framework.ts.mdx new file mode 100644 index 000000000000..c407f12cc0a7 --- /dev/null +++ b/docs/snippets/react/react-vite-add-framework.ts.mdx @@ -0,0 +1,12 @@ +```ts +// .storybook/main.ts +import { StorybookConfig } from '@storybook/react-vite'; + +const config: StorybookConfig = { + // ... + // framework: '@storybook/react-webpack5', πŸ‘ˆ Remove this + framework: '@storybook/react-vite', // πŸ‘ˆ Add this +}; + +export default config; +``` diff --git a/docs/snippets/react/react-vite-install.npm.js.mdx b/docs/snippets/react/react-vite-install.npm.js.mdx new file mode 100644 index 000000000000..6a9b052c19bb --- /dev/null +++ b/docs/snippets/react/react-vite-install.npm.js.mdx @@ -0,0 +1,3 @@ +```shell +npm install --save-dev @storybook/react-vite +``` diff --git a/docs/snippets/react/react-vite-install.pnpm.js.mdx b/docs/snippets/react/react-vite-install.pnpm.js.mdx new file mode 100644 index 000000000000..10b128bb0b31 --- /dev/null +++ b/docs/snippets/react/react-vite-install.pnpm.js.mdx @@ -0,0 +1,3 @@ +```shell +pnpm install --save-dev @storybook/react-vite +``` diff --git a/docs/snippets/react/react-vite-install.yarn.js.mdx b/docs/snippets/react/react-vite-install.yarn.js.mdx new file mode 100644 index 000000000000..a566adef61ba --- /dev/null +++ b/docs/snippets/react/react-vite-install.yarn.js.mdx @@ -0,0 +1,3 @@ +```shell +yarn add --dev @storybook/react-vite +``` diff --git a/docs/toc.js b/docs/toc.js index aecde723f11f..7b42d8d677e8 100644 --- a/docs/toc.js +++ b/docs/toc.js @@ -33,6 +33,11 @@ module.exports = { title: 'Next.js', type: 'link', }, + { + pathSegment: 'react-vite', + title: 'React & Vite', + type: 'link', + }, { pathSegment: 'vue3-vite', title: 'Vue & Vite', From 3586fc9b27833b275c7296cf7f38ae48a3ae1e35 Mon Sep 17 00:00:00 2001 From: Kyle Gach Date: Thu, 7 Mar 2024 10:41:56 -0700 Subject: [PATCH 2/2] Address comments --- docs/get-started/react-vite.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/get-started/react-vite.md b/docs/get-started/react-vite.md index edb6db8a9de3..9fbe5eca53af 100644 --- a/docs/get-started/react-vite.md +++ b/docs/get-started/react-vite.md @@ -27,8 +27,8 @@ Storybook for React & Vite is only supported in [React](?renderer=react) project ## Requirements - React β‰₯ 16.8 -- Vite β‰₯ 3.0 (4+ recommended) -- Storybook β‰₯ 7.0 +- Vite β‰₯ 4.0 +- Storybook β‰₯ 8.0 ## Getting started