Skip to content

Commit

Permalink
docs: Improve Storybook docs
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Oct 24, 2024
1 parent 70023b0 commit 4472ea1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
47 changes: 39 additions & 8 deletions docs/src/pages/docs/workflows/storybook.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,46 @@ import Image from 'next/image';

# Storybook integration for `next-intl`

[Storybook](https://storybook.js.org/) is a tool for developing UI components in isolation.
[Storybook](https://storybook.js.org/) is a tool for developing UI components in isolation and can be used in combination with `next-intl` to handle components that rely on internationalization.

If you like to set up stories for components that use `next-intl`, you can use [`storybook-next-intl`](https://github.com/stevensacks/storybook-next-intl), a community-maintained addon that configures Storybook accordingly for you.
## Manual setup

To set up Storybook for `next-intl`, you can configure a [global decorator](https://storybook.js.org/docs/writing-stories/decorators#global-decorators) that renders [`NextIntlClientProvider`](/docs/usage/configuration#nextintlclientprovider) to wrap your stories accordingly:

```tsx filename=".storybook/preview.tsx"
import {Preview} from '@storybook/react';
import defaultMessages from '../messages/en.json';

const preview: Preview = {
decorators: [
(Story) => (
<NextIntlClientProvider
locale="en"
messages={defaultMessages}
// ... potentially other config
>
<Story />
</NextIntlClientProvider>
)
]
};

export default preview;
```

With this setup in place, you're able to render components that use hook-based APIs like `useTranslations`.

Note that support for async Server Components is currently [experimental](https://storybook.js.org/docs/get-started/frameworks/nextjs#react-server-components-rsc) in Storybook and might require additional configuration.

<Callout>

**Tip:** If you declare components that render as Server Components in your app via [non-async components](/docs/environments/server-client-components#shared-components), these components can render as Client Components in Storybook and will consume configuration from `NextIntlClientProvider`.

</Callout>

## `storybook-next-intl`

Alternatively to setting up the global decorator yourself, you can use [`storybook-next-intl`](https://github.com/stevensacks/storybook-next-intl), a community-maintained addon that configures Storybook accordingly for you.

**Features**

Expand All @@ -19,9 +56,3 @@ If you like to set up stories for components that use `next-intl`, you can use [
height={1128}
alt="Storybook integration for next-intl"
/>

<Callout>

**Tip:** If you declare components that render as Server Components in your app via non-async functions, these components can render as Client Components in Storybook and will consume configuration from `NextIntlClientProvider` (see also: [Non-async components](/docs/environments/server-client-components#shared-components)).

</Callout>
2 changes: 1 addition & 1 deletion docs/src/pages/docs/workflows/vscode-integration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ These extensions are known to support `next-intl`:
- Inline annotations
- Inline message editing
- [Message linting](https://inlang.com/m/r7kp499g/app-inlang-ideextension#message-linting?ref=next-intl)
- Integration with other parts of the inlang ecosystem like [the Fink editor](https://inlang.com/m/tdozzpar/app-inlang-editor?ref=next-intl) or [the inlang CLI](https://inlang.com/m/2qj2w8pu/app-inlang-cli?ref=next-intl)
- Integration with other parts of the inlang ecosystem like [the inlang CLI](https://inlang.com/m/2qj2w8pu/app-inlang-cli?ref=next-intl)

**Setup:**

Expand Down

0 comments on commit 4472ea1

Please sign in to comment.