Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,6 +82,19 @@ Additional examples can be found [here](./index.html).

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

## 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';

<Button size="icon" account="example.chain">
```

## Start the project for development

You need to install [Node.js](https://nodejs.org/) firstly.
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "",
"main": "dist/index.js",
"browser": "dist/index.js",
"dependencies": {},
"files": [
"dist",
"src"
Expand All @@ -27,6 +26,10 @@
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12"
},
"optionalDependencies": {
"prop-types": "^15.7.2",
"react": "^17.0.0"
Comment on lines +30 to +31
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, these dependencies are inlined into the bundle, let's use externals to keep them extracted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope that will help with that, I will add it

  externals: {
    'prop-types': 'prop-types',
    'react': 'react'
  },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general idea is not to hope but to test it using a bundle analyzer and trying to use it in different environments

Copy link
Copy Markdown
Contributor Author

@shapkarin shapkarin Nov 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check it at Monday's morning

},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npm run build && serve",
Expand Down
22 changes: 22 additions & 0 deletions src/button-react.js
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While working on #38 I have found that the replacement of the DOM node breaks subsequent component updates. I have fixed it there by using a different API.

}

render() {
return React.createElement('div', { ref: this.button });
}
};

Button.propTypes = {
size: PropTypes.oneOf(['icon', 'small', 'medium', 'large']),
url: PropTypes.string,
account: PropTypes.string,
};
10 changes: 8 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is not working if imported using the script tag because React exposes itself there as React, it is fixed in #38

},
module: {
rules: [
{
Expand Down Expand Up @@ -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'}),
];