diff --git a/README.md b/README.md
index 32ec673a..3298d597 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,9 @@ all, and write your own instead.
## Usage
+- [Plain JavaScript](#button-superheroutilscreatebutton)
+- [React.js](#reactjs-component)
+
### Button (`superheroUtils.createButton`)
This library exports a function that creates buttons. This function accepts arguments:
- class name of nodes that should become buttons, or the DOM node itself
@@ -79,6 +82,19 @@ Additional examples can be found [here](./index.html).
+## React.js component
+
+### Usage with ES6
+
+Props the same with [plain js vesrion](##button-superheroutilscreatebutton).
+
+#### Example:
+```js
+import Button from '@aeternity/superhero-utils/button-react';
+
+
+```
+
## Start the project for development
You need to install [Node.js](https://nodejs.org/) firstly.
diff --git a/package.json b/package.json
index 70091366..afab24f1 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,6 @@
"description": "",
"main": "dist/index.js",
"browser": "dist/index.js",
- "dependencies": {},
"files": [
"dist",
"src"
@@ -27,6 +26,10 @@
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12"
},
+ "optionalDependencies": {
+ "prop-types": "^15.7.2",
+ "react": "^17.0.0"
+ },
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npm run build && serve",
diff --git a/src/button-react.js b/src/button-react.js
new file mode 100644
index 00000000..3cf04e0a
--- /dev/null
+++ b/src/button-react.js
@@ -0,0 +1,22 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import createButton from './button';
+
+export default class Button extends React.Component {
+ constructor(props) {
+ super(props);
+ this.button = React.createRef();
+ this.componentDidMount = this.componentDidUpdate = () =>
+ createButton(this.button.current, this.props);
+ }
+
+ render() {
+ return React.createElement('div', { ref: this.button });
+ }
+};
+
+Button.propTypes = {
+ size: PropTypes.oneOf(['icon', 'small', 'medium', 'large']),
+ url: PropTypes.string,
+ account: PropTypes.string,
+};
diff --git a/webpack.config.js b/webpack.config.js
index a8c7d5b2..13f8ce70 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -2,14 +2,19 @@ const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
-const genConfig = (filename, { inlineCss } = {}) => ({
+const genConfig = (outputFilename, { inlineCss, inputFilename = 'index.js' } = {}) => ({
output: {
path: path.resolve(__dirname, 'dist'),
- filename,
+ filename: outputFilename,
library: 'superheroUtils',
libraryTarget: 'umd'
},
+ entry: `./src/${inputFilename}`,
target: 'web',
+ externals: {
+ 'prop-types': 'prop-types',
+ 'react': 'react'
+ },
module: {
rules: [
{
@@ -40,4 +45,5 @@ const genConfig = (filename, { inlineCss } = {}) => ({
module.exports = [
genConfig('index-without-styles.js'),
genConfig('index.js', { inlineCss: true }),
+ genConfig('button-react.js', { inputFilename: 'button-react.js'}),
];