|
| 1 | +import React from 'react' |
| 2 | +import type { Parameters, Preview } from '@storybook/react-vite' |
| 3 | +import { withThemeFromJSXProvider } from '@storybook/addon-themes' |
| 4 | +import { |
| 5 | + createGlobalStyle, |
| 6 | + ThemeProvider as StyledThemeProvider, |
| 7 | +} from 'styled-components' |
| 8 | +import { CommonStyles, themeDark, themeLight, themeOld } from '@redis-ui/styles' |
| 9 | +import 'modern-normalize/modern-normalize.css' |
| 10 | +import '@redis-ui/styles/normalized-styles.css' |
| 11 | +import '@redis-ui/styles/fonts.css' |
| 12 | +import { RootStoryLayout } from './RootStoryLayout' |
| 13 | +import { StoryContextProvider } from './Story.context' |
| 14 | +import { useStoryContext } from 'storybook/internal/preview-api' |
| 15 | +import { TooltipProvider } from '@redis-ui/components' |
| 16 | +import { type Theme } from 'uiSrc/components/base/theme/types' |
| 17 | +// import { store } from 'uiSrc/utils/test-utils' |
| 18 | +import { Provider } from 'react-redux' |
| 19 | +import { store } from 'uiSrc/slices/store' |
| 20 | +import Router from 'uiSrc/Router' |
| 21 | + |
| 22 | +const parameters: Parameters = { |
| 23 | + parameters: { |
| 24 | + layout: 'centered', |
| 25 | + }, |
| 26 | + actions: { argTypesRegex: '^on[A-Z].*' }, |
| 27 | + controls: { |
| 28 | + disableSaveFromUI: true, |
| 29 | + matchers: { |
| 30 | + color: /(background|color)$/i, |
| 31 | + date: /Date$/, |
| 32 | + }, |
| 33 | + expanded: true, |
| 34 | + sort: 'requiredFirst', |
| 35 | + exclude: ['theme'], |
| 36 | + }, |
| 37 | + docs: { |
| 38 | + toc: true, |
| 39 | + controls: { |
| 40 | + sort: 'requiredFirst', |
| 41 | + }, |
| 42 | + }, |
| 43 | + options: { |
| 44 | + storySort: { |
| 45 | + method: 'alphabetical', |
| 46 | + order: ['Getting Started', 'Playground', '*'], |
| 47 | + }, |
| 48 | + }, |
| 49 | +} |
| 50 | + |
| 51 | +const GlobalStoryStyles = createGlobalStyle` |
| 52 | + .sb-show-main, .docs-story { |
| 53 | + background: ${({ theme }: { theme: Theme }) => theme.globals.body.bgColor}; |
| 54 | + color: ${({ theme }: { theme: Theme }) => theme.globals.body.textColor}; |
| 55 | + } |
| 56 | +` |
| 57 | + |
| 58 | +const preview: Preview = { |
| 59 | + parameters, |
| 60 | + decorators: [ |
| 61 | + (Story) => ( |
| 62 | + <StoryContextProvider value={useStoryContext()}> |
| 63 | + <Router> |
| 64 | + <Provider store={store}> |
| 65 | + <TooltipProvider> |
| 66 | + <RootStoryLayout storyContext={useStoryContext()}> |
| 67 | + <CommonStyles /> |
| 68 | + <Story /> |
| 69 | + </RootStoryLayout> |
| 70 | + </TooltipProvider> |
| 71 | + </Provider> |
| 72 | + </Router> |
| 73 | + </StoryContextProvider> |
| 74 | + ), |
| 75 | + withThemeFromJSXProvider({ |
| 76 | + themes: { |
| 77 | + light: themeLight, |
| 78 | + dark: themeDark, |
| 79 | + obsolete: themeOld, |
| 80 | + }, |
| 81 | + defaultTheme: 'light', |
| 82 | + Provider: StyledThemeProvider, |
| 83 | + GlobalStyles: GlobalStoryStyles, |
| 84 | + }), |
| 85 | + ], |
| 86 | +} |
| 87 | + |
| 88 | +export default preview |
0 commit comments