Using Saas UI in Storybook
A guide for using Saas UI with Storybook
1
Install the required dependencies for Saas UI and Storybook.
npm i @storybook/addon-themes @saas-ui/react@next @chakra-ui/react @emotion/react
2
Edit the .storybook/preview.tsx
file to include the Saas UI provider.
import { SuiProvider, defaultSystem } from '@saas-ui/react'
import type { Preview } from '@storybook/react'
const preview: Preview = {
// ...
decorators: [
(Story) => (
<SuiProvider value={defaultSystem}>
<Story />
</SuiProvider>
),
],
}
export default preview
3
Use the withThemeByClassName
decorator from @storybook/addon-themes
to add a
color mode toggle to the Storybook toolbar.
import { withThemeByClassName } from '@storybook/addon-themes'
import type { Preview, ReactRenderer } from '@storybook/react'
const preview: Preview = {
decorators: [
// ...
withThemeByClassName({
defaultTheme: 'light',
themes: { light: '', dark: 'dark' },
}),
],
}
export default preview
4
npm run storybook
5
Use Saas UI components in your stories.
import { Button } from '@saas-ui/react'
export const SampleStory = {
render() {
return <Button>Click me</Button>
},
}