Skip to content

chore: upgrade to storybook v8 #4246

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

Merged
merged 3 commits into from
Aug 6, 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
6,619 changes: 2,261 additions & 4,358 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions react-storybook/host/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

*storybook.log
38 changes: 25 additions & 13 deletions react-storybook/host/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
const moduleFederationConfig = require('../modulefederation.config.js');
import { dirname, join } from 'path';
import moduleFederationConfig from '../modulefederation.config';

const storybookConfig = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value) {
return dirname(require.resolve(join(value, 'package.json')));
}

/** @type { import('@storybook/react-webpack5').StorybookConfig } */
const config = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/preset-create-react-app',
getAbsolutePath('@storybook/preset-create-react-app'),
getAbsolutePath('@storybook/addon-onboarding'),
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@chromatic-com/storybook'),
getAbsolutePath('@storybook/addon-interactions'),
{
name: '@module-federation/storybook-addon',
options: {
moduleFederationConfig,
},
},
}
],
framework: '@storybook/react',
core: {
builder: '@storybook/builder-webpack5',
framework: {
name: getAbsolutePath('@storybook/react-webpack5'),
options: {},
},
staticDirs: ['../public'],
};

module.exports = storybookConfig;
export default config;
35 changes: 19 additions & 16 deletions react-storybook/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
"build": "node ./scripts/build.js",
"test": "react-scripts test",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public"
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"eslintConfig": {
"extends": [
"react-app"
"react-app",
"plugin:storybook/recommended"
],
"overrides": [
{
Expand All @@ -43,21 +44,23 @@
]
},
"devDependencies": {
"@module-federation/storybook-addon": "0.2.0",
"@chromatic-com/storybook": "^1.6.1",
"@module-federation/storybook-addon": "2.0.1",
"@module-federation/utilities": "3.0.32",
"webpack-virtual-modules": "0.6.2",
"@storybook/addon-actions": "6.5.16",
"@storybook/addon-essentials": "6.5.16",
"@storybook/addon-interactions": "6.5.16",
"@storybook/addon-links": "6.5.16",
"@storybook/builder-webpack5": "6.5.16",
"@storybook/manager-webpack5": "6.5.16",
"@storybook/node-logger": "6.5.16",
"@storybook/preset-create-react-app": "4.1.2",
"@storybook/react": "6.5.16",
"@storybook/testing-library": "0.2.2",
"@storybook/addon-essentials": "^8.2.6",
"@storybook/addon-interactions": "^8.2.6",
"@storybook/addon-links": "^8.2.6",
"@storybook/addon-onboarding": "^8.2.6",
"@storybook/blocks": "^8.2.6",
"@storybook/preset-create-react-app": "^8.2.6",
"@storybook/react": "^8.2.6",
"@storybook/react-webpack5": "^8.2.6",
"@storybook/test": "^8.2.6",
"babel-plugin-named-exports-order": "0.0.2",
"eslint-plugin-storybook": "^0.8.0",
"prop-types": "15.8.1",
"webpack": "5.92.1"
"storybook": "^8.2.6",
"webpack": "5.92.1",
"webpack-virtual-modules": "0.6.2"
}
}
50 changes: 50 additions & 0 deletions react-storybook/host/src/stories/Button.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import PropTypes from 'prop-types';
import './button.css';

/**
* Primary UI component for user interaction
*/
export const Button = ({ primary, backgroundColor, size, label, ...props }) => {
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
return (
<button
type="button"
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
style={backgroundColor && { backgroundColor }}
{...props}
>
{label}
</button>
);
};

Button.propTypes = {
/**
* Is this the principal call to action on the page?
*/
primary: PropTypes.bool,
/**
* What background color to use
*/
backgroundColor: PropTypes.string,
/**
* How large should the button be?
*/
size: PropTypes.oneOf(['small', 'medium', 'large']),
/**
* Button contents
*/
label: PropTypes.string.isRequired,
/**
* Optional click handler
*/
onClick: PropTypes.func,
};

Button.defaultProps = {
backgroundColor: null,
primary: false,
size: 'medium',
onClick: undefined,
};
48 changes: 48 additions & 0 deletions react-storybook/host/src/stories/Button.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { fn } from '@storybook/test';
import { Button } from './Button';

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
export default {
title: 'Example/Button',
component: Button,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
layout: 'centered',
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/api/argtypes
argTypes: {
backgroundColor: { control: 'color' },
},
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
args: { onClick: fn() },
};

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Primary = {
args: {
primary: true,
label: 'Button',
},
};

export const Secondary = {
args: {
label: 'Button',
},
};

export const Large = {
args: {
size: 'large',
label: 'Button',
},
};

export const Small = {
args: {
size: 'small',
label: 'Button',
},
};
Loading
Loading