This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
forked from HHS/simpler-grants-gov
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update storybook settings for app router
- Loading branch information
Showing
5 changed files
with
95 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |