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

Upgrade Storybook v8.x #1904

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions .changeset/chilled-donuts-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@khanacademy/perseus-dev-ui": patch
"@khanacademy/math-input": patch
"@khanacademy/perseus": patch
"@khanacademy/perseus-editor": patch
---

Upgrade Storybook to v8.x
5 changes: 5 additions & 0 deletions .changeset/yellow-carrots-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus-dev-ui": patch
---

Upgrade Storybook to v8.x
17 changes: 0 additions & 17 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import turbosnap from "vite-plugin-turbosnap";
import viteConfig from "../dev/vite.config";
import {mergeConfig} from "vite";

Expand Down Expand Up @@ -54,24 +53,8 @@ const config: StorybookConfig = {
},
// Fix from: https://github.com/storybookjs/storybook/issues/25256#issuecomment-1866441206
assetsInclude: ["/sb-preview/runtime.js"],
plugins:
configType === "PRODUCTION"
? [
turbosnap({
// This should be the base path of your storybook. In monorepos, you may only need process.cwd().
rootDir: config.root ?? process.cwd(),
}),
]
: [],
});
},

typescript: {
reactDocgen: "react-docgen",
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Storybook now defaults to react-docgen so no need to specify this here: https://storybook.js.org/docs/api/main-config/main-config-typescript#reactdocgen

docs: {
autodocs: true,
},
staticDirs: ["../static"],
};

Expand Down
4 changes: 4 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const preview: Preview = {
})),
},
},
tags: [
//👇 Enables auto-generated documentation for all stories
"autodocs",
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

};

export default preview;
3 changes: 2 additions & 1 deletion dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@phosphor-icons/core": "^2.0.2"
},
"devDependencies": {
"vite": "^5.1.0"
"vite": "^5.1.0",
"@vitejs/plugin-react": "^4.3.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now need to specify this dep explicitly.

}
}
2 changes: 2 additions & 0 deletions dev/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "node:fs";
import {resolve, dirname, join} from "node:path";

import react from "@vitejs/plugin-react";
import glob from "fast-glob";
import {defineConfig} from "vite";

