Skip to content

Commit b94c723

Browse files
author
Yury Shapkarin
committed
add react tip button
1 parent d28936e commit b94c723

4 files changed

Lines changed: 52 additions & 3 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ all, and write your own instead.
2222

2323
## Usage
2424

25+
- [Plain JavaScript](#.button-(%60superheroUtils.createButton%60))
26+
- [React.js](#.reactjs-component)
27+
2528
### Button (`superheroUtils.createButton`)
2629
This library exports a function that creates buttons. This function accepts arguments:
2730
- 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).
7982

8083
<img width="607" alt="Paywall" src="https://user-images.githubusercontent.com/9007851/95088220-58d0d000-072b-11eb-8cd6-57052d40765c.png">
8184

85+
## React.js component
86+
87+
### Usage with ES6
88+
89+
Props the same with [plain js vesrion](#Button-(`superheroUtils.createButton`)).
90+
91+
#### Example:
92+
```js
93+
import Button from '@aeternity/superhero-utils/button-react';
94+
95+
<Button size="icon" account="example.chain">
96+
```
97+
8298
## Start the project for development
8399

84100
You need to install [Node.js](https://nodejs.org/) firstly.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "",
55
"main": "dist/index.js",
66
"browser": "dist/index.js",
7-
"dependencies": {},
87
"files": [
98
"dist",
109
"src"
@@ -27,6 +26,10 @@
2726
"webpack": "^4.44.1",
2827
"webpack-cli": "^3.3.12"
2928
},
29+
"optionalDependencies": {
30+
"prop-types": "^15.7.2",
31+
"react": "^17.0.0"
32+
},
3033
"scripts": {
3134
"test": "echo \"Error: no test specified\" && exit 1",
3235
"start": "npm run build && serve",

src/button-react.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import createButton from './button';
4+
5+
export default class Button extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
this.button = React.createRef();
9+
this.componentDidMount = this.componentDidUpdate = () =>
10+
createButton(this.button.current, this.props);
11+
}
12+
13+
render() {
14+
return React.createElement('div', { ref: this.button });
15+
}
16+
};
17+
18+
Button.propTypes = {
19+
size: PropTypes.oneOf(['icon', 'small', 'medium', 'large']),
20+
url: PropTypes.string,
21+
account: PropTypes.string,
22+
};

webpack.config.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ const path = require('path');
22
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
33
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
44

5-
const genConfig = (filename, { inlineCss } = {}) => ({
5+
const genConfig = (outputFilename, { inlineCss, inputName = 'index.js' } = {}) => ({
66
output: {
77
path: path.resolve(__dirname, 'dist'),
8-
filename,
8+
filename: outputFilename,
99
library: 'superheroUtils',
1010
libraryTarget: 'umd'
1111
},
12+
entry: {
13+
entry: `./src/${inputName}`,
14+
},
1215
target: 'web',
16+
externals: {
17+
'prop-types': 'prop-types',
18+
'react': 'react'
19+
},
1320
module: {
1421
rules: [
1522
{
@@ -40,4 +47,5 @@ const genConfig = (filename, { inlineCss } = {}) => ({
4047
module.exports = [
4148
genConfig('index-without-styles.js'),
4249
genConfig('index.js', { inlineCss: true }),
50+
genConfig('button-react.js', { inputName: 'button-react.js'}),
4351
];

0 commit comments

Comments
 (0)