Skip to content

Commit

Permalink
Storybook 7 Upgrade - AR (#7622)
Browse files Browse the repository at this point in the history
- Updated all storybook dependencies to v7
- Added storybook package and new CLI commands
- Updated `main.js` to use framework instead of builders
- Added `addon-essentials` dependency to AR
- Used `StoryFn` type for stories with type errors
- Used `.storyName` instead of `.story.name`
  • Loading branch information
JamieB-gu authored Apr 26, 2023
1 parent 7c9ef86 commit f74ab9a
Show file tree
Hide file tree
Showing 6 changed files with 2,382 additions and 4,146 deletions.
7 changes: 4 additions & 3 deletions apps-rendering/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ const webpack = require('webpack');

/** @type {import("@storybook/react/types").StorybookConfig} */
module.exports = {
core: {
builder: 'webpack5',
},
stories: ['../src/**/*.stories.@(js|mdx|ts|tsx)'],
addons: [
'@storybook/addon-essentials',
Expand Down Expand Up @@ -53,6 +50,10 @@ module.exports = {
// See: https://storybook.js.org/docs/react/configure/environment-variables
CI: 'true',
}),
framework: {
name: '@storybook/react-webpack5',
options: {}
}
};

const webpackConfig = (config) => {
Expand Down
21 changes: 11 additions & 10 deletions apps-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"build:client:prod": "webpack --config webpack.config.ts --config-name clientProduction",
"synth": "cdk synth --path-metadata false --version-reporting false",
"diff": "cdk diff --path-metadata false --version-reporting false",
"storybook": "start-storybook -p 4003",
"build-storybook": "node --max-old-space-size=4096 $(yarn bin)/build-storybook"
"storybook": "storybook dev -p 4003",
"build-storybook": "node --max-old-space-size=4096 $(yarn bin)/storybook build"
},
"author": "",
"license": "ISC",
Expand Down Expand Up @@ -56,14 +56,14 @@
"@guardian/source-react-components": "^11.4.0",
"@guardian/source-react-components-development-kitchen": "10.0.1",
"@guardian/types": "^9.0.1",
"@storybook/addons": "^6.4.0",
"@storybook/api": "^6.4.0",
"@storybook/builder-webpack5": "^6.4.0",
"@storybook/components": "^6.5.15",
"@storybook/core-events": "^6.4.0",
"@storybook/manager-webpack5": "^6.4.0",
"@storybook/react": "^6.4.0",
"@storybook/theming": "^6.5.15",
"@storybook/addon-essentials": "^7.0.7",
"@storybook/addons": "^7.0.7",
"@storybook/api": "^7.0.7",
"@storybook/components": "^7.0.7",
"@storybook/core-events": "^7.0.7",
"@storybook/react": "^7.0.7",
"@storybook/react-webpack5": "^7.0.7",
"@storybook/theming": "^7.0.7",
"@types/clean-css": "^4.2.5",
"@types/compression": "^1.7.2",
"@types/express": "^4.17.13",
Expand Down Expand Up @@ -107,6 +107,7 @@
"react-test-renderer": "^17.0.2",
"require-from-string": "^2.0.2",
"source-map-support": "^0.5.21",
"storybook": "^7.0.7",
"thrift": "^0.16.0",
"ts-jest": "^28.0.7",
"ts-loader": "^9.4.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const Deadblogs = (): ReactElement => {
);
};

Deadblogs.storyName = 'Deadblogs comment count below desktop';
Deadblogs.story = {
name: 'Deadblogs comment count below desktop',
parameters: {
viewport: { defaultViewport: 'tablet' },
chromatic: { viewports: [breakpoints.tablet] },
Expand Down
18 changes: 5 additions & 13 deletions apps-rendering/src/components/Layout/Layout.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Edition } from '@guardian/apps-rendering-api-models/edition';
import { ArticleSpecial } from '@guardian/libs';
import { breakpoints } from '@guardian/source-foundations';
import type { StoryFn } from '@storybook/react';
import { formatToString } from 'articleFormat';
import {
analysis,
Expand Down Expand Up @@ -40,13 +41,6 @@ import LiveLayout from './LiveLayout';
import NewsletterSignUpLayout from './NewsletterSignUpLayout';
import StandardLayout from './StandardLayout';

// ----- Types ----- //

/**
* A storybook story with a name.
*/
type Story = { (): ReactElement; story: { name: string } };

// ----- Helpers ----- //

/**
Expand All @@ -64,9 +58,9 @@ const setSpecialReportAlt = setTheme(ArticleSpecial.SpecialReportAlt);
*/
const createLayoutStory =
<Fixture extends Item>(Layout: FC<{ item: Fixture }>) =>
(fixture: Fixture): Story => {
(fixture: Fixture): StoryFn<typeof Layout> => {
const story = (): ReactElement => <Layout item={fixture} />;
story.story = { name: formatToString(fixture) };
story.storyName = formatToString(fixture);

return story;
};
Expand Down Expand Up @@ -103,7 +97,7 @@ const newsletterSignUpLayoutStory = createLayoutStory(
);
const newsletterSignUpFallbackLayoutStory = (
fixture: NewsletterSignup,
): Story => {
): StoryFn<typeof NewsletterSignUpLayout> => {
const story = (): ReactElement => (
<>
<style>
Expand All @@ -114,9 +108,7 @@ const newsletterSignUpFallbackLayoutStory = (
<NewsletterSignUpLayout item={fixture} />
</>
);
story.story = {
name: `${formatToString(fixture)} (form component not supported)`,
};
story.storyName = `${formatToString(fixture)} (form component not supported)`;

return story;
};
Expand Down
14 changes: 5 additions & 9 deletions apps-rendering/src/components/Pagination/Pagination.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ArticleDesign, ArticleDisplay } from '@guardian/libs';
import { breakpoints } from '@guardian/source-foundations';
import type { StoryFn } from '@storybook/react';
import { formatToString } from 'articleFormat';
import { getAllThemes } from 'fixtures/article';
import type { ReactElement } from 'react';
import { Pagination } from '.';

export default {
Expand All @@ -19,7 +19,7 @@ const formats = getAllThemes({
design: ArticleDesign.Standard,
});

export const notFirstPage = (): ReactElement => {
export const notFirstPage: StoryFn<typeof Pagination> = () => {
return (
<>
{formats.map((format) => (
Expand All @@ -33,11 +33,9 @@ export const notFirstPage = (): ReactElement => {
</>
);
};
notFirstPage.story = {
name: 'Not first page',
};
notFirstPage.storyName = 'Not first page';

export const firstPageStory = (): ReactElement => {
export const firstPageStory: StoryFn<typeof Pagination> = () => {
return (
<>
{formats.map((format) => (
Expand All @@ -51,6 +49,4 @@ export const firstPageStory = (): ReactElement => {
</>
);
};
firstPageStory.story = {
name: 'First page',
};
firstPageStory.storyName = 'First page';
Loading

0 comments on commit f74ab9a

Please sign in to comment.