11import { useMemo } from 'react' ;
2+ import { DocsContainer } from '@storybook/addon-docs/blocks' ;
23import type { Preview } from '@storybook/react' ;
34import { App as AntdApp , ConfigProvider as AntdConfigProvider , theme } from 'antd' ;
45import enUS from 'antd/es/locale/en_US' ;
56import zhCN from 'antd/es/locale/zh_CN' ;
6- // import { ensure, themes } from 'storybook/theming';
7+ import { ensure , themes } from 'storybook/theming' ;
78import ConfigProvider from '../src/components/ConfigProvider' ;
89import 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 ? @ e x a m p l e [ \s \S ] * ?(? = \n @ \w + | $ ) / g, '' )
89+ . trim ( )
90+ ) ;
91+ }
92+
7593export default preview ;
0 commit comments