Skip to content

Commit 422b252

Browse files
committed
eslint
1 parent d304beb commit 422b252

File tree

7 files changed

+701
-55
lines changed

7 files changed

+701
-55
lines changed

.eslintrc.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es6": true
5+
},
6+
"extends": ["airbnb"],
7+
"globals": {
8+
"Atomics": "readonly",
9+
"SharedArrayBuffer": "readonly"
10+
},
11+
"parserOptions": {
12+
"ecmaFeatures": {
13+
"jsx": true
14+
},
15+
"ecmaVersion": 2018,
16+
"sourceType": "module"
17+
},
18+
"plugins": ["react"],
19+
"rules": {}
20+
}

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true
6+
}

package.json

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
"name": "react-cam",
33
"version": "0.1.4",
44
"dependencies": {
5-
"babel-cli": "^6.26.0"
5+
"babel-cli": "^6.26.0",
6+
"prop-types": "^15.6.2",
7+
"react": "^16.4.1",
8+
"react-dom": "^16.4.1"
69
},
710
"devDependencies": {
811
"enzyme": "3.3.0",
912
"enzyme-adapter-react-16": "^1.1.1",
13+
"eslint": "^5.16.0",
14+
"eslint-config-airbnb": "^17.1.1",
15+
"eslint-plugin-import": "^2.18.0",
16+
"eslint-plugin-jsx-a11y": "^6.2.3",
17+
"eslint-plugin-react": "^7.14.2",
1018
"jest": "20.0.4",
11-
"react": "^16.4.1",
12-
"react-dom": "^16.4.1",
13-
"react-scripts": "1.1.4",
14-
"prop-types": "^15.6.2"
19+
"prettier": "^1.18.2",
20+
"react-scripts": "1.1.4"
1521
},
1622
"scripts": {
1723
"start": "react-scripts start",

src/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import { Camera } from './lib';
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import { Camera } from "./lib";
44

55
const App = () => (
66
<div style={{ width: 640, margin: "15px auto" }}>
77
<h1>Hello React</h1>
88
<Camera
99
showFocus={true}
1010
front={false}
11-
capture={()=>{}}
11+
capture={() => {}}
1212
width={1920}
1313
height={1440}
14-
btnColor="yellow" />
14+
btnColor="yellow"
15+
/>
1516
</div>
1617
);
17-
ReactDOM.render(<App />, document.getElementById("root"));
18+
ReactDOM.render(<App />, document.getElementById("root"));

src/lib/reactCam.js

+45-23
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Camera extends Component {
1919
this.state = {
2020
camWidth: null,
2121
camHeight: null,
22-
}
22+
};
2323
}
2424
success = stream => {
2525
const video = this.refs.cam;
@@ -30,18 +30,18 @@ class Camera extends Component {
3030
error = err => {
3131
console.log(err);
3232
};
33-
33+
3434
capture = () => {
3535
const canvas = this.refs.canvas;
3636
const video = this.refs.cam;
37-
const context = canvas.getContext("2d");
37+
const context = canvas.getContext('2d');
3838
context.drawImage(video, 0, 0);
39-
this.props.capture(canvas.toDataURL("image/jpeg"));
40-
}
39+
this.props.capture(canvas.toDataURL('image/jpeg'));
40+
};
4141

42-
componentDidMount(){
42+
componentDidMount() {
4343
const video = this.refs.cam;
44-
video.addEventListener("playing", () => {
44+
video.addEventListener('playing', () => {
4545
this.setState({
4646
camWidth: video.videoWidth,
4747
camHeight: video.videoHeight,
@@ -50,24 +50,46 @@ class Camera extends Component {
5050
}
5151

5252
render() {
53+
const defaultColor = '#2acef5';
5354
return (
5455
<div>
55-
<video
56-
id="video"
57-
autoPlay
58-
playsInline
59-
ref="cam"
60-
/>
61-
{ this.props.showFocus ?
62-
<div className="camera-focus" style={{ borderColor: this.props.btnColor?this.props.btnColor:'#2acef5' }} />: null
63-
}
56+
<video id="video" autoPlay playsInline ref="cam" />
57+
{this.props.showFocus ? (
58+
<div
59+
className="camera-focus"
60+
style={{
61+
borderColor: this.props.btnColor
62+
? this.props.btnColor
63+
: defaultColor,
64+
}}
65+
/>
66+
) : null}
6467
<div
65-
className="camera-btn-outer flexbox"
66-
style={{ justifyContent: 'center', alignItems: 'center', bottom: 10, background: this.props.btnColor?this.props.btnColor:'#2acef5' }}
67-
>
68-
<input type="button" onClick={this.capture} id="camera-btn" style={{ background: this.props.btnColor?this.props.btnColor:'#2acef5' }} />
68+
className="camera-btn-outer flexbox"
69+
style={{
70+
background: this.props.btnColor
71+
? this.props.btnColor
72+
: defaultColor,
73+
}}
74+
>
75+
<input
76+
type="button"
77+
onClick={this.capture}
78+
id="camera-btn"
79+
style={{
80+
background: this.props.btnColor
81+
? this.props.btnColor
82+
: defaultColor,
83+
}}
84+
/>
6985
</div>
70-
<canvas id="canvas" width={this.state.camWidth} height={this.state.camHeight} ref="canvas" style={{ display: 'none' }}></canvas>
86+
<canvas
87+
id="canvas"
88+
width={this.state.camWidth}
89+
height={this.state.camHeight}
90+
ref="canvas"
91+
style={{ display: 'none' }}
92+
/>
7193
</div>
7294
);
7395
}
@@ -80,6 +102,6 @@ Camera.propTypes = {
80102
capture: PropTypes.func.isRequired,
81103
showFocus: PropTypes.bool,
82104
btnColor: PropTypes.string,
83-
}
105+
};
84106

85-
export default Camera;
107+
export default Camera;

src/lib/style.css

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
.flexbox{
1+
.flexbox {
22
display: flex;
33
}
4-
.camera-focus{
4+
.camera-focus {
55
width: 80%;
66
height: 56%;
77
border: 1px solid #2acef5;
@@ -10,9 +10,9 @@
1010
margin-left: 50%;
1111
left: -40%;
1212
z-index: 99;
13-
box-shadow: 0px 0px 1px 1000px rgba(0,0,0,0.5)
13+
box-shadow: 0px 0px 1px 1000px rgba(0, 0, 0, 0.5);
1414
}
15-
#new-image{
15+
#new-image {
1616
position: fixed;
1717
bottom: 12px;
1818
left: 20px;
@@ -23,7 +23,7 @@
2323
background-position: center;
2424
background-repeat: no-repeat;
2525
}
26-
.camera-btn-outer{
26+
.camera-btn-outer {
2727
width: 60px;
2828
height: 60px;
2929
position: fixed;
@@ -33,19 +33,22 @@
3333
bottom: 10;
3434
background: #2acef5;
3535
z-index: 99;
36+
justify-content: center;
37+
align-items: center;
38+
bottom: 10px;
3639
}
37-
#camera-btn{
40+
#camera-btn {
3841
width: 52px;
3942
height: 52px;
4043
border: 2px solid #fff;
4144
border-radius: 26px !important;
4245
background: #2acef5;
4346
}
44-
#video{
47+
#video {
4548
position: fixed;
4649
top: 0px;
4750
left: 0px;
4851
width: 100%;
4952
height: auto;
5053
background: #000;
51-
}
54+
}

0 commit comments

Comments
 (0)