Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Update storybook settings for app router
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed May 22, 2024
1 parent 9d2e08a commit 39f115d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 70 deletions.
30 changes: 30 additions & 0 deletions frontend/.storybook/I18nStoryWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @file Storybook decorator, enabling internationalization for each story.
* @see https://storybook.js.org/docs/writing-stories/decorators
*/
import { StoryContext } from "@storybook/react";

import { NextIntlClientProvider } from "next-intl";
import React from "react";

import { defaultLocale, formats, timeZone } from "../src/i18n/config";

const I18nStoryWrapper = (
Story: React.ComponentType,
context: StoryContext,
) => {
const locale = (context.globals.locale as string) ?? defaultLocale;

return (
<NextIntlClientProvider
formats={formats}
timeZone={timeZone}
locale={locale}
messages={context.loaded.messages as undefined}
>
<Story />
</NextIntlClientProvider>
);
};

export default I18nStoryWrapper;
22 changes: 0 additions & 22 deletions frontend/.storybook/i18next.js

This file was deleted.

6 changes: 1 addition & 5 deletions frontend/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ function blockSearchEnginesInHead(head) {
*/
const config = {
stories: ["../stories/**/*.stories.@(mdx|js|jsx|ts|tsx)"],
addons: [
"@storybook/addon-essentials",
"storybook-react-i18next",
"@storybook/addon-designs",
],
addons: ["@storybook/addon-essentials", "@storybook/addon-designs"],
framework: {
name: "@storybook/nextjs",
options: {
Expand Down
43 changes: 0 additions & 43 deletions frontend/.storybook/preview.js

This file was deleted.

64 changes: 64 additions & 0 deletions frontend/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @file Setup the toolbar, styling, and global context for each Storybook story.
* @see https://storybook.js.org/docs/configure#configure-story-rendering
*/
import { Loader, Preview } from "@storybook/react";

import "../src/styles/styles.scss";

import { defaultLocale, locales } from "../src/i18n/config";
import { getMessagesWithFallbacks } from "../src/i18n/getMessagesWithFallbacks";
import I18nStoryWrapper from "./I18nStoryWrapper";

const parameters = {
nextjs: {
appDirectory: true,
},
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
options: {
storySort: {
method: "alphabetical",
order: [
"Welcome",
"Core",
// Storybook infers the title when not explicitly set, but is case-sensitive
// so we need to explicitly set both casings here for this to properly sort.
"Components",
"components",
"Templates",
"Pages",
"pages",
],
},
},
};

const i18nMessagesLoader: Loader = async (context) => {
const messages = await getMessagesWithFallbacks(
context.globals.locale as string,
);
return { messages };
};

const preview: Preview = {
loaders: [i18nMessagesLoader],
decorators: [I18nStoryWrapper],
parameters,
globalTypes: {
locale: {
description: "Active language",
defaultValue: defaultLocale,
toolbar: {
icon: "globe",
items: locales,
},
},
},
};

export default preview;

0 comments on commit 39f115d

Please sign in to comment.