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

Bump Storybook to 6.1 #2054

Merged
merged 3 commits into from
Mar 21, 2021
Merged
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
5 changes: 5 additions & 0 deletions packages/core/config/storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const baseConfig = {
}
}

const userPreviewPath = fs.existsSync(getPaths().web.storybookPreviewConfig)
? getPaths().web.storybookPreviewConfig
: './preview.example.js'
sbConfig.resolve.alias['~__REDWOOD__USER_STORYBOOK_PREVIEW_CONFIG'] = userPreviewPath

sbConfig.resolve.extensions = rwConfig.resolve.extensions
sbConfig.resolve.plugins = rwConfig.resolve.plugins // Directory Named Plugin

Expand Down
8 changes: 8 additions & 0 deletions packages/core/config/storybook/preview.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This is an example of a custom preview.js file. If you'd like to
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created this file since ~__REDWOOD__USER_STORYBOOK_PREVIEW_CONFIG should always be aliased to a valid filepath, otherwise HMR complains when we require it. This is essentially a no-op file to alias it to if the user doesn't have their own config file.

// customize your own, copy this file to web/config/storybook.preview.js
// and restart your Storybook server.
// For more information see https://storybook.js.org/docs/react/configure/overview#configure-story-rendering

// export const decorators = [
// Story => <div style={{ margin: '3em'}}><Story /></div>
// ]
17 changes: 12 additions & 5 deletions packages/core/config/storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const React = require('react')

const { addDecorator } = require('@storybook/react')
const { merge } = require('webpack-merge')

// The StorybookProvider is responsible for importing all the mock files,
// booting up the mock server workers, and mocking the router.
Expand All @@ -11,6 +10,14 @@ const {
// Import the user's default CSS file
require('~__REDWOOD__USER_WEB_DEFAULT_CSS')

addDecorator((storyFn, { id }) => {
return React.createElement(StorybookProvider, { storyFn, id })
})
// The base config provides Redwood-specific integrations. User config values
// will be merged into this.
const baseConfig = {
decorators: [
(storyFn, { id }) => React.createElement(StorybookProvider, { storyFn, id }),
]
}

const userConfig = require('~__REDWOOD__USER_STORYBOOK_PREVIEW_CONFIG')

module.exports = merge(baseConfig, userConfig)
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@redwoodjs/eslint-config": "^0.27.1",
"@redwoodjs/internal": "^0.27.1",
"@redwoodjs/testing": "^0.27.1",
"@storybook/react": "^5.3.19",
"@storybook/react": "^6.1.21",
"@testing-library/jest-dom": "5.11.6",
"@types/jest": "^26.0.10",
"@types/node": "^14.6.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/internal/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface BrowserTargetPaths {
webpack: string
postcss: string
storybookConfig: string
storybookPreviewConfig: string
dist: string
}

Expand Down Expand Up @@ -77,6 +78,7 @@ const PATH_WEB_DIR_CONFIG = 'web/config'
const PATH_WEB_DIR_CONFIG_WEBPACK = 'web/config/webpack.config.js'
const PATH_WEB_DIR_CONFIG_POSTCSS = 'web/config/postcss.config.js'
const PATH_WEB_DIR_CONFIG_STORYBOOK_CONFIG = 'web/config/storybook.config.js'
const PATH_WEB_DIR_CONFIG_STORYBOOK_PREVIEW = 'web/config/storybook.preview.js'

const PATH_WEB_DIR_DIST = 'web/dist'

Expand Down Expand Up @@ -173,6 +175,10 @@ export const getPaths = (BASE_DIR: string = getBaseDir()): Paths => {
BASE_DIR,
PATH_WEB_DIR_CONFIG_STORYBOOK_CONFIG
),
storybookPreviewConfig: path.join(
BASE_DIR,
PATH_WEB_DIR_CONFIG_STORYBOOK_PREVIEW
),
dist: path.join(BASE_DIR, PATH_WEB_DIR_DIST),
},
}
Expand Down
Loading