Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit 1da0b4c

Browse files
authored
Merge pull request #60 from skellock/inline-storybook
Inline Storybook + Storybook-focus components
2 parents b3b21a6 + e627dea commit 1da0b4c

File tree

19 files changed

+192
-53
lines changed

19 files changed

+192
-53
lines changed

.storybook/webpack.config.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ const path = require('path')
22
const genDefaultConfig = require('@storybook/react/dist/server/config/defaults/webpack.config.js')
33

44
module.exports = (config, env) => {
5-
const myConfig = genDefaultConfig(config, env)
5+
const myConfig = genDefaultConfig(config, env)
66

7-
myConfig.module.rules.push({
8-
test: /\.tsx?$/,
9-
loader: 'ts-loader',
10-
exclude: /node_modules/,
11-
include: path.resolve(__dirname, '..', 'src')
12-
})
7+
myConfig.module.rules.push({
8+
test: /\.tsx?$/,
9+
loader: 'ts-loader',
10+
exclude: /node_modules/,
11+
include: path.resolve(__dirname, '..', 'src'),
12+
})
1313

14-
myConfig.resolve.extensions.unshift('.tsx')
15-
myConfig.resolve.extensions.unshift('.ts')
14+
myConfig.resolve.extensions.unshift('.tsx')
15+
myConfig.resolve.extensions.unshift('.ts')
1616

17-
return myConfig
17+
return myConfig
1818
}

