Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedyrose committed Jan 22, 2018
0 parents commit f494e67
Show file tree
Hide file tree
Showing 10 changed files with 4,423 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"presets": [
"react"
],
"env": {
"es5": {
"presets": [
"es2015"
]
}
},
"plugins": [
"syntax-dynamic-import",
["transform-react-remove-prop-types", {
"mode": "wrap"
}]
]
}
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# System generated files
.DS_Store

# Logs
logs
*.log
npm-debug.log*

# Dependency directories
node_modules/

# Development/Environment
.env
.env.*
dist
.next
json
public
.cache
envdotjs-key
env.js
.serverless
dist-es6/
dist-es5/
dist-modules/

# Temporary
temp
temp-*
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.4.0
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# React Component Boilerplate

A simple React boilerplate that outputs to ES5 and ES6.

## Getting started

```bash
git clone [email protected]:escaladesports/react-component-boilerplate.git --depth=1 your-component
cd your-component
rm -rf .git
```

Also make sure to edit the `package.json` file with a new name, version number, author, and anything else you might need.

## Usage

- `yarn dev`: Runs a local dev server from the `dev` directory
- `yarn analyze`: View bundle sizes
15 changes: 15 additions & 0 deletions dev/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import { render } from 'react-dom'
import Img from '../src/index'

const containerEl = document.createElement('div')
document.body.appendChild(containerEl)

render(
<Img
src='http:https://via.placeholder.com/500x1000'
width={500}
height={1000}
/>,
containerEl
)
4 changes: 4 additions & 0 deletions dev/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<html>
<body>
<script src="index.js"></script>
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "react-hubspot-form",
"version": "0.0.0",
"keywords": [
"react",
"hubspot",
"form",
"integration"
],
"main": "dist-es5/index.js",
"browser": "dist-es5/index.js",
"module": "dist-es6/index.js",
"jsnext:main": "dist-es6/index.js",
"author": "Kennedy Rose <[email protected]>",
"repository": {
"type": "git",
"url": "https://github.com/escaladesports/react-hubspot-form.git"
},
"license": "MIT",
"scripts": {
"dev": "webpack-dev-server --hot --open --open-page \"/dev\"",
"analyze": "cross-env ANALYZE=1 webpack -p",
"build": "run-p build:es5 build:es6",
"build:es6": "cross-env BABEL_ENV=es6 babel ./src --out-dir ./dist-es6",
"build:es5": "cross-env BABEL_ENV=es5 babel ./src --out-dir ./dist-es5",
"prepublishOnly": "npm run build"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-minify-webpack-plugin": "^0.2.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.10",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"cross-env": "^5.1.1",
"npm-run-all": "^4.1.2",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"webpack": "^3.8.1",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-dev-server": "^2.9.4"
},
"dependencies": {
"isomorphic-fetch": "^2.2.1"
}
}
79 changes: 79 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react'

export default class extends React.Component {
constructor(props){
super(props)
this.state = { loading: false }
this.hideLoader = this.hideLoader.bind(this)
this.showLoader = this.showLoader.bind(this)
this.startTimeout = this.startTimeout.bind(this)
}
componentWillReceiveProps() {
this.startTimeout()
}
componentDidMount() {
if (this.img.complete) {
this.hideLoader()
}
else {
this.startTimeout()
}
}
startTimeout() {
clearTimeout(this.timeout)
this.timeout = setTimeout(this.showLoader, 100)
}
showLoader() {
if (!this.img.complete) {
this.setState({ loading: true })
}
}
hideLoader() {
clearTimeout(this.timeout)
this.setState({ loading: false })
}
render(){
const TagName = this.props.tagName || 'img'
return (
<div style={{
maxWidth: this.props.width,
maxHeight: this.props.height,
margin: this.props.center ? 'auto' : ''
}}>
<div style={{
position: 'relative',
paddingBottom: `${(this.props.height / this.props.width) * 100}%`
}}>
<TagName
type={this.props.type}
srcSet={this.props.srcSet}
sizes={this.props.sizes}
src={this.props.src}
ref={img => this.img = img}
onLoad={this.hideLoader}
onError={this.hideLoader}
alt={this.props.alt}
style={{
position: 'absolute',
width: '100%',
maxWidth: '100%',
top: 0,
left: 0,
display: this.state.loading ? 'none' : 'block'
}}
/>
{this.state.loading && this.props.loading &&
<div style={{
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)'
}}>
{this.props.loading}
</div>
}
</div>
</div>
)
}
}
39 changes: 39 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const path = require('path')
const webpack = require('webpack')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')

const plugins = []
if (process.env.ANALYZE) {
plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'server',
openAnalyzer: true
}))
}
else{
plugins.push(new webpack.HotModuleReplacementPlugin())
}

module.exports = {
devtool: 'eval',
entry: [
'./dev/dev.js'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js',
publicPath: '/dev/'
},
plugins: plugins,
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [{
test: /\.js?$/,
use: [{
loader: 'babel-loader'
}],
include: path.join(__dirname, '/')
}]
}
}
Loading

0 comments on commit f494e67

Please sign in to comment.