Skip to content

Commit 93f952f

Browse files
committed
Compile code before publishing the package
1 parent 7d7564d commit 93f952f

File tree

4 files changed

+18
-106
lines changed

4 files changed

+18
-106
lines changed

.babelrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"react",
4+
["env", { "targets": { "node": "8.0.0" } }]
5+
],
6+
}

decorator.js

-40
This file was deleted.

package.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22
"name": "storybook-styled-components",
33
"version": "1.0.1",
44
"description": "",
5-
"main": "index.js",
5+
"main": "dist/decorator.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build": "babel src --out-dir dist/",
9+
"prepublish": "npm run build"
810
},
911
"author": "Nicolo Taddei <[email protected]>",
1012
"license": "ISC",
1113
"dependencies": {
1214
"@storybook/addons": "^3.2.14",
1315
"react": "^16.0.0",
1416
"styled-components": "^2.2.3"
17+
},
18+
"devDependencies": {
19+
"babel-cli": "^6.26.0",
20+
"babel-core": "^6.26.0",
21+
"babel-plugin-transform-class-properties": "^6.24.1",
22+
"babel-preset-env": "^1.6.1",
23+
"babel-preset-react": "^6.24.1"
1524
}
1625
}

register.js

100755100644
+1-64
Original file line numberDiff line numberDiff line change
@@ -1,64 +1 @@
1-
import React from 'react'
2-
import addonAPI from '@storybook/addons'
3-
4-
class PanelContainer extends React.Component {
5-
state = {
6-
theme: null,
7-
themes: {},
8-
initialised: false,
9-
}
10-
11-
constructor(props) {
12-
super()
13-
14-
props.channel.on('storybook-styled-components/init', this.onInit)
15-
}
16-
17-
onInit = themes => {
18-
const queryTheme = this.props.api.getQueryParam('currentTheme')
19-
20-
const theme = queryTheme
21-
? queryTheme
22-
: this.state.theme ? this.state.theme : Object.keys(themes)[0]
23-
24-
this.setTheme(themes, theme)
25-
}
26-
27-
updateTheme = e => {
28-
const newTheme = e.target.value
29-
this.setTheme(this.state.themes, newTheme)
30-
}
31-
32-
setTheme(themes, theme) {
33-
this.setState({ themes, theme })
34-
this.props.channel.emit('storybook-styled-components/update', theme)
35-
this.props.api.setQueryParams({ currentTheme: theme })
36-
}
37-
38-
render() {
39-
const { theme, themes } = this.state
40-
41-
if (!theme) return <div>Addon is initialising</div>
42-
43-
return (
44-
<div>
45-
<select value={this.state.theme} onChange={this.updateTheme}>
46-
{Object.keys(themes).map(theme => (
47-
<option key={theme} value={theme}>
48-
{theme}
49-
</option>
50-
))}
51-
</select>
52-
</div>
53-
)
54-
}
55-
}
56-
57-
addonAPI.register('storybook-styled-components', storybookAPI => {
58-
addonAPI.addPanel('storybook-styled-components/panel', {
59-
title: 'Theme Picker',
60-
render: () => (
61-
<PanelContainer channel={addonAPI.getChannel()} api={storybookAPI} />
62-
),
63-
})
64-
})
1+
require('./dist/register');

0 commit comments

Comments
 (0)