Skip to content

Commit 089ce87

Browse files
authored
Initiate BoostNote storybook (#702)
* Configure babelrc for storybook * Introduce a storybook * Refactor theme * Create utils/theme * Create Button storybook * Apply prettier
1 parent 7de2968 commit 089ce87

File tree

10 files changed

+11720
-1582
lines changed

10 files changed

+11720
-1582
lines changed

.babelrc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
{
22
"presets": [
3-
["@babel/preset-env", { "targets": "last 2 Chrome versions" }],
3+
[
4+
"@babel/preset-env",
5+
{ "targets": "last 2 Chrome versions", "loose": true }
6+
],
47
"@babel/preset-typescript",
58
"@babel/preset-react"
69
],
7-
"plugins": ["@babel/plugin-proposal-class-properties"]
10+
"plugins": [
11+
["@babel/plugin-proposal-class-properties", { "loose": true }],
12+
["@babel/plugin-proposal-private-methods", { "loose": true }],
13+
["@babel/plugin-proposal-private-property-in-object", { "loose": true }]
14+
]
815
}

.storybook/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
3+
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
4+
}

.storybook/preview.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const parameters = {
2+
actions: { argTypesRegex: '^on[A-Z].*' },
3+
}

package-lock.json

Lines changed: 11591 additions & 1559 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"test": "jest -c jest.json",
3030
"test:watch": "jest -c jest.json --watch",
3131
"tsc": "tsc --watch --noEmit",
32-
"ico": "png2icons static/logo.png static/icon -allwe"
32+
"ico": "png2icons static/logo.png static/icon -allwe",
33+
"storybook": "start-storybook -p 6006",
34+
"build-storybook": "build-storybook"
3335
},
3436
"keywords": [
3537
"markdown",
@@ -42,9 +44,15 @@
4244
"devDependencies": {
4345
"@babel/core": "^7.6.0",
4446
"@babel/plugin-proposal-class-properties": "^7.5.5",
47+
"@babel/plugin-proposal-private-methods": "^7.12.1",
48+
"@babel/plugin-proposal-private-property-in-object": "^7.12.1",
4549
"@babel/preset-env": "^7.6.0",
4650
"@babel/preset-react": "^7.0.0",
4751
"@babel/preset-typescript": "^7.6.0",
52+
"@storybook/addon-actions": "^6.1.10",
53+
"@storybook/addon-essentials": "^6.1.10",
54+
"@storybook/addon-links": "^6.1.10",
55+
"@storybook/react": "^6.1.10",
4856
"@testing-library/react-hooks": "^2.0.1",
4957
"@types/codemirror": "0.0.98",
5058
"@types/dashify": "^1.0.0",
@@ -73,6 +81,7 @@
7381
"@types/webpack-env": "^1.14.0",
7482
"@typescript-eslint/eslint-plugin": "^2.3.0",
7583
"@typescript-eslint/parser": "^2.3.0",
84+
"babel-loader": "^8.2.2",
7685
"chalk": "^4.0.0",
7786
"copy-webpack-plugin": "^6.2.1",
7887
"cross-env": "^6.0.0",

src/components/App.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import React, { useMemo, useState, useEffect } from 'react'
22
import Router from './Router'
33
import GlobalStyle from './GlobalStyle'
44
import { ThemeProvider } from 'styled-components'
5-
import { legacyTheme } from '../themes/legacy'
6-
import { darkTheme } from '../themes/dark'
7-
import { lightTheme } from '../themes/light'
8-
import { sepiaTheme } from '../themes/sepia'
9-
import { solarizedDarkTheme } from '../themes/solarizedDark'
5+
import { selectTheme } from '../themes'
106
import Dialog from './organisms/Dialog'
117
import { useDb } from '../lib/db'
128
import PreferencesModal from './PreferencesModal/PreferencesModal'
@@ -374,20 +370,5 @@ const App = () => {
374370
</ThemeProvider>
375371
)
376372
}
377-
function selectTheme(theme: string) {
378-
switch (theme) {
379-
case 'legacy':
380-
return legacyTheme
381-
case 'light':
382-
return lightTheme
383-
case 'sepia':
384-
return sepiaTheme
385-
case 'solarizedDark':
386-
return solarizedDarkTheme
387-
case 'dark':
388-
default:
389-
return darkTheme
390-
}
391-
}
392373

393374
export default App

src/stories/Button.stories.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Meta } from '@storybook/react/types-6-0'
2+
3+
import { FormPrimaryButton } from '../components/atoms/form'
4+
import { createThemedTemplate } from './utils/themes'
5+
6+
const { Template, themeArgType } = createThemedTemplate(FormPrimaryButton)
7+
8+
export default {
9+
title: 'Legacy/Atoms/FormPrimaryButton',
10+
component: FormPrimaryButton,
11+
argTypes: {
12+
theme: themeArgType,
13+
},
14+
} as Meta
15+
16+
export const Primary = Template.bind({})
17+
Primary.args = {
18+
children: 'Button',
19+
}

