Skip to content

Commit 49e9f9d

Browse files
committed
feat: upgrade storybook to v10
1 parent 0a38e9f commit 49e9f9d

File tree

4 files changed

+689
-539
lines changed

4 files changed

+689
-539
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = {
22
extends: [
33
'./node_modules/@tiny-codes/code-style-all-in-one/eslint/config/react-recommended',
44
'plugin:@tiny-codes/react-hooks/recommended',
5+
'plugin:storybook/recommended',
56
],
67
rules: {
78
'react/no-array-index-key': 'error',

.storybook/preview.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useMemo } from 'react';
2+
import { DocsContainer } from '@storybook/addon-docs/blocks';
23
import type { Preview } from '@storybook/react';
34
import { App as AntdApp, ConfigProvider as AntdConfigProvider, theme } from 'antd';
45
import enUS from 'antd/es/locale/en_US';
56
import zhCN from 'antd/es/locale/zh_CN';
6-
// import { ensure, themes } from 'storybook/theming';
7+
import { ensure, themes } from 'storybook/theming';
78
import ConfigProvider from '../src/components/ConfigProvider';
89
import demoI18n from './locales';
910

@@ -25,7 +26,15 @@ const preview: Preview = {
2526
},
2627
},
2728
docs: {
28-
// theme: ensure(isPreferDark ? themes.dark : themes.light),
29+
container: (props: any) => {
30+
const bgValue = props.context.globals?.backgrounds?.value;
31+
const isDark = bgValue ? bgValue === 'dark' : isPreferDark;
32+
return <DocsContainer {...props} theme={isDark ? themes.dark : themes.light} />;
33+
},
34+
extractComponentDescription: (component: any) => {
35+
const raw = component?.__docgenInfo?.description ?? '';
36+
return stripExampleBlock(raw);
37+
},
2938
},
3039
},
3140
globalTypes: {
@@ -72,4 +81,13 @@ const preview: Preview = {
7281
],
7382
};
7483

84+
function stripExampleBlock(input = '') {
85+
return (
86+
input
87+
// Remove @example to the next @tag (or the end).
88+
.replace(/\n?@example[\s\S]*?(?=\n@\w+|$)/g, '')
89+
.trim()
90+
);
91+
}
92+
7593
export default preview;

0 commit comments

Comments
 (0)