Skip to content

chore: upgrade to Storybook7 #1282

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 1 commit into from
Aug 16, 2023
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
8 changes: 3 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:

- run: yarn install

- run: yarn build --ignore=@strapi/design-system-docs

- name: Run lint
run: yarn lint

Expand Down Expand Up @@ -91,14 +93,10 @@ jobs:
- run: yarn install

- name: Install Playwright
run: npx playwright@1.35.1 install
run: npx playwright@1.37.0 install

- name: Build
run: yarn build

- name: Start storybook
working-directory: ./docs/storybook-static
run: yarn add -D http-server && yarn http-server -p 6006 &

- name: Run the tests
run: yarn test:e2e:ci -- --project=${{ matrix.browser }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ storybook-static
# Visual Studio Code
############################

.vscode/
.vscode/*
!.vscode/settings.json
front-workspace.code-workspace
.yarnrc
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint.workingDirectories": [{ "mode": "auto" }]
}
40 changes: 22 additions & 18 deletions docs/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
{
"root": true,
"extends": ["plugin:react/recommended", "prettier"],
"plugins": ["prettier"],
"settings": {
"react": {
"version": "detect"
}
},
"extends": ["@strapi/eslint-config/front/typescript"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
"project": ["./tsconfig.eslint.json"]
},
"rules": {
"no-console": 0
"settings": {
"import/resolver": {
"typescript": {
"project": "./tsconfig.eslint.json"
}
}
},
"ignorePatterns": ["**/*.mdx/*.{ts,tsx}"],
"overrides": [
{
"files": ["*.stories.tsx"],
"rules": {
"react-hooks/rules-of-hooks": "off",
"import/no-default-export": "off",
"no-console": "off"
}
},
{
"files": ["*.mdx"],
"settings": {
"mdx/code-blocks": true
},
"extends": ["plugin:mdx/recommended"]
"extends": ["plugin:mdx/recommended"],
"rules": {
"import/namespace": "off",
"@typescript-eslint/no-unused-vars": "error"
}
}
]
}
27 changes: 0 additions & 27 deletions docs/.storybook/components/Theme.js

This file was deleted.

34 changes: 0 additions & 34 deletions docs/.storybook/main.js

This file was deleted.

54 changes: 54 additions & 0 deletions docs/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { dirname, join, resolve } from 'path';
import type { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.tsx'],
addons: [getAbsolutePath('@storybook/addon-essentials'), getAbsolutePath('storybook-dark-mode')],
staticDirs: ['../public'],
typescript: {
reactDocgen: 'react-docgen-typescript',
reactDocgenTypescriptOptions: {
compilerOptions: {
allowSyntheticDefaultImports: false,
esModuleInterop: false,
},
},
},
viteFinal: (config) => {
if (config.mode !== 'production') {
config.optimizeDeps = {
...config.optimizeDeps,
exclude: ['@strapi/ui-primtivies', '@strapi/design-system', '@strapi/icons'],
};

if (!config.resolve) {
config.resolve = {};
}

config.resolve.alias = {
...config.resolve?.alias,
'@strapi/ui-primitives': resolve(__dirname, '..', '..', 'packages', 'primitives', 'src'),
'@strapi/design-system': resolve(__dirname, '..', '..', 'packages', 'strapi-design-system', 'src'),
'@strapi/design-system/v2': resolve(__dirname, '..', '..', 'packages', 'strapi-design-system', 'src', 'v2'),
'@strapi/icons': resolve(__dirname, '..', '..', 'packages', 'strapi-icons', 'src'),
};
}

return config;
},

framework: {
name: getAbsolutePath('@storybook/react-vite'),
options: {},
},

docs: {
autodocs: true,
},
};

function getAbsolutePath<T extends string>(value: T): T {
return dirname(require.resolve(join(value, 'package.json'))) as T;
}

export default config;
5 changes: 1 addition & 4 deletions docs/.storybook/manager.js → docs/.storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { addons } from '@storybook/addons';
import { addons } from '@storybook/manager-api';
import { lightTheme } from '@strapi/design-system';
import { createCustomTheme } from './utils/createCustomTheme';

addons.setConfig({
theme: createCustomTheme({
theme: lightTheme,
options: {
base: 'light',
},
}),
});
12 changes: 12 additions & 0 deletions docs/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<style>
body {
padding: 0 !important;
}

#storybook-root:not([hidden='true']) {
display: flex;
justify-content: stretch;
align-items: stretch;
height: 100%;
}
</style>
40 changes: 0 additions & 40 deletions docs/.storybook/preview.js

This file was deleted.

66 changes: 66 additions & 0 deletions docs/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ReactNode, useEffect, useState } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { Preview } from '@storybook/react';
import { useDarkMode } from 'storybook-dark-mode';
import { parse } from 'qs';

import { VisuallyHidden, DesignSystemProvider, Box, darkTheme, lightTheme } from '@strapi/design-system';

import { createCustomTheme } from './utils/createCustomTheme';

const preview: Preview = {
decorators: [
(Story) => (
<MemoryRouter>
<Theme>
<main>
<VisuallyHidden>
{/* Necessary in order to prevent axe core from providing errors on main / heading */}
<h1>Storybook story</h1>
</VisuallyHidden>
<Box height="100%" padding={2}>
<Story />
</Box>
</main>
</Theme>
</MemoryRouter>
),
],
parameters: {
options: {
storySort: {
order: ['Design System', ['Primitives', 'Technical Components', 'Components']],
},
},
actions: { argTypesRegex: '^on[A-Z].*' },
darkMode: {
// Override the default dark theme
dark: createCustomTheme({ theme: darkTheme, asStorybookTheme: false }),
// Override the default light theme
light: createCustomTheme({ theme: lightTheme, asStorybookTheme: false }),
},
},
};

const themeQueryURL = parse(document.location.search).theme;

const Theme = ({ children }: { children: ReactNode }) => {
const isDarkAddon = useDarkMode();
const [isDark, setIsDark] = useState(themeQueryURL || isDarkAddon);

useEffect(() => {
if (!themeQueryURL && isDarkAddon !== isDark) {
setIsDark(isDarkAddon);
}
}, [isDarkAddon, isDark]);

return (
<DesignSystemProvider locale="en" theme={isDark ? darkTheme : lightTheme}>
<Box flex="1 0 100%" padding={2} background="neutral0">
{children}
</Box>
</DesignSystemProvider>
);
};

export default preview;
22 changes: 0 additions & 22 deletions docs/.storybook/utils/createCustomTheme.js

This file was deleted.

Loading