Expand All @@ -20,6 +21,7 @@ export default defineConfig({
// Dev/Storybook environment.
"process.env.STORYBOOK": JSON.stringify(true),
},
plugins: [react({jsxRuntime: "automatic"})],
resolve: {
alias: {
hubble: resolve(__dirname, "../vendor/hubble/hubble.js"),
Expand Down
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"engines": {
"node": ">=20"
},
"dependencies": {
"devDependencies": {
"@babel/core": "^7.23.2",
"@babel/eslint-parser": "^7.22.15",
"@babel/eslint-plugin": "^7.22.10",
Expand All @@ -40,14 +40,14 @@
"@rollup/plugin-node-resolve": "^13.2.1",
"@rollup/plugin-replace": "^4.0.0",
"@sheerun/mutationobserver-shim": "^0.3.3",
"@storybook/addon-a11y": "^7.6.17",
"@storybook/addon-actions": "^7.6.17",
"@storybook/addon-controls": "^7.6.17",
"@storybook/addon-essentials": "^7.6.17",
"@storybook/addon-links": "^7.6.17",
"@storybook/addon-viewport": "^7.6.17",
"@storybook/react": "^7.6.17",
"@storybook/react-vite": "^7.6.17",
"@storybook/addon-a11y": "^8.4.5",
"@storybook/addon-actions": "^8.4.5",
"@storybook/addon-controls": "^8.4.5",
"@storybook/addon-essentials": "^8.4.5",
"@storybook/addon-links": "^8.4.5",
"@storybook/addon-viewport": "^8.4.5",
"@storybook/react": "^8.4.5",
"@storybook/react-vite": "^8.4.5",
"@swc-node/register": "^1.6.6",
"@swc/core": "^1.3.68",
"@testing-library/dom": "^10.3.1",
Expand Down Expand Up @@ -117,13 +117,12 @@
"rollup-plugin-preserve-shebangs": "^0.2.0",
"rollup-plugin-styles": "^4.0.0",
"sloc": "^0.2.1",
"storybook": "^7.6.17",
"storybook": "^8.4.5",
"style-loader": "^3.3.3",
"tiny-invariant": "^1.3.1",
"typescript": "^5.4.2",
"typescript-coverage-report": "^0.7.0",
"vite-plugin-istanbul": "^5.0.0",
"vite-plugin-turbosnap": "^1.0.3",
Copy link
Contributor Author

@mark-fitzgerald mark-fitzgerald Nov 25, 2024

Choose a reason for hiding this comment

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

turbosnap is now built into the "@storybook/react-vite" bundle and can be enabled with the standard --stats-json argument

"winston": "^3.7.2"
},
"scripts": {
Expand All @@ -143,7 +142,7 @@
"test": "jest",
"storybook": "storybook dev -p 6006",
"start": "storybook dev -p 6006",
"build-storybook": "storybook build",
"build-storybook": "storybook build --stats-json",
"cypress": "cypress open --component",
"cypress:ci": "cross-env cypress run --component",
"format": "prettier --write .",
Expand Down
90 changes: 42 additions & 48 deletions packages/math-input/src/full-keypad.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import {action} from "@storybook/addon-actions";
import {INITIAL_VIEWPORTS} from "@storybook/addon-viewport";
import * as React from "react";

import Keypad from "./components/keypad";

import type {PropsFor} from "@khanacademy/wonder-blocks-core";
import type {ComponentStory} from "@storybook/react";
import type {StoryObj} from "@storybook/react";

const opsPage = "Operators Page";
const numsPage = "Numbers Page";
Expand Down Expand Up @@ -85,58 +82,55 @@ export default {
},
};

const Template: ComponentStory<typeof Keypad> = (
args: PropsFor<typeof Keypad>,
): React.ReactElement => (
<Keypad
{...args}
onClickKey={action("onClickKey")}
onAnalyticsEvent={async (e) => action("onAnalyticsEvent")(e)}
/>
);
type Story = StoryObj<typeof Keypad>;

export const Default = Template.bind({});
export const Default: Story = {};

export const PreAlgebra = Template.bind({});
PreAlgebra.args = {
preAlgebra: true,
export const PreAlgebra: Story = {
args: {
preAlgebra: true,
},
};

export const Trigonometry = Template.bind({});
Trigonometry.args = {
preAlgebra: true,
trigonometry: true,
export const Trigonometry: Story = {
args: {
preAlgebra: true,
trigonometry: true,
},
};

export const FractionsOnly = Template.bind({});
FractionsOnly.args = {
fractionsOnly: true,
export const FractionsOnly: Story = {
args: {
fractionsOnly: true,
},
};

export const Everything = Template.bind({});
Everything.args = {
advancedRelations: true,
basicRelations: true,
divisionKey: true,
logarithms: true,
convertDotToTimes: false,
preAlgebra: true,
trigonometry: true,
expandedView: true,
showDismiss: true,
extraKeys: ["a", "b", "c"],
export const Everything: Story = {
args: {
advancedRelations: true,
basicRelations: true,
divisionKey: true,
logarithms: true,
convertDotToTimes: false,
preAlgebra: true,
trigonometry: true,
expandedView: true,
showDismiss: true,
extraKeys: ["a", "b", "c"],
},
};

export const EverythingMinusNavigationPad = Template.bind({});
EverythingMinusNavigationPad.args = {
advancedRelations: true,
basicRelations: true,
divisionKey: true,
logarithms: true,
convertDotToTimes: false,
preAlgebra: true,
trigonometry: true,
expandedView: false,
showDismiss: true,
extraKeys: ["a", "b", "c"],
export const EverythingMinusNavigationPad: Story = {
args: {
advancedRelations: true,
basicRelations: true,
divisionKey: true,
logarithms: true,
convertDotToTimes: false,
preAlgebra: true,
trigonometry: true,
expandedView: false,
showDismiss: true,
extraKeys: ["a", "b", "c"],
},
};
Loading