Skip to content

Commit

Permalink
Merge pull request #64 from nkbt/ES6-Classes
Browse files Browse the repository at this point in the history
ES6 Classes
  • Loading branch information
nkbt authored Apr 26, 2017
2 parents 7fc5a5a + 54efcf4 commit 5ef9e10
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
12 changes: 10 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
"react"
],
"plugins": [
"transform-object-rest-spread"
]
"transform-object-rest-spread",
"transform-class-properties"
],
"env": {
"production": {
"plugins": [
["transform-react-remove-prop-types", {"removeImport": true}]
]
}
}
}
13 changes: 12 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{
"extends": "./node_modules/react-component-template/.eslintrc"
"extends": "./node_modules/react-component-template/.eslintrc",
"plugins": [
"babel"
],
"rules": {
"babel/new-cap": 2,
"babel/object-curly-spacing": 2,
"babel/no-invalid-this": 2,
"babel/semi": 2,
"no-invalid-this": 0,
"react/jsx-sort-props": 0
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
},
"homepage": "https://github.com/nkbt/react-copy-to-clipboard",
"peerDependencies": {
"react": "^0.14 || ^15"
"react": "^15.3.0"
},
"dependencies": {
"copy-to-clipboard": "^3",
"create-react-class": "^15.5.2",
"prop-types": "^15.5.8"
},
"devDependencies": {
"react-component-template": "0.1.9"
"eslint-plugin-babel": "4.1.1",
"react-component-template": "0.1.10"
}
}
15 changes: 6 additions & 9 deletions src/Component.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import React from 'react';
import createReactClass from 'create-react-class';
import PropTypes from 'prop-types';
import copy from 'copy-to-clipboard';


export const CopyToClipboard = createReactClass({
propTypes: {
export class CopyToClipboard extends React.PureComponent {
static propTypes = {
text: PropTypes.string.isRequired,
children: PropTypes.element.isRequired,
onCopy: PropTypes.func,
options: PropTypes.shape({
debug: PropTypes.bool,
message: PropTypes.string
})
},
};


onClick(event) {
onClick = event => {
const {
text,
onCopy,
Expand All @@ -36,8 +34,7 @@ export const CopyToClipboard = createReactClass({
if (elem && elem.props && typeof elem.props.onClick === 'function') {
elem.props.onClick(event);
}
},

};

render() {
const {
Expand All @@ -51,4 +48,4 @@ export const CopyToClipboard = createReactClass({

return React.cloneElement(elem, {...props, onClick: this.onClick});
}
});
}
27 changes: 10 additions & 17 deletions src/example/App/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
import React from 'react';
import createReactClass from 'create-react-class';
import CopyToClipboard from '../..';
import {name} from '../../../package.json';
import css from './App.css';


const App = createReactClass({
getInitialState() {
return {value: '', copied: false};
},
class App extends React.PureComponent {
state = {value: '', copied: false};


onChange({target: {value}}) {
onChange = ({target: {value}}) => {
this.setState({value, copied: false});
},


onCopy() {
this.setState({copied: true});
},

};

onClick({target: {innerHTML}}) {
onClick = ({target: {innerHTML}}) => {
console.log(`Clicked on "${innerHTML}"!`); // eslint-disable-line
},
};

onCopy = () => {
this.setState({copied: true});
};

render() {
return (
Expand Down Expand Up @@ -55,7 +48,7 @@ const App = createReactClass({
</div>
);
}
});
}


export default App;

0 comments on commit 5ef9e10

Please sign in to comment.