src/stories/Index.mdx

Whitespace-only changes.

src/stories/utils/themes.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React, { FC, PropsWithChildren, ComponentType } from 'react'
2+
import { Story } from '@storybook/react/types-6-0'
3+
import { ThemeProvider } from 'styled-components'
4+
5+
import { ThemeTypes, selectTheme } from '../../themes'
6+
import styled from '../../lib/styled'
7+
8+
interface ThemedWrapperProps {
9+
theme?: ThemeTypes
10+
}
11+
12+
export const ThemedWrapper: FC<ThemedWrapperProps> = ({
13+
theme = 'dark',
14+
children,
15+
}) => {
16+
return (
17+
<ThemeProvider theme={selectTheme(theme)}>
18+
<StyledBackground>{children}</StyledBackground>
19+
</ThemeProvider>
20+
)
21+
}
22+
23+
const StyledBackground = styled.div`
24+
position: absolute;
25+
top: 0;
26+
left: 0;
27+
right: 0;
28+
bottom: 0;
29+
padding: 10px;
30+
background-color: ${({ theme }) => theme.backgroundColor};
31+
box-sizing: border-box;
32+
`
33+
34+
export type ThemedStory<P> = Story<{ theme: ThemeTypes } & PropsWithChildren<P>>
35+
36+
export function createThemedTemplate<P = {}>(
37+
Component: ComponentType<P>
38+
): {
39+
Template: ThemedStory<P>
40+
themeArgType: {}
41+
} {
42+
return {
43+
Template: ({ theme, ...args }: any) => {
44+
return (
45+
<ThemedWrapper theme={theme}>
46+
<Component {...args} />
47+
</ThemedWrapper>
48+
)
49+
},
50+
themeArgType: {
51+
defaultValue: 'dark',
52+
control: {
53+
type: 'inline-radio',
54+
options: ['light', 'dark', 'sepia', 'solarizedDark', 'legacy'],
55+
},
56+
},
57+
}
58+
}

src/themes/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { lightTheme } from './light'
2+
import { darkTheme } from './dark'
3+
import { sepiaTheme } from './sepia'
4+
import { solarizedDarkTheme } from './solarizedDark'
5+
import { legacyTheme } from './legacy'
6+
7+
export { lightTheme, darkTheme, sepiaTheme, solarizedDarkTheme, legacyTheme }
8+
9+
export type ThemeTypes = 'light' | 'dark' | 'sepia' | 'solarizedDark' | 'legacy'
10+
11+
export function selectTheme(theme: string) {
12+
switch (theme) {
13+
case 'legacy':
14+
return legacyTheme
15+
case 'light':
16+
return lightTheme
17+
case 'sepia':
18+
return sepiaTheme
19+
case 'solarizedDark':
20+
return solarizedDarkTheme
21+
case 'dark':
22+
default:
23+
return darkTheme
24+
}
25+
}

0 commit comments

Comments
 (0)