react-js-banner 0.6.1 → 0.7.0

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,25 @@
1
+ /******/ (() => { // webpackBootstrap
2
+ /******/ var __webpack_modules__ = ({
3
+
4
+ /***/ "./src/index.jsx":
5
+ /*!***********************!*\
6
+ !*** ./src/index.jsx ***!
7
+ \***********************/
8
+ /***/ (() => {
9
+
10
+ throw new Error("Module parse failed: Unexpected token (42:8)\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders\n| if (this.props.image && this.props.imageClass){\n| return(\n> <img \n| src={this.props.image} \n| className={this.props.imageClass}");
11
+
12
+ /***/ })
13
+
14
+ /******/ });
15
+ /************************************************************************/
16
+ /******/
17
+ /******/ // startup
18
+ /******/ // Load entry module and return exports
19
+ /******/ // This entry module doesn't tell about it's top-level declarations so it can't be inlined
20
+ /******/ var __webpack_exports__ = {};
21
+ /******/ __webpack_modules__["./src/index.jsx"]();
22
+ /******/ module.exports = __webpack_exports__;
23
+ /******/
24
+ /******/ })()
25
+ ;
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.0",
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
+
11
9
  },
12
10
  "scripts": {
13
11
  "start": "webpack --watch",
@@ -27,11 +25,12 @@
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
+ "react": "^18.2.0",
29
+ "react-dom": "^18.2.0",
32
30
  "style-loader": "^3.3.4",
33
31
  "webpack": "^5.91.0",
34
- "webpack-cli": "^5.1.4"
32
+ "webpack-cli": "^5.1.4",
33
+ "prop-types": "^15.8.1"
35
34
  },
36
35
  "repository": {
37
36
  "type": "git",
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;