react-js-banner 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
2
+
3
+ /**
4
+ * @license React
5
+ * react-jsx-runtime.production.min.js
6
+ *
7
+ * Copyright (c) Facebook, Inc. and its affiliates.
8
+ *
9
+ * This source code is licensed under the MIT license found in the
10
+ * LICENSE file in the root directory of this source tree.
11
+ */
package/package.json CHANGED
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "name": "react-js-banner",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "description": "React JS Banner component customizable with auto hide option",
5
5
  "main": "build/index.js",
6
- "peerDependencies": {
7
- "react": "^16.8.0"
8
- },
6
+ "peerDependencies": {},
9
7
  "dependencies": {
10
-
8
+ "source-map-explorer": "^2.5.3"
11
9
  },
12
10
  "scripts": {
13
11
  "start": "webpack --watch",
@@ -27,8 +25,9 @@
27
25
  "eslint": "^6.8.0",
28
26
  "html-loader": "^2.1.2",
29
27
  "html-webpack-plugin": "^5.3.1",
30
- "react": "^16.14.0",
31
- "react-dom": "^16.14.0",
28
+ "prop-types": "^15.8.1",
29
+ "react": "^18.2.0",
30
+ "react-dom": "^18.2.0",
32
31
  "style-loader": "^3.3.4",
33
32
  "webpack": "^5.91.0",
34
33
  "webpack-cli": "^5.1.4"
package/src/banner.css CHANGED
@@ -1,3 +1,33 @@
1
+ @keyframes opacityOn {
2
+ 0% {
3
+ opacity: 0;
4
+ }
5
+ 25% {
6
+ opacity: 0;
7
+ }
8
+ 50% {
9
+ opacity: 1;
10
+ }
11
+ 85% {
12
+ opacity: 1;
13
+ }
14
+ 100% {
15
+ opacity: 0;
16
+ }
17
+ }
18
+
19
+ @keyframes noFadeOut {
20
+ 0% {
21
+ opacity: 0;
22
+ }
23
+ 50% {
24
+ opacity: 1;
25
+ }
26
+ 100% {
27
+ opacity: 1;
28
+ }
29
+ }
30
+
1
31
  .banner{
2
32
  background-color: orange;
3
33
  text-align: center;
@@ -9,6 +39,7 @@
9
39
  text-align: center;
10
40
  align-items: center;
11
41
  justify-content: center;
42
+ animation: opacityOn 5s normal forwards;
12
43
  }
13
44
 
14
45
  .banner-transition-appear {
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { Component } from "react";
2
-
2
+ import {useState} from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import "./banner.css";
5
5
 
@@ -7,22 +7,26 @@ import "./banner.css";
7
7
  * Banner component
8
8
  * @author [Jose Antonio Ciccio](https://github.com/jciccio)
9
9
  */
10
-
11
10
  class Banner extends Component {
12
11
  constructor(props) {
13
12
  super(props);
14
- this.state = {
15
- visibleTime: 0,
16
- show: undefined
13
+ this.state = {
14
+ showBanner: undefined
17
15
  };
16
+
17
+ }
18
+
19
+ componentDidMount() {
20
+ this.hideBanner();
18
21
  }
19
22
 
20
23
  static getDerivedStateFromProps(nextProps, prevState) {
21
24
  if (nextProps.visibleTime !== undefined && nextProps.visibleTime > 0){
22
25
  let newState = {
23
26
  bannerMessage: nextProps.bannerMessage,
24
- visibleTime: nextProps.visibleTime
27
+ showBanner: true
25
28
  };
29
+
26
30
  return newState;
27
31
  }
28
32
  return null;
@@ -60,18 +64,21 @@ class Banner extends Component {
60
64
  async hideBanner() {
61
65
  if(this.props.visibleTime !== undefined && this.props.visibleTime > 0)
62
66
  {
63
- await this.timeout(1000 + this.props.visibleTime);
64
- await this.setState({ show: false });
67
+ this.timeout(this.props.visibleTime);
65
68
  }
66
69
  }
67
70
 
68
71
  renderBanner() {
69
- let showBanner = this.props.showBanner !== undefined ? this.props.showBanner : true;
72
+
73
+ const showBanner = this.state.showBanner !== undefined ? this.state.showBanner : true;
74
+
75
+ const visibleTimeAnim = (this.props.visibleTime > 0) ? `opacityOn ${this.props.visibleTime/1000}s` : `noFadeOut 3s`;
76
+ const animation = {"animation": `${visibleTimeAnim} normal forwards`}
70
77
  if(showBanner){
71
- if (this.props.title && (this.state.show === undefined || this.state.show) ) {
72
- {this.hideBanner()}
78
+ if (this.props.title && (this.state.show === undefined || this.state.showBanner) ) {
79
+
73
80
  return (
74
- <div key="banner" className="banner" style={this.props.css}>
81
+ <div key="banner" className="banner" style={{...this.props.css, ...animation}}>
75
82
  {this.renderImage()}
76
83
  {this.renderTitle()}
77
84
  </div>
@@ -79,7 +86,7 @@ class Banner extends Component {
79
86
  }
80
87
  else if (this.props.children){
81
88
  return(
82
- <div key="banner" className="banner" style={this.props.css}>
89
+ <div key="banner" className="banner" style={{...this.props.css, ...animation}}>
83
90
  {this.props.children}
84
91
  </div>
85
92
  )
@@ -92,11 +99,15 @@ class Banner extends Component {
92
99
  }
93
100
 
94
101
  renderTitle(){
95
- return <div>{this.props.title}</div>
102
+ return <div key={`BannerId-${this.props.id}`}>{this.props.title}</div>
96
103
  }
97
104
 
98
105
  timeout(ms) {
99
- return new Promise(resolve => setTimeout(resolve, ms));
106
+ setTimeout(() => {
107
+ if(this.props.onHideCallback != null){
108
+ this.props.onHideCallback(this.props.id);
109
+ }
110
+ }, ms);
100
111
  }
101
112
 
102
113
  }
@@ -107,10 +118,16 @@ Banner.propTypes = {
107
118
  visibleTime: PropTypes.number,
108
119
  image: PropTypes.string,
109
120
  imageClass: PropTypes.string,
121
+ id: PropTypes.string.isRequired,
110
122
  transitionAppearTime: PropTypes.number,
111
123
  transitionTime: PropTypes.number,
112
124
  showBanner: PropTypes.bool,
113
- children: PropTypes.node
125
+ children: PropTypes.node,
126
+ onHideCallback: PropTypes.func
114
127
  };
115
128
 
129
+ Banner.defaultProps = {
130
+ onHideCallback: null,
131
+ }
132
+
116
133
  export default Banner;
package/webpack.config.js CHANGED
@@ -1,41 +1,27 @@
1
- const path = require('path');
1
+ var path = require("path");
2
2
 
3
3
  module.exports = {
4
- entry: './src/index.js',
5
- mode: 'development',
4
+ mode: "production",
5
+ entry: "./src/index.js",
6
6
  output: {
7
- path: path.resolve(__dirname, 'build'),
8
- filename: 'index.js',
9
- libraryTarget: 'commonjs2',
7
+ path: path.resolve("build"),
8
+ filename: "index.js",
9
+ libraryTarget: "commonjs2"
10
10
  },
11
11
  module: {
12
12
  rules: [
13
+ { test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" },
13
14
  {
14
- test: /\.js$/,
15
- include: path.resolve(__dirname, 'src'),
16
- exclude: /(node_modules|bower_components|build)/,
17
- use: {
18
- loader: 'babel-loader'
19
- }
20
- },
21
- {
22
- test:/\.html$/i,
23
- use: [
24
- {
25
- loader: 'html-loader'
26
- }
27
- ]
15
+ test: /\.css$/,
16
+ loader: "style-loader"
28
17
  },
29
18
  {
30
19
  test: /\.css$/,
31
- include: path.resolve(__dirname, 'src'),
32
- exclude: /(node_modules|bower_components|build)/,
33
- use:['style-loader','css-loader']
20
+ loader: "css-loader"
34
21
  }
35
22
  ]
36
23
  },
37
- resolve: {
38
- extensions: [".js",".jsx", '.json']
39
- },
40
- devtool: 'inline-source-map'
24
+ externals: {
25
+ react: "react"
26
+ }
41
27
  };