-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrade to Storybook v5 [SL-2026] (#3)
* feat: upgrade to Storybook v5 * refactor: use hooks in themes addon * chore: install missing deps * fix: don't import Toaster * style: btn paddings * style: btn background
- Loading branch information
Showing
11 changed files
with
4,666 additions
and
2,441 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module.exports = { | ||
preset: '@stoplight/scripts', | ||
testEnvironment: 'jsdom', | ||
setupTestFrameworkScriptFile: './setupTests.ts', | ||
setupFilesAfterEnv: ['./setupTests.ts'], | ||
snapshotSerializers: ['enzyme-to-json/serializer'], | ||
}; |
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 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 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,68 @@ | ||
import { Box } from '@stoplight/ui-kit/Box'; | ||
import { Button } from '@stoplight/ui-kit/Button'; | ||
import Channel from '@storybook/channels'; | ||
import * as React from 'react'; | ||
|
||
interface IPanel { | ||
active: boolean; | ||
channel: Channel; | ||
} | ||
|
||
export const Panel: React.FunctionComponent<IPanel> = ({ active, channel }) => { | ||
const [themeName, setThemeName] = React.useState(sessionStorage.themeName || 'light'); | ||
const [themes, setThemes] = React.useState<string[]>([]); | ||
|
||
const setTheme = React.useCallback<(theme: string) => void>( | ||
theme => { | ||
setThemeName(theme); | ||
sessionStorage.themeName = theme; | ||
}, | ||
[setThemeName] | ||
); | ||
|
||
React.useEffect( | ||
() => { | ||
channel.on('themes/list', setThemes); | ||
|
||
return () => { | ||
channel.removeListener('themes/list', setThemes); | ||
}; | ||
}, | ||
[channel, setThemes] | ||
); | ||
|
||
React.useEffect( | ||
() => { | ||
channel.on('themes/setTheme', setTheme); | ||
|
||
return () => { | ||
channel.removeListener('themes/setTheme', setTheme); | ||
}; | ||
}, | ||
[channel, setTheme] | ||
); | ||
|
||
if (!active) return null; | ||
|
||
return ( | ||
<Box m="25px" width="100%" overflow="auto"> | ||
{themes.map((theme: string) => ( | ||
<Button | ||
key={theme} | ||
onClick={() => channel.emit('themes/setTheme', theme)} | ||
display="inline-block" | ||
py={2} | ||
px={3} | ||
fontWeight={700} | ||
mr={3} | ||
borderRadius={3} | ||
color={theme === themeName ? 'green' : undefined} | ||
cursor={theme === themeName ? 'default' : 'pointer'} | ||
backgroundColor={theme === themeName ? 'eee' : 'transparent'} | ||
> | ||
{theme} | ||
</Button> | ||
))} | ||
</Box> | ||
); | ||
}; |
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,45 @@ | ||
import addons, { makeDecorator, StoryContext } from '@storybook/addons'; | ||
import Channel from '@storybook/channels'; | ||
import * as React from 'react'; | ||
|
||
interface IThemeContainer { | ||
channel: Channel; | ||
children: React.ReactElement; | ||
themes: string[]; | ||
} | ||
|
||
export const withThemes = ({ ThemeProvider, themes, zones }: any) => | ||
makeDecorator({ | ||
name: 'withThemes', | ||
wrapper: (story: (context: StoryContext) => React.ReactNode, context: StoryContext) => ( | ||
<ThemeContainer channel={addons.getChannel()} themes={themes}> | ||
<ThemeProvider zones={zones}>{story(context)}</ThemeProvider> | ||
</ThemeContainer> | ||
), | ||
}); | ||
|
||
const ThemeContainer: React.FunctionComponent<IThemeContainer> = ({ channel, themes, children }) => { | ||
const [themeName, setThemeName] = React.useState(sessionStorage.themeName || 'light'); | ||
|
||
React.useEffect( | ||
() => { | ||
channel.emit('themes/list', themes); | ||
}, | ||
[themes] | ||
); | ||
|
||
React.useEffect( | ||
() => { | ||
channel.on('themes/setTheme', setThemeName); | ||
|
||
return () => { | ||
channel.removeListener('themes/setTheme', setThemeName); | ||
}; | ||
}, | ||
[channel, setThemeName] | ||
); | ||
|
||
return React.cloneElement(children, { | ||
theme: { base: themeName }, | ||
}); | ||
}; |
File renamed without changes.
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 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
Oops, something went wrong.