grafana/packages/grafana-ui/.storybook/main.ts
Jack Westbrook 33ba5310ab
Chore: Upgrade Storybook to v7 (#65943)
* chore(grafana-ui): begin migration to storybook7

* refactor(storybook): begin cleanup of storybook and addon configs

* chore(storybook): add storybook/blocks to keep yarn berry happy

* chore(storybook): rename intro story for storybook 7

* chore(stories): rename internal stories to support SB7 story name mapper

* chore(betterer): update glob to support internal story renaming

* chore(stories): silence TS errors for subcomponents in SB7

* fix(clickoutsidewrapper): window | document can be undefined not null

* chore(storybook): remove patch for 6.5.16

* revert(storybook): put back story globs

* docs(storybook): replace removed <Props /> with <ArgsTypes /> in mdx files

* docs(storybook): use ArgTypes instead of ArgsTable

* chore(storybook): use correct ArgTypes import name in mdx files

* chore(storybook): patch blocks to expose Preview component for docs

* chore(storybook): rename deprecated ComponentStory and ComponentMeta for v7

* feat(storybook): add STORY env var to customise which stories storybook should load

* chore(storybook): bump to 7.0.4

* fix(storybook): set esbuild minify target to fix erroring docs in production builds

* fix(toolbarbuttonrow): fix import path to prevent error in storybook doc

* docs(storybook): fix up some more stories

* chore(storybook): more config updates to match storybook documentation

* chore(storybook): bump to 7.0.5

* Apply suggestions from code review

Co-authored-by: Joao Silva <100691367+JoaoSilvaGrafana@users.noreply.github.com>

* chore(storybook): fix broken merge causing types issues

* chore(storybook): mimic broken alphabetical storySort and docs overview ordering

* docs(storybook): fix button docs adding p tags due to mdx2

* chore(storybook): bump to 7.0.10

* chore(storybook): apply patch on yarn install

* chore(text): update stories for storybook 7

* fix(storybook): make sure globs don't include internal stories in production

---------

Co-authored-by: Joao Silva <100691367+JoaoSilvaGrafana@users.noreply.github.com>
2023-05-11 14:26:12 +02:00

133 lines
3.6 KiB
TypeScript

import path from 'path';
import type { StorybookConfig } from '@storybook/react-webpack5';
// avoid importing from @grafana/data to prevent node error: ERR_REQUIRE_ESM
import { availableIconsIndex, IconName } from '../../grafana-data/src/types/icon';
import { getIconSubDir } from '../src/components/Icon/utils';
// Internal stories should only be visible during development
const storyGlob =
process.env.NODE_ENV === 'production'
? '../src/components/**/!(*.internal).story.tsx'
: '../src/components/**/*.story.tsx';
const stories = ['../src/Intro.mdx', storyGlob];
// We limit icon paths to only the available icons so publishing
// doesn't require uploading 1000s of unused assets.
const iconPaths = Object.keys(availableIconsIndex)
.filter((iconName) => !iconName.includes('fa'))
.map((iconName) => {
const subDir = getIconSubDir(iconName as IconName, 'default');
return {
from: `../../../public/img/icons/${subDir}/${iconName}.svg`,
to: `/public/img/icons/${subDir}/${iconName}.svg`,
};
});
const mainConfig: StorybookConfig = {
stories,
addons: [
{
name: '@storybook/addon-essentials',
options: {
backgrounds: false,
},
},
'@storybook/addon-a11y',
{
name: '@storybook/preset-scss',
options: {
styleLoaderOptions: {
// this is required for theme switching .use() and .unuse()
injectType: 'lazyStyleTag',
},
cssLoaderOptions: {
url: false,
importLoaders: 2,
},
},
},
'@storybook/addon-storysource',
'storybook-dark-mode',
{
// replace babel-loader in manager and preview with esbuild-loader
name: 'storybook-addon-turbo-build',
options: {
optimizationLevel: 3,
// Target must match storybook 7 manager otherwise minimised docs error in production
esbuildMinifyOptions: {
target: 'chrome100',
minify: true,
},
},
},
],
core: {},
docs: {
autodocs: true,
},
framework: {
name: '@storybook/react-webpack5',
options: {
fastRefresh: true,
builder: {
fsCache: true,
},
},
},
logLevel: 'debug',
staticDirs: [
{
from: '../../../public/fonts',
to: '/public/fonts',
},
{
from: '../../../public/img/grafana_text_logo-dark.svg',
to: '/public/img/grafana_text_logo-dark.svg',
},
{
from: '../../../public/img/grafana_text_logo-light.svg',
to: '/public/img/grafana_text_logo-light.svg',
},
{
from: '../../../public/img/fav32.png',
to: '/public/img/fav32.png',
},
{
from: '../../../public/lib',
to: '/public/lib',
},
...iconPaths,
],
typescript: {
check: true,
reactDocgen: 'react-docgen-typescript',
reactDocgenTypescriptOptions: {
tsconfigPath: path.resolve(__dirname, 'tsconfig.json'),
shouldExtractLiteralValuesFromEnum: true,
shouldRemoveUndefinedFromOptional: true,
propFilter: (prop: any) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
savePropValueAsString: true,
},
},
webpackFinal: async (config) => {
// expose jquery as a global so jquery plugins don't break at runtime.
config.module?.rules?.push({
test: require.resolve('jquery'),
loader: 'expose-loader',
options: {
exposes: ['$', 'jQuery'],
},
});
// use the asset module for SVGS for compatibility with grafana/ui Icon component.
config.module?.rules?.push({
test: /(unicons|mono|custom)[\\/].*\.svg$/,
type: 'asset/source',
});
return config;
},
};
module.exports = mainConfig;