-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate storybook to TS (#375)
- Loading branch information
1 parent
27a4945
commit 6e5aaca
Showing
5 changed files
with
1,005 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React, { useEffect } from 'react'; | ||
|
||
import { Box, useColorMode } from '@chakra-ui/react'; | ||
import { Preview } from '@storybook/react'; | ||
import { themes } from '@storybook/theming'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { useDarkMode } from 'storybook-dark-mode'; | ||
|
||
import { Providers } from '../src/app/Providers'; | ||
import i18nGlobal from '../src/lib/i18n/config'; | ||
import { | ||
AVAILABLE_LANGUAGES, | ||
DEFAULT_LANGUAGE_KEY, | ||
} from '../src/lib/i18n/constants'; | ||
// @ts-ignore don't want to implement a d.ts declaration for storybook only | ||
import logoReversed from './logo-reversed.svg'; | ||
// @ts-ignore don't want to implement a d.ts declaration for storybook only | ||
import logo from './logo.svg'; | ||
|
||
const DocumentationWrapper = ({ children, context }) => { | ||
const { i18n } = useTranslation(); | ||
const isDarkMode = useDarkMode(); | ||
const { colorMode, setColorMode } = useColorMode(); | ||
|
||
// Update color mode | ||
useEffect(() => { | ||
// Add timeout to prevent unsync color mode between docs and classic modes | ||
const timer = setTimeout(() => { | ||
if (isDarkMode) { | ||
setColorMode('dark'); | ||
} else { | ||
setColorMode('light'); | ||
} | ||
}); | ||
return () => clearTimeout(timer); | ||
}, [isDarkMode]); | ||
|
||
// Update language | ||
useEffect(() => { | ||
i18n.changeLanguage(context.globals.locale); | ||
}, [context.globals.locale]); | ||
|
||
return ( | ||
<Box | ||
id="start-ui-storybook-wrapper" | ||
p="4" | ||
pb="8" | ||
bg={colorMode === 'dark' ? 'gray.900' : 'white'} | ||
flex="1" | ||
> | ||
{children} | ||
</Box> | ||
); | ||
}; | ||
|
||
const preview: Preview = { | ||
globalTypes: { | ||
locale: { | ||
name: 'Locale', | ||
description: 'Internationalization locale', | ||
defaultValue: DEFAULT_LANGUAGE_KEY, | ||
toolbar: { | ||
icon: 'globe', | ||
items: AVAILABLE_LANGUAGES.map(({ key }) => ({ | ||
value: key, | ||
title: i18nGlobal.t(`languages.${String(key)}`), | ||
})), | ||
}, | ||
}, | ||
}, | ||
parameters: { | ||
options: { | ||
storySort: { | ||
order: ['StyleGuide', 'Components', 'Fields', 'App Layout'], | ||
}, | ||
}, | ||
actions: { argTypesRegex: '^on[A-Z].*' }, | ||
darkMode: { | ||
dark: { | ||
...themes.dark, | ||
brandImage: logoReversed.src, | ||
brandTitle: 'Start UI', | ||
}, | ||
light: { | ||
...themes.light, | ||
brandImage: logo.src, | ||
brandTitle: 'Start UI', | ||
}, | ||
}, | ||
layout: 'fullscreen', | ||
backgrounds: { disable: true, grid: { disable: true } }, | ||
}, | ||
decorators: [ | ||
(story, context) => ( | ||
<Providers> | ||
<MemoryRouter> | ||
<DocumentationWrapper context={context}> | ||
{/* Calling as a function to avoid errors. Learn more at: | ||
* https://github.com/storybookjs/storybook/issues/15223#issuecomment-1092837912 | ||
*/} | ||
{story(context)} | ||
</DocumentationWrapper> | ||
</MemoryRouter> | ||
</Providers> | ||
), | ||
], | ||
}; | ||
|
||
export default preview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
6e5aaca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
start-ui – ./
start-ui.vercel.app
demo.start-ui.com
start-ui-git-master-bearstudio.vercel.app
start-ui-bearstudio.vercel.app