Skip to content

Commit 9ba335d

Browse files
author
joeshub
committed
adding React JSS
1 parent cb73b32 commit 9ba335d

File tree

9 files changed

+5562
-1
lines changed

9 files changed

+5562
-1
lines changed

11-react-jss/button/App.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, { Component } from 'react'
2+
import pkg from './package.json'
3+
import Button from './Button'
4+
5+
export default class App extends Component {
6+
7+
state = {
8+
depressed: false
9+
}
10+
11+
onButtonClicked = () => this.setState({
12+
depressed: !this.state.depressed
13+
})
14+
15+
render () {
16+
const { depressed } = this.state
17+
18+
return (
19+
<main>
20+
<p>{pkg.description}</p>
21+
<Button
22+
onClick={ this.onButtonClicked }
23+
depressed={ depressed }
24+
>Button</Button>
25+
</main>
26+
)
27+
}
28+
}

11-react-jss/button/Button.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React, { Component } from 'react'
2+
import injectSheet from 'react-jss'
3+
4+
const styles = {
5+
btn: {
6+
display: 'inline-block',
7+
outline: 'none',
8+
textAlign: 'center',
9+
font: 'bold 32px helvetica',
10+
padding: '20px 40px',
11+
border: 0,
12+
cursor: 'pointer',
13+
color: '#fff',
14+
transition: 'background-color 300ms',
15+
transform: 'translateZ(0)',
16+
backfaceVisibility: 'visible',
17+
backgroundColor: props => props.depressed ? props.bgDepressed : props.bgColor,
18+
'&:hover': {
19+
backgroundColor: props => props.depressed ? props.bgDepressed : props.bgHover
20+
}
21+
}
22+
}
23+
24+
class Button extends Component {
25+
26+
static defaultProps = {
27+
bgColor: '#ec4800',
28+
bgHover: '#f98d00',
29+
bgDepressed: '#bebebe'
30+
}
31+
32+
onButtonClicked = () => {
33+
this.props.onClick && this.props.onClick()
34+
}
35+
36+
render () {
37+
const { depressed, classes, bgColor, bgHover, bgDepressed, ...otherProps } = this.props
38+
39+
return (
40+
<button
41+
className={ classes.btn }
42+
onClick={ this.onButtonClicked }
43+
{ ...otherProps }
44+
/>
45+
)
46+
}
47+
}
48+
49+
export default injectSheet(styles)(Button)

11-react-jss/button/entry.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react'
2+
import { render } from 'react-dom'
3+
import { AppContainer } from 'react-hot-loader'
4+
import App from './App'
5+
6+
render (
7+
<AppContainer>
8+
<App />
9+
</AppContainer>,
10+
document.getElementById('app')
11+
)
12+
13+
// Hot Module Replacement API
14+
if (module.hot) {
15+
module.hot.accept('./App', () => {
16+
const NextApp = require('./App').default
17+
render(
18+
<AppContainer>
19+
<NextApp/>
20+
</AppContainer>,
21+
document.getElementById('app')
22+
)
23+
})
24+
}

11-react-jss/button/package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "react-jss-button",
3+
"version": "1.0.0",
4+
"description": "Button - React JSS",
5+
"author": "Joe Seifi",
6+
"license": "ISC",
7+
"main": "build/app.js",
8+
"scripts": {
9+
"start": "../../node_modules/.bin/cross-env NODE_ENV=development node ../../scripts/server-button.js",
10+
"build": "../../node_modules/.bin/cross-env NODE_ENV=production ../../node_modules/.bin/webpack --config webpack.build.js --progress --colors"
11+
},
12+
"devDependencies": {
13+
"babel-core": "^6.23.1",
14+
"babel-eslint": "^7.1.1",
15+
"babel-loader": "^6.3.2",
16+
"babel-plugin-transform-decorators-legacy": "^1.3.4",
17+
"babel-polyfill": "^6.23.0",
18+
"babel-preset-es2015": "^6.22.0",
19+
"babel-preset-react": "^6.23.0",
20+
"babel-preset-stage-0": "^6.22.0",
21+
"cross-env": "^3.1.4",
22+
"css-loader": "^0.26.1",
23+
"eslint": "^3.15.0",
24+
"eslint-plugin-react": "^6.10.0",
25+
"express": "^4.14.1",
26+
"extract-text-webpack-plugin": "^2.0.0-rc.3",
27+
"html-webpack-plugin": "^2.28.0",
28+
"json-loader": "^0.5.4",
29+
"react": "^15.4.2",
30+
"react-dom": "^15.4.2",
31+
"react-hot-loader": "^3.0.0-beta.6",
32+
"react-jss": "^8.3.3",
33+
"style-loader": "^0.13.1",
34+
"webpack": "^2.2.1",
35+
"webpack-dev-middleware": "^1.10.1",
36+
"webpack-hot-middleware": "^2.17.0"
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var path = require('path')
2+
var webpack = require('webpack')
3+
var HtmlWebpackPlugin = require('html-webpack-plugin')
4+
5+
module.exports = {
6+
entry: ['babel-polyfill','./entry.js'],
7+
output: {
8+
path: path.join(__dirname + '/build'),
9+
filename: 'app.js',
10+
publicPath: ''
11+
},
12+
plugins: [
13+
new HtmlWebpackPlugin({ inject: true, template: '../../templates/plain.ejs' }),
14+
new webpack.optimize.OccurrenceOrderPlugin(),
15+
new webpack.DefinePlugin({
16+
'process.env': {
17+
'NODE_ENV': JSON.stringify('production')
18+
}
19+
})
20+
],
21+
module: {
22+
rules: [
23+
{
24+
test: /\.js$/,
25+
exclude: /node_modules/,
26+
use: 'babel-loader'
27+
},
28+
{
29+
test: /\.css$/,
30+
use: ['style-loader','css-loader']
31+
},
32+
{
33+
test: /\.json$/,
34+
use: 'json-loader'
35+
}
36+
]
37+
}
38+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var path = require('path')
2+
var webpack = require('webpack')
3+
var HtmlWebpackPlugin = require('html-webpack-plugin')
4+
var settings = require('../../scripts/settings.js')
5+
var devServer = settings.devServer
6+
7+
module.exports = {
8+
devServer: devServer,
9+
devtool: 'source-map',
10+
entry: [
11+
'react-hot-loader/patch',
12+
'webpack-hot-middleware/client?reload=1',
13+
'babel-polyfill',
14+
'./entry'
15+
],
16+
output: {
17+
path: path.join(__dirname),
18+
filename: 'bundle.js',
19+
publicPath: '/'
20+
},
21+
plugins: [
22+
new HtmlWebpackPlugin({ inject: true, template: '../../templates/server.ejs' }),
23+
new webpack.HotModuleReplacementPlugin(),
24+
new webpack.NoEmitOnErrorsPlugin()
25+
],
26+
module: {
27+
rules: [
28+
{
29+
test: /\.js$/,
30+
exclude: /node_modules/,
31+
use: 'babel-loader'
32+
},
33+
{
34+
test: /\.css$/,
35+
use: ['style-loader','css-loader']
36+
},
37+
{
38+
test: /\.json$/,
39+
use: 'json-loader'
40+
}
41+
]
42+
}
43+
}

0 commit comments

Comments
 (0)