- Upgrade all your dependencies
$ yarn upgrade-interactive --latest
(🚨 do NOT upgrade Prettier to >=3.0.0, theprettier.format
method used in preview.tsx became async, and storybook doesn't support async functions insidesource.transform
) - Inside
.storybook/preview.tsx
, refactordocs.transformSource
intodocs.source.transform
:
source: {
transform: function(src, storyContext) {
const component = createElement(storyContext.component, storyContext.initialArgs);
return renderHtml(component);
},
},
- In
Blank.mdx
, refactor the deprecated<Canvas>
by the following:
<Canvas of={Blank.Default} />
- Upgrade all your dependencies
$ yarn upgrade-interactive --latest
$ yarn remove webpack-cli @svgr/webpack
$ yarn add clsx glob svg-sprite
$ yarn add -D storybook @storybook/addon-interactions @storybook/manager-api @storybook/blocks @storybook/testing-library @storybook/react-vite rollup @rollup/plugin-commonjs @rollup/plugin-node-resolve @rollup/plugin-terser @vitejs/plugin-react
- In
./package.json
, replace the following scripts with their updated versions:
"tailwind:build": "export NODE_ENV=production && npx tailwindcss -i ./src/styles/base.css -o ./public/css/styles.css --minify",
"tailwind:start": "npx tailwindcss -i ./src/styles/base.css -o ./public/css/styles.css --watch",
"storybook:start": "storybook dev --no-open -p 6006",
"storybook:build": "storybook build",
"modules:build": "rollup --config",
"build": "yarn build:assets",
"build:styleguide": "yarn build:assets && yarn storybook:build",
- Add the following script:
"build:assets": "yarn tailwind:build && yarn modules:build && npx @ffflorian/jszip-cli add public/ > public/tl-styleguide-assets.zip",
"icons:build": "svg-sprite -s --symbol-inline --symbol-dest public --symbol-sprite icons.svg src/assets/icons/*.svg",
"images:build": "npx zx bin/generate-image.mjs",
- Replace the content of your
.storybook/preview.js
files with the following:
import { createElement } from 'react';
import ReactDomServer from 'react-dom/server';
import prettierHtml from 'prettier/parser-html';
import prettier from 'prettier/standalone';
const renderHtml = function(component) {
return prettier.format(ReactDomServer.renderToStaticMarkup(component).
replace(/<script><\/script>/g, ''), {
parser: 'html',
plugins: [prettierHtml],
htmlWhitespaceSensitivity: 'ignore',
});
};
const preview = {
parameters: {
actions: {argTypesRegex: '^on[A-Z].*'},
html: {
prettier: {
tabWidth: 2,
useTabs: false,
},
},
docs: {
source: {
transform: function(src, storyContext) {
const component = createElement(storyContext.component, storyContext.initialArgs);
return renderHtml(component);
},
},
},
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
};
export default preview;
- Rename your
.storybook/main.js
to.storybook/main.ts
and replace the content by the following:
import type { StorybookConfig } from "@storybook/react-vite";
const config: StorybookConfig = {
stories: [
"../src/**/*.stories.mdx",
"../src/**/*.stories.@(js|jsx|ts|tsx)",
],
addons: [
"@storybook/addon-docs",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
"@storybook/addon-links",
"@storybook/theming",
"@storybook/manager-api",
],
framework: {
name: "@storybook/react-vite",
options: {},
},
docs: {
autodocs: "tag",
defaultName: "Documentation",
},
};
export default config;
- Remove
styles.css
from the content of your.storybook/preview-head.html
and import theme directly into.storybook/preview.tsx
like
import '../public/css/styles.css';
Storybook v7 comes with some changes to the way it handles markdown. You need to refactor them with the following steps:
- Refactor your
[component].stories.tsx
file in the style of the Blank component - Add a
[component].mdx
file in the same level as the.stories.tsx
file. - This file will serve as the documentation of the component, you can take a look at this file to get an example of how to document your component: Blank.mdx
- Add the new
"modules:start": "webpack --watch",
NPM script - Remove
postcss-nested
dependencies - Update your devDependencies
- Udapte your
postcss.config.js
with something like
module.exports = {
plugins: {
'postcss-import': {},
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
},
};
- In your colors documentation, use the Tailwind config like:
import resolveConfig from 'tailwindcss/resolveConfig';
resolveConfig(tailwindConfig).theme.colors
- Create a dedicated
tailwind.css
file to import first frombase.css
with
@tailwind base;
@tailwind components;
@tailwind utilities;
- Update your
tailwind.config.js
with something like
module.exports = {
important: true,
content: ['./src/**/*.{jsx,tsx,html,twig}'],
theme: {
extend: {...},
},
plugins: [...],
};
- In your
tsconfig.json
, change"isolatedModules": false,
- Upgrade all your dependencies
$ yarn upgrade-interactive --latest
- Remove
css-loader
($ yarn remove css-loader
) - Ensure Webpack 5 (
$ yarn add webpack --dev
) - In
webpack.congif.js
, add after line 17:mode: 'production',
- Remove in
.storybook/preview.js
:import '!style-loader!css-loader!./../build/styles.css';
- Add in
.storybook/preview-head.html
:<link rel="stylesheet" href="/styles.css" />
- Update your NPM scripts to something like:
- "storybook:build": "NODE_PATH=src build-storybook",
+ "storybook:build": "NODE_PATH=src build-storybook && cp ./build/styles.css ./storybook-static",
- Remove
chokidar-cli
andpostcss-cli
dependencies - Update all your dependencies (
$ yarn upgrade-interactive --latest
) - Update the content of your
.storybook/main.js
withmodule.exports = { "stories": [ "../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)", ], "addons": [ "@whitespace/storybook-addon-html", "@storybook/addon-docs", "@storybook/addon-links", "@storybook/addon-essentials" ], typescript: { reactDocgen: 'react-docgen' } }
- Replace all
tailwind:XXX
npm script by:"tailwind:build": "export NODE_ENV=production && npx tailwindcss -i ./src/styles/base.css -o ./build/styles.css --minify --purge='./src/**/*.tsx' --postcss", "tailwind:start": "npx tailwindcss -i ./src/styles/base.css -o ./build/styles.css --watch --jit --purge='./src/**/*.tsx' --postcss",
- Update your
src/components/atoms/Icons/Icons.tsx
like:import React, { FunctionComponent, SVGAttributes } from 'react'; import External from 'assets/icons/external.svg'; import Home from 'assets/icons/home.svg'; export const iconList: Record<string, unknown> = { home: Home, external: External, }; export type IconNames = 'home' | 'external'; const Icons = (): JSX.Element => ( <div style={{ display: 'none' }}> {Object.keys(iconList).map(icon => React.createElement<SVGAttributes<SVGAElement>>( iconList[icon] as FunctionComponent, { key: icon, id: icon.replace(/_/gm, '-'), } ) )} </div> ); //...
- In your
src/components/atoms/Icon/Icon.tsx
import and use the newIconNames
type like:import { IconNames } from 'components/atoms/Icons/Icons'; export type Props = { name?: IconNames; };
Nothing to worry about 😉
Nothing to worry about 😉, but the new src/modules/collapse-react.tsx
and src/modules/collapse-vanilla.tsx
should help you to better understand Storybox modules system.
Nothing to worry about 😉