fuse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Sparky.task('default', ['copy-html'], () => {
4343
.bundle('renderer')
4444
.instructions('> [renderer/index.tsx] +fuse-box-css')
4545
.plugin(CSSPlugin())
46-
.plugin(CopyPlugin({ useDefault: true, files: ASSETS, dest: 'assets', resolve: 'assets/' }))
46+
.plugin(CopyPlugin({ useDefault: false, files: ASSETS, dest: 'assets', resolve: 'assets/' }))
4747

4848
// and watch & hot reload unless we're bundling for production
4949
if (!isProduction) {

src/main/main-window/load-url.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { join } from 'path'
2+
import { format } from 'url'
3+
4+
export function loadURL(
5+
window: Electron.BrowserWindow,
6+
appPath: string,
7+
showStorybook: boolean = false,
8+
) {
9+
if (showStorybook) {
10+
window.loadURL('http://localhost:6006')
11+
} else {
12+
window.loadURL(
13+
format({
14+
pathname: join(appPath, 'out/index.html'),
15+
protocol: 'file:',
16+
slashes: true,
17+
}),
18+
)
19+
}
20+
}

src/main/main-window/main-window.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { app, BrowserWindow } from 'electron'
2-
import { join } from 'path'
3-
import { format } from 'url'
42
import WindowStateManager = require('electron-window-state-manager')
3+
import { loadURL } from './load-url'
54

65
// default dimensions
76
const DIMENSIONS = { width: 600, height: 500, minWidth: 450, minHeight: 450 }
@@ -52,13 +51,7 @@ export function createMainWindow(appPath: string) {
5251
window.on('resize', () => windowState.saveState(window))
5352

5453
// load entry html page in the renderer.
55-
window.loadURL(
56-
format({
57-
pathname: join(appPath, 'out/index.html'),
58-
protocol: 'file:',
59-
slashes: true,
60-
}),
61-
)
54+
loadURL(window, appPath)
6255

6356
// only appear once we've loaded
6457
window.webContents.on('did-finish-load', () => {

src/main/main.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { app } from 'electron'
1+
import { app, ipcMain } from 'electron'
22
import { createMainWindow } from './main-window/main-window'
3+
import { loadURL } from './main-window/load-url'
34
import * as log from 'electron-log'
45
import * as isDev from 'electron-is-dev'
56
import { createUpdater } from './updater/updater'
@@ -9,14 +10,25 @@ import { createMenu } from './menu/menu'
910
log.transports.file.level = isDev ? false : 'info'
1011
log.transports.console.level = isDev ? 'debug' : false
1112

13+
let window: Electron.BrowserWindow
14+
let showStorybook = false
15+
1216
// usually we'd just use __dirname here, however, the FuseBox
1317
// bundler rewrites that, so we have to get it from Electron.
1418
const appPath = app.getAppPath()
1519

1620
// fires when Electron is ready to start
1721
app.on('ready', () => {
18-
const window = createMainWindow(appPath)
22+
window = createMainWindow(appPath)
1923
createMenu(window)
24+
25+
if (isDev) {
26+
ipcMain.on('storybook-toggle', () => {
27+
log.info('toggle')
28+
showStorybook = !showStorybook
29+
loadURL(window, appPath, showStorybook)
30+
})
31+
}
2032
})
2133

2234
// fires when all windows are closed

src/main/menu/linux-menu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function createLinuxMenu(
1616
submenu: isDev
1717
? [
1818
{ ...shared.reload, accelerator: 'Ctrl+R' },
19+
{ ...shared.storybook, accelerator: 'Ctrl+Shift+S' },
1920
{ ...shared.toggleDevTools, accelerator: 'Ctrl+Alt+I' },
2021
]
2122
: [{ ...shared.fullScreen, accelerator: 'Ctrl+Alt+F' }],

src/main/menu/macos-menu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function createMacMenu(
2626
submenu: isDev
2727
? [
2828
{ ...shared.reload, accelerator: 'Command+R' },
29+
{ ...shared.storybook, accelerator: 'Command+Shift+S' },
2930
{ ...shared.toggleDevTools, accelerator: 'Alt+Command+I' },
3031
]
3132
: [{ ...shared.fullScreen, accelerator: 'Ctrl+Command+F' }],

src/main/menu/shared-menu.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { shell } from 'electron'
1+
import * as log from 'electron-log'
2+
import { shell, ipcMain } from 'electron'
23

34
export function createSharedMenuItems(window: Electron.BrowserWindow) {
45
const visit: Electron.MenuItemConstructorOptions = {
@@ -15,6 +16,14 @@ export function createSharedMenuItems(window: Electron.BrowserWindow) {
1516
},
1617
}
1718

19+
const storybook: Electron.MenuItemConstructorOptions = {
20+
label: 'Toggle Storybook',
21+
click() {
22+
log.info('gonna send')
23+
ipcMain.emit('storybook-toggle')
24+
},
25+
}
26+
1827
const quit: Electron.MenuItemConstructorOptions = { label: 'Quit', role: 'quit' }
1928

2029
const toggleDevTools: Electron.MenuItemConstructorOptions = {
@@ -34,6 +43,7 @@ export function createSharedMenuItems(window: Electron.BrowserWindow) {
3443
return {
3544
visit,
3645
reload,
46+
storybook,
3747
quit,
3848
toggleDevTools,
3949
fullScreen,

src/main/menu/windows-menu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function createWindowsMenu(
1616
submenu: isDev
1717
? [
1818
{ ...shared.reload, accelerator: 'Ctrl+R' },
19+
{ ...shared.storybook, accelerator: 'Ctrl+Shift+S' },
1920
{ ...shared.toggleDevTools, accelerator: 'Ctrl+Alt+I' },
2021
]
2122
: [{ ...shared.fullScreen, accelerator: 'Ctrl+Alt+F' }],
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import * as React from 'react'
22
import { storiesOf } from '@storybook/react'
3+
import {
4+
StorybookStory as Story,
5+
StorybookGroup as Group,
6+
} from '../../../platform/components/storybook'
37

4-
import { FunDog } from './index'
8+
import { FunDog } from './fun-dog'
59

6-
storiesOf('Fun Dog', module).add('default', () => <FunDog />)
10+
storiesOf('Fun Dog', module).add('default', () =>
11+
<Story>
12+
<Group title='is a doggo'>
13+
<div style={{ display: 'flex', flexDirection: 'row' }}>
14+
<FunDog />
15+
</div>
16+
</Group>
17+
</Story>,
18+
)

0 commit comments

Comments
 (0)