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

Commit

Permalink
Update to .storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed May 21, 2024
1 parent 8fc6b93 commit 4c0dc27
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 66 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 ?? defaultLocale;

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

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

This file was deleted.

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

This file was deleted.

62 changes: 62 additions & 0 deletions frontend/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @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);
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 4c0dc27

Please sign in to comment.