flash-notifications 0.0.8 → 0.0.10

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.
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "main": "index.js",
3
3
  "name": "flash-notifications",
4
- "version": "0.0.8",
4
+ "version": "0.0.10",
5
5
  "private": false,
6
6
  "dependencies": {
7
7
  "diggerize": "^1.0.5",
8
- "prop-types-exact": "^1.2.0"
8
+ "prop-types-exact": "^1.2.4",
9
+ "set-state-compare": "^1.0.45"
9
10
  },
10
11
  "devDependenciesOnlyForLocalDevelopment": {
11
12
  "@testing-library/jest-dom": "^5.11.4",
@@ -1,23 +1,50 @@
1
- import {memo, useCallback} from "react"
1
+ import {memo} from "react"
2
2
  import {digg} from "diggerize"
3
3
  import Notification from "./notification"
4
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
4
5
  import useEventListener from "@kaspernj/api-maker/src/use-event-listener"
5
- import useShape from "set-state-compare/src/use-shape"
6
6
  import {View} from "react-native"
7
7
 
8
- const FlashNotificationsContainer = (props) => {
9
- const s = useShape(props)
8
+ export default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {
9
+ setup() {
10
+ this.useStates({
11
+ count: 0,
12
+ notifications: []
13
+ })
14
+
15
+ useEventListener(window, "pushNotification", this.onPushNotification)
16
+ }
10
17
 
11
- s.useStates({
12
- count: 0,
13
- notifications: []
14
- })
18
+ render() {
19
+ return (
20
+ <View
21
+ dataSet={{class: "flash-notifications-container"}}
22
+ style={{
23
+ position: "fixed",
24
+ zIndex: 99999,
25
+ top: 20,
26
+ right: 20
27
+ }}
28
+ >
29
+ {this.state.notifications.map((notification) =>
30
+ <Notification
31
+ key={`notification-${notification.count}`}
32
+ message={notification.message}
33
+ notification={notification}
34
+ onRemovedClicked={this.onRemovedClicked}
35
+ title={notification.title}
36
+ type={notification.type}
37
+ />
38
+ )}
39
+ </View>
40
+ )
41
+ }
15
42
 
16
- const onPushNotification = useCallback((event) => {
43
+ onPushNotification = (event) => {
17
44
  const detail = digg(event, "detail")
18
- const count = s.s.count + 1
45
+ const count = this.state.count + 1
19
46
 
20
- setTimeout(() => removeNotification(count), 4000)
47
+ setTimeout(() => this.removeNotification(count), 4000)
21
48
 
22
49
  const notification = {
23
50
  count,
@@ -26,43 +53,14 @@ const FlashNotificationsContainer = (props) => {
26
53
  type: digg(detail, "type")
27
54
  }
28
55
 
29
- s.set({count, notifications: s.s.notifications.concat([notification])})
30
- }, [])
56
+ this.setState({count, notifications: this.state.notifications.concat([notification])})
57
+ }
31
58
 
32
- const onRemovedClicked = useCallback((e, notification) => {
33
- e.preventDefault()
34
- removeNotification(digg(notification, "count"))
35
- }, [])
59
+ onRemovedClicked = (notification) => this.removeNotification(digg(notification, "count"))
36
60
 
37
- const removeNotification = useCallback((count) => {
38
- s.set({
39
- notifications: s.s.notifications.filter((notification) => notification.count != count)
61
+ removeNotification = (count) => {
62
+ this.setState({
63
+ notifications: this.state.notifications.filter((notification) => notification.count != count)
40
64
  })
41
- }, [])
42
-
43
- useEventListener(window, "pushNotification", onPushNotification)
44
-
45
- return (
46
- <View
47
- dataSet={{class: "flash-notifications-container"}}
48
- style={{
49
- position: "fixed",
50
- zIndex: 99999,
51
- top: 20,
52
- right: 20
53
- }}
54
- >
55
- {s.s.notifications.map((notification) =>
56
- <Notification
57
- key={`notification-${notification.count}`}
58
- message={notification.message}
59
- onRemovedClicked={(e) => onRemovedClicked(e, notification)}
60
- title={notification.title}
61
- type={notification.type}
62
- />
63
- )}
64
- </View>
65
- )
66
- }
67
-
68
- export default memo(FlashNotificationsContainer)
65
+ }
66
+ }))
@@ -1,59 +1,66 @@
1
1
  import {Pressable, Text, View} from "react-native"
2
2
  import {memo} from "react"
3
+ import PropTypes from "prop-types"
3
4
  import PropTypesExact from "prop-types-exact"
5
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
4
6
 
5
- const NotificationsNotification = (props) => {
6
- const {className, message, onRemovedClicked, title, type} = props
7
+ export default memo(shapeComponent(class NotificationsNotification extends ShapeComponent {
8
+ static propTypes = PropTypesExact({
9
+ className: PropTypes.string,
10
+ message: PropTypes.string.isRequired,
11
+ notification: PropTypes.object.isRequired,
12
+ onRemovedClicked: PropTypes.func.isRequired,
13
+ title: PropTypes.string.isRequired,
14
+ type: PropTypes.string.isRequired
15
+ })
7
16
 
8
- const style = {
9
- width: 300,
10
- maxWidth: "100%",
11
- marginBottom: 15,
12
- padding: 15,
13
- borderRadius: 11,
14
- cursor: "pointer"
15
- }
17
+ render() {
18
+ const {className, message, title, type} = this.props
16
19
 
17
- if (type == "error") {
18
- style.border = "1px solid rgba(161 34 32 / 95%)"
19
- style.background = "rgba(161 34 32 / 87%)"
20
- }
20
+ const style = {
21
+ width: 300,
22
+ maxWidth: "100%",
23
+ marginBottom: 15,
24
+ padding: 15,
25
+ borderRadius: 11,
26
+ cursor: "pointer"
27
+ }
21
28
 
22
- if (type == "success") {
23
- style.border = "1px solid rgba(0 0 0 / 95%)"
24
- style.background = "rgba(0 0 0 / 87%)"
25
- }
29
+ if (type == "error") {
30
+ style.border = "1px solid rgba(161 34 32 / 95%)"
31
+ style.background = "rgba(161 34 32 / 87%)"
32
+ }
26
33
 
34
+ if (type == "success") {
35
+ style.border = "1px solid rgba(0 0 0 / 95%)"
36
+ style.background = "rgba(0 0 0 / 87%)"
37
+ }
27
38
 
28
- if (type == "alert") {
29
- style.border = "1px solid rgba(204 51 0 / 95%)"
30
- style.background = "rgba(204 51 0 / 87%)"
31
- }
32
39
 
33
- return (
34
- <Pressable dataSet={{class: classNames("flash-notifications-notification", className), type}} onPress={onRemovedClicked}>
35
- <View style={style}>
36
- <View dataSet={{class: "notification-title"}} style={{marginBottom: 5}}>
37
- <Text style={{color: "#fff", fontWeight: "bold"}}>
38
- {title}
39
- </Text>
40
- </View>
41
- <View dataSet={{class: "notification-message"}}>
42
- <Text style={{color: "#fff"}}>
43
- {message}
44
- </Text>
40
+ if (type == "alert") {
41
+ style.border = "1px solid rgba(204 51 0 / 95%)"
42
+ style.background = "rgba(204 51 0 / 87%)"
43
+ }
44
+
45
+ return (
46
+ <Pressable dataSet={{class: classNames("flash-notifications-notification", className), type}} onPress={this.onRemovedClicked}>
47
+ <View style={style}>
48
+ <View dataSet={{class: "notification-title"}} style={{marginBottom: 5}}>
49
+ <Text style={{color: "#fff", fontWeight: "bold"}}>
50
+ {title}
51
+ </Text>
52
+ </View>
53
+ <View dataSet={{class: "notification-message"}}>
54
+ <Text style={{color: "#fff"}}>
55
+ {message}
56
+ </Text>
57
+ </View>
45
58
  </View>
46
- </View>
47
- </Pressable>
48
- )
49
- }
50
-
51
- NotificationsNotification.propTypes = PropTypesExact({
52
- className: PropTypes.string,
53
- message: PropTypes.string.isRequired,
54
- onRemovedClicked: PropTypes.func.isRequired,
55
- title: PropTypes.string.isRequired,
56
- type: PropTypes.string.isRequired
57
- })
58
-
59
- export default memo(NotificationsNotification)
59
+ </Pressable>
60
+ )
61
+ }
62
+
63
+ onRemovedClicked = () => {
64
+ this.p.onRemovedClicked(this.p.notification)
65
+ }
66
+ }))