Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Add Preact-vite framework docs #30271

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/_snippets/preact-vite-add-framework.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```js filename=".storybook/main.js" renderer="react" language="js"
export default {
// ...
// framework: '@storybook/preact-webpack5', 👈 Remove this
framework: '@storybook/preact-vite', // 👈 Add this
};
```
Comment on lines +1 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: renderer should be 'preact' instead of 'react' since this is Preact-specific documentation


```ts filename=".storybook/main.ts" renderer="react" language="ts"
import { StorybookConfig } from '@storybook/preact-vite';

const config: StorybookConfig = {
// ...
// framework: '@storybook/preact-webpack5', 👈 Remove this
framework: '@storybook/preact-vite', // 👈 Add this
};

export default config;
```
Comment on lines +9 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: renderer should be 'preact' instead of 'react' since this is Preact-specific documentation

25 changes: 25 additions & 0 deletions docs/_snippets/preact-vite-framework-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
```js filename=".storybook/main.js" renderer="preact" language="js"
export default {
framework: {
name: '@storybook/preact-vite',
options: {
// ...
},
},
};
```

```ts filename=".storybook/main.ts" renderer="preact" language="ts"
import type { StorybookConfig } from '@storybook/preact-vite';

const config: StorybookConfig = {
framework: {
name: '@storybook/preact-vite',
options: {
// ...
},
},
};

export default config;
```
11 changes: 11 additions & 0 deletions docs/_snippets/preact-vite-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```shell renderer="react" language="js" packageManager="npm"
npm install --save-dev @storybook/preact-vite
```

```shell renderer="react" language="js" packageManager="pnpm"
pnpm add --save-dev @storybook/preact-vite
```

```shell renderer="react" language="js" packageManager="yarn"
yarn add --dev @storybook/preact-vite
```
102 changes: 102 additions & 0 deletions docs/get-started/frameworks/preact-vite.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
title: Storybook for Preact & Vite
sidebar:
order: 13
title: Preact & Vite
---

Storybook for Preact & Vite is a [framework](../../contribute/framework.mdx) that makes it easy to develop and test UI components in isolation for [Preact](https://preactjs.com/) applications built with [Vite](https://vitejs.dev/). It includes:

* 🏎️ Pre-bundled for performance
* 🪄 Zero config
* 💫 and more!

<If notRenderer="Preact">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Case mismatch in notRenderer="Preact" - should be lowercase 'preact' to match renderer="preact" usage below

<Callout variant="info">
Storybook for Preact & Vite is only supported in [Preact](?renderer=preact) projects.
</Callout>

{/* End non-supported renderers */}
</If>

<If renderer="preact">
## Requirements

* Preact 8.x || 10.x
* Vite ≥ 4.0
* Storybook ≥ 8.0

## Getting started

### In a project without Storybook

Follow the prompts after running this command in your React project's root directory:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: 'React project' should be 'Preact project' since this is Preact-specific documentation


{/* prettier-ignore-start */}

<CodeSnippets path="init-command.md" />

{/* prettier-ignore-end */}

[More on getting started with Storybook.](../install.mdx)

### 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:

{/* prettier-ignore-start */}

<CodeSnippets path="storybook-upgrade.md" />

{/* prettier-ignore-end */}

#### Automatic migration

When running the `upgrade` command above, you should get a prompt asking you to migrate to `@storybook/preact-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:

{/* prettier-ignore-start */}

<CodeSnippets path="preact-vite-install.md" />

{/* prettier-ignore-end */}

Then, update your `.storybook/main.js|ts` to change the framework property:

{/* prettier-ignore-start */}

<CodeSnippets path="preact-vite-add-framework.md" />

{/* prettier-ignore-end */}

## 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.mdx).

![Storybook onboarding](../../_assets/get-started/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:

{/* prettier-ignore-start */}

<CodeSnippets path="preact-vite-framework-options.md" />

{/* prettier-ignore-end */}

#### `builder`

Type: `Record<string, any>`

Configure options for the [framework's builder](../../api/main-config/main-config-framework.mdx#optionsbuilder). For this framework, available options can be found in the [Vite builder docs](../../builders/vite.mdx).

{/* End supported renderers */}
</If>
Loading