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

[Debt] Replaces storybook-addon-intl with storybook-react-intl #10022

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 14 additions & 7 deletions apps/web/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React from "react";
import {
FeatureFlagDecorator,
HelmetDecorator,
MockGraphqlDecorator,
ReducedMotionDecorator,
RouterDecorator,
ThemeDecorator,
VIEWPORTS
VIEWPORTS,
} from "@gc-digital-talent/storybook-helpers";
import { richTextElements as defaultRichTextElements } from "@gc-digital-talent/i18n";
import frCommonCompiled from "@gc-digital-talent/i18n/frCompiled.json";

import frCommonCompiled from "@gc-digital-talent/i18n/frCompiled.json";
import frCompiled from "../src/lang/frCompiled.json";

import "../src/assets/css/hydrogen.css";
Expand All @@ -23,23 +24,29 @@ const messages = {
},
};

const getMessages = (locale) => messages[locale];
export const globals = {
locale: "en",
locales: {
en: "English",
fr: "Français",
},
};

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
backgrounds: {
disable: true
disable: true,
},
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
intl: {
locales: ["en", "fr"],
reactIntl: {
defaultLocale: "en",
getMessages,
locales: ["en", "fr"],
messages,
defaultRichTextElements,
},
viewport: {
Expand Down
8 changes: 3 additions & 5 deletions packages/storybook-helpers/decorators/ThemeDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ type ThemeSetterProps = {
theme: Theme;
};
const ThemeSetter = ({ theme }: ThemeSetterProps) => {
const { setTheme } = useTheme();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if it's as a result of the library change or of this theme change but it seems like Chromatic is taking some snapshots before the components are ready.

For these, the theme icon hasn't yet settled to the right one for the story:
image

And this one still has the loading spinner running:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good 👁️, thanks! As discussed, any of the stories with the ThemeSwitcher component were actually previously incorrect due to the infinite re-render bug in ThemeDecorator where the initial state should have been the system default rather than light mode. The home page I've added a Chromatic delay to the DateInput and Pending stories that should get them to where they should be (more or less). The other diffs are existing issues: #9636, #10025.


React.useEffect(() => {
const { setTheme, key, mode } = useTheme();
if (theme.key !== key || theme.mode !== mode) {
setTheme({
key: theme.key,
mode: theme.mode,
});
}, [setTheme, theme.key, theme.mode]);

}
return null;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/storybook-helpers/main.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

For anyone else who might be confused like me, the switcher is now the globe icon in the toolbar.
image

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const main: StorybookConfig = {
"@storybook/addon-links",
"@storybook/addon-themes",
"@storybook/addon-viewport",
"storybook-addon-intl",
"storybook-react-intl",
],
framework: {
name: "@storybook/react-webpack5",
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"hydrogen-webpack-plugin": "workspace:*",
"react": "^18.2.0",
"storybook": "^7.6.17",
"storybook-addon-intl": "^3.2.0",
"storybook-react-intl": "~2.0.10",
"tsconfig": "workspace:*",
"tsconfig-paths-webpack-plugin": "^4.1.0"
}
Expand Down
49 changes: 41 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.