Skip to content

Commit

Permalink
Merge pull request #360 from omnivore-app/OMN-SB
Browse files Browse the repository at this point in the history
[OMN-SB]: Setup storybook
  • Loading branch information
jacksonh authored Apr 19, 2022
2 parents 44081f5 + 643f57f commit 04708ad
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 3 deletions.
30 changes: 30 additions & 0 deletions packages/web/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require('path')

module.exports = {
stories: [
"../stories/**/*.stories.mdx",
"../stories/**/*.stories.@(js|jsx|ts|tsx)"
],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
"storybook-addon-next-router"
],
framework: "@storybook/react",
core: {
builder: "webpack5"
},
typescript: {
reactDocgen: false
},
webpackFinal: async (config, { configType }) => {
config.resolve.roots = [
path.resolve(__dirname, '../public'),
'node_modules',
];

// Return the altered config
return config;
},
}
42 changes: 42 additions & 0 deletions packages/web/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { RouterContext } from 'next/dist/shared/lib/router-context';
import * as NextImage from 'next/image';
import { getCssText } from '../components/tokens/stitches.config';
import "../styles/globals.css";

const OriginalNextImage = NextImage.default;

Object.defineProperty(NextImage, 'default', {
configurable: true,
value: props => <OriginalNextImage {...props} unoptimized />
})

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
nextRouter: {
Provider: RouterContext.Provider
}
}

export const decorators = [
(Story, context) => {
return (
<>
<style
id="stitches"
dangerouslySetInnerHTML={{
__html: getCssText(),
}}
/>
<div className='Gray'>
<Story {...context} />
</div>
</>
);
}
]
Empty file added packages/web/index.d.ts
Empty file.
17 changes: 15 additions & 2 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"test": "jest",
"test:watch": "jest --watch",
"test:build": "jest && next build",
"upgrade-psdpdfkit": "cp -R '../../node_modules/pspdfkit/dist/pspdfkit-lib' public/pspdfkit-lib"
"upgrade-psdpdfkit": "cp -R '../../node_modules/pspdfkit/dist/pspdfkit-lib' public/pspdfkit-lib",
"storybook": "start-storybook -p 6006 -s ./public",
"build-storybook": "build-storybook -s public"
},
"dependencies": {
"@radix-ui/react-avatar": "^0.1.1",
Expand Down Expand Up @@ -45,6 +47,15 @@
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/core": "^7.17.5",
"@storybook/addon-actions": "^6.4.22",
"@storybook/addon-essentials": "^6.4.22",
"@storybook/addon-interactions": "^6.4.22",
"@storybook/addon-links": "^6.4.22",
"@storybook/builder-webpack5": "^6.4.22",
"@storybook/manager-webpack5": "^6.4.22",
"@storybook/react": "^6.4.22",
"@storybook/testing-library": "^0.0.9",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "13.5.0",
Expand All @@ -57,11 +68,13 @@
"@types/segment-analytics": "^0.0.34",
"@types/uuid": "^8.3.1",
"babel-jest": "^27.4.5",
"babel-loader": "^8.2.3",
"eslint-config-next": "12.0.7",
"eslint-plugin-functional": "^4.0.2",
"eslint-plugin-react": "^7.28.0",
"graphql": "^15.6.1",
"jest": "^27.4.5"
"jest": "^27.4.5",
"storybook-addon-next-router": "^3.1.1"
},
"volta": {
"node": "14.18.0",
Expand Down
53 changes: 53 additions & 0 deletions packages/web/stories/Snackbar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { Toaster, ToastPosition } from 'react-hot-toast'
import { showErrorToast, showSuccessToast } from '../lib/toastHelpers'
import { Button } from '../components/elements/Button'

export default {
title: 'Components/Snackbar',
component: Toaster,
argTypes: {
position: {
description: 'The position of the snackbar',
options: [
'top-left',
'top-center',
'top-right',
'bottom-right',
'bottom-center',
'bottom-left',
],
control: { type: 'select' },
},
},
} as ComponentMeta<typeof Toaster>

const Template = ({ showToast, position }: { showToast: () => void; position?: ToastPosition }) => (
<div>
<Toaster position={position} />
<div
style={{
height: '15rem',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<Button style='ctaGray' onClick={showToast}>
Show Toast
</Button>
</div>
</div>
)

export const SuccessSnackbar: ComponentStory<typeof Toaster> = (args: any) => {
return (
<Template {...args} showToast={() => showSuccessToast('Success Message')} />
)
}

export const ErrorSnackbar: ComponentStory<typeof Toaster> = (args: any) => {
return (
<Template {...args} showToast={() => showErrorToast('Error Message!')} />
)
}
10 changes: 9 additions & 1 deletion packages/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
"isolatedModules": true,
"jsx": "preserve",
"types": ["node", "jest", "@testing-library/jest-dom"],
"incremental": true
"incremental": true,
"paths": {
"@emotion/core": [
"./index.d.ts"
],
"@storybook/theming": [
"./index.d.ts"
]
}
},
"include": ["additional.d.ts", "next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
Expand Down

2 comments on commit 04708ad

@vercel
Copy link

@vercel vercel bot commented on 04708ad Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 04708ad Apr 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.