Skip to content

Commit 0b2b50e

Browse files
author
Rares Mardare
committed
3.2.4 + fixes
1 parent d271cd5 commit 0b2b50e

File tree

18 files changed

+1468
-284
lines changed

18 files changed

+1468
-284
lines changed

package-lock.json

Lines changed: 1192 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "react-notifications-component",
3-
"version": "3.2.2",
3+
"version": "3.2.4",
44
"homepage": "http://teodosii.github.io/react-notifications-component",
55
"description": "React component for creating notifications on the fly",
66
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
78
"scripts": {
89
"build": "npm run build:library:dev && npm run build:library:prod",
910
"build:library:dev": "webpack --config webpack.dev.js",
@@ -75,6 +76,7 @@
7576
"html-webpack-plugin": "^5.5.0",
7677
"mini-css-extract-plugin": "^2.5.2",
7778
"node-sass": "^7.0.1",
79+
"npm-dts-webpack-plugin": "^1.3.10",
7880
"object-assign": "^4.1.1",
7981
"optimize-css-assets-webpack-plugin": "^6.0.1",
8082
"prettier": "^2.5.1",

samples/js/components/Content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { store } from 'src'
2+
import { Store } from 'src'
33
import ContainerExample from 'components/examples/ContainerExample'
44
import TypeExample from 'components/examples/TypeExample'
55
import InsertExample from 'components/examples/InsertExample'
@@ -11,7 +11,7 @@ function ExampleHeading() {
1111
<div className="row">
1212
<div className="col-lg-6 offset-lg-3 column col-md-10 offset-md-1 col-sm-12 heading">
1313
<h2 className="text-center">Examples</h2>
14-
<button type="button" className="btn btn-outline-danger" onClick={() => store.removeAllNotifications()}>
14+
<button type="button" className="btn btn-outline-danger" onClick={() => Store.removeAllNotifications()}>
1515
Remove All Notifications
1616
</button>
1717
<div className="alert alert-warning alert-small">

samples/js/components/examples/AnimationExample.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react'
22
import notification from 'samples/js/helpers/notification'
33
import { getContainer, getMessage, getType } from 'samples/js/helpers/randomize'
4-
import { store } from 'src'
5-
import { iNotification } from 'src/components/Notification'
4+
import { Store } from 'src'
5+
import { iNotification } from 'src/types'
66

77
function AnimationInExample() {
88
return (
@@ -136,7 +136,7 @@ function add(isEntranceAnimation: boolean, htmlClasses: string[]) {
136136
const object: iNotification = {}
137137

138138
if (isEntranceAnimation) {
139-
return store.addNotification(
139+
return Store.addNotification(
140140
Object.assign(object, notification, {
141141
animationIn: htmlClasses,
142142
container: getContainer(),
@@ -146,7 +146,7 @@ function add(isEntranceAnimation: boolean, htmlClasses: string[]) {
146146
)
147147
}
148148

149-
return store.addNotification(
149+
return Store.addNotification(
150150
Object.assign(object, notification, {
151151
slidingExit: { delay: 300 },
152152
animationOut: htmlClasses,

samples/js/components/examples/ContainerExample.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react'
22
import notification from 'samples/js/helpers/notification'
33
import { getMessage, getTitle, getType } from 'samples/js/helpers/randomize'
4-
import { store } from 'src'
5-
import { iNotification } from 'src/components/Notification'
4+
import { Store } from 'src'
5+
import { iNotification } from 'src/types'
66

77
export default function ContainerExample() {
88
return (
@@ -88,7 +88,7 @@ function add(container: string): string {
8888
const type = getType()
8989
const object: iNotification = {}
9090

91-
return store.addNotification(
91+
return Store.addNotification(
9292
Object.assign(object, notification, {
9393
title: getTitle(type),
9494
message: getMessage(type),

samples/js/components/examples/CustomContentExample.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { useEffect, useState } from 'react'
22
import notification from 'samples/js/helpers/notification'
33
import reactImage from 'samples/images/react.png'
44
import { getContainer } from 'samples/js/helpers/randomize'
5-
import { store } from 'src'
6-
import { iNotification } from 'src/components/Notification'
5+
import { Store } from 'src'
6+
import { iNotification } from 'src/types'
77

88
export default function CustomContentExample() {
99
const [cachedImage] = useState(new Image())
@@ -53,7 +53,7 @@ export default function CustomContentExample() {
5353
function add(cachedImage: HTMLImageElement): void {
5454
const object: iNotification = {}
5555

56-
store.addNotification(
56+
Store.addNotification(
5757
Object.assign(object, notification, {
5858
width: 325,
5959
container: getContainer(),
@@ -78,7 +78,7 @@ function addCustomIcon(type: string, iconClassName: string): void {
7878

7979
const object: iNotification = {}
8080

81-
store.addNotification(
81+
Store.addNotification(
8282
Object.assign(object, notification, {
8383
width: 275,
8484
container: getContainer(),

samples/js/components/examples/InsertExample.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react'
2-
import { store } from 'src'
2+
import { Store } from 'src'
33
import notification from 'samples/js/helpers/notification'
44
import { getType, getMessage, getTitle } from 'samples/js/helpers/randomize'
5-
import { iNotification } from 'src/components/Notification'
5+
import { iNotification } from 'src/types'
66

77
export default function InsertExample() {
88
return (
@@ -30,7 +30,7 @@ export default function InsertExample() {
3030
function add(insert: string) {
3131
const type = getType()
3232
const object: iNotification = {}
33-
return store.addNotification(
33+
return Store.addNotification(
3434
Object.assign(object, notification, {
3535
type,
3636
insert,

samples/js/components/examples/TypeExample.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react'
2-
import { store } from 'src'
2+
import { Store } from 'src'
33
import notification from 'samples/js/helpers/notification'
44
import { getContainer, getMessage, getTitle } from 'samples/js/helpers/randomize'
5-
import { iNotification } from 'src/components/Notification'
5+
import { iNotification } from 'src/types'
66

77
export default function TypeExample() {
88
return (
@@ -54,7 +54,7 @@ export default function TypeExample() {
5454

5555
function add(type: string) {
5656
const object: iNotification = {}
57-
return store.addNotification(
57+
return Store.addNotification(
5858
Object.assign(object, notification, {
5959
type,
6060
title: getTitle(type),

src/components/Container.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
import React from 'react'
2+
import { iContainerProps, iContainerState, iNotification } from 'src'
23
import ReactNotification from 'src/components/Notification'
34
import 'src/scss/notification.scss'
45
import store from 'src/store'
56
import { DEFAULT_CONTAINER_VALUES as DCV } from 'src/utils/constants'
6-
import type { iNotification, iNotificationCustomType } from 'src/components/Notification'
77
import {
88
getNotificationsForEachContainer,
99
getNotificationsForMobileView,
1010
isNullOrUndefined
1111
} from 'src/utils/helpers'
1212

13-
interface iContainerProps {
14-
isMobile?: boolean
15-
breakpoint?: number
16-
types?: iNotificationCustomType[]
17-
defaultNotificationWidth?: number
18-
}
19-
20-
interface iContainerState {
21-
isMobile: boolean
22-
breakpoint: number
23-
notifications: iNotification[]
24-
windowWidth: number
25-
}
26-
2713
class Container extends React.Component<iContainerProps, iContainerState> {
2814
constructor(props: iContainerProps) {
2915
super(props)

src/components/Notification.tsx

Lines changed: 7 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { REMOVAL, INSERTION, NOTIFICATION_CONTAINER, NOTIFICATION_TYPE } from 'src/utils/constants'
2+
import { iNotificationProps, iNotificationState, iNotificationParentStyle, NOTIFICATION_REMOVAL_SOURCE } from 'src'
33
import {
44
getHtmlClassesForType,
55
getTransition,
@@ -8,92 +8,6 @@ import {
88
} from 'src/utils/helpers'
99
import Timer from 'src/utils/timer'
1010

11-
export type { iNotification, iTransition, iTouchTransition, iDismiss, iNotificationCustomType }
12-
13-
interface iNotification {
14-
id?: string
15-
onRemoval?: (id: string, removalFlag: string) => void
16-
title?: NotificationTitleMessage
17-
message?: NotificationTitleMessage
18-
content?: NotificationContent
19-
type?: NOTIFICATION_TYPE
20-
container?: NOTIFICATION_CONTAINER
21-
insert?: INSERTION
22-
dismiss?: iDismiss
23-
animationIn?: string[]
24-
animationOut?: string[]
25-
slidingEnter?: iTransition
26-
slidingExit?: iTransition
27-
touchRevert?: iTransition
28-
touchSlidingExit?: {
29-
fade: iTransition
30-
swipe: iTransition
31-
}
32-
userDefinedTypes?: iNotificationCustomType[]
33-
width?: number
34-
hasBeenRemoved?: boolean
35-
}
36-
37-
export type NotificationTitleMessage = string | React.ReactNode | React.FunctionComponent
38-
export type NotificationContent =
39-
| React.ComponentClass<any, any>
40-
| React.FunctionComponent<any>
41-
| React.ReactElement
42-
43-
interface iTransition {
44-
duration: number
45-
timingFunction: string
46-
delay: number
47-
}
48-
49-
interface iTouchTransition {
50-
swipe: iTransition
51-
fade: iTransition
52-
}
53-
54-
interface iDismiss {
55-
duration: number
56-
onScreen: boolean
57-
pauseOnHover: boolean
58-
waitForAnimation: boolean
59-
click: boolean
60-
touch: boolean
61-
showIcon: boolean
62-
}
63-
64-
interface iNotificationCustomType {
65-
htmlClasses: string[]
66-
name: string
67-
}
68-
69-
class iNotificationProps {
70-
id: string
71-
notification: iNotification
72-
defaultNotificationWidth: number
73-
notificationsCount: number
74-
isMobile: boolean
75-
hasBeenRemoved: boolean
76-
toggleRemoval: (id: string, callback: () => void) => void
77-
}
78-
79-
interface iNotificationState {
80-
parentStyle?: iParentStyle
81-
htmlClassList?: string[]
82-
animationPlayState?: string
83-
touchEnabled?: boolean
84-
onTransitionEnd?: (event: React.TransitionEvent<HTMLDivElement>) => void
85-
onAnimationEnd?: (event: React.AnimationEvent<HTMLDivElement>) => void
86-
startX?: number
87-
currentX?: number
88-
}
89-
90-
interface iParentStyle {
91-
height?: string
92-
overflow?: string
93-
width?: string
94-
transition?: string
95-
}
96-
9711
class Notification extends React.Component<iNotificationProps, iNotificationState> {
9812
constructor(props: iNotificationProps) {
9913
super(props)
@@ -137,7 +51,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
13751

13852
const onTransitionEnd = () => {
13953
if (!duration || onScreen) return
140-
const callback = () => this.removeNotification(REMOVAL.TIMEOUT)
54+
const callback = () => this.removeNotification(NOTIFICATION_REMOVAL_SOURCE.TIMEOUT)
14155
this.timer = new Timer(callback, duration)
14256
}
14357

@@ -164,7 +78,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
16478

16579
componentDidUpdate(prevProps: iNotificationProps) {
16680
if (this.props.hasBeenRemoved && !prevProps.hasBeenRemoved) {
167-
this.removeNotification(REMOVAL.MANUAL)
81+
this.removeNotification(NOTIFICATION_REMOVAL_SOURCE.MANUAL)
16882
}
16983

17084
if (prevProps !== this.props) {
@@ -190,7 +104,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
190104

191105
const htmlClassList = [...notification.animationOut, ...getHtmlClassesForType(notification)]
192106
const onTransitionEnd = () => toggleRemoval(id, () => onRemoval(id, removalFlag))
193-
const parentStyle: iParentStyle = {
107+
const parentStyle: iNotificationParentStyle = {
194108
height: `0px`,
195109
overflow: 'hidden',
196110
transition: getTransition(notification.slidingExit, 'height')
@@ -226,7 +140,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
226140
notification: { dismiss }
227141
} = this.props
228142
if (dismiss.click || dismiss.showIcon) {
229-
this.removeNotification(REMOVAL.CLICK)
143+
this.removeNotification(NOTIFICATION_REMOVAL_SOURCE.CLICK)
230144
}
231145
}
232146

@@ -265,7 +179,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
265179
const t1 = getTransition(swipe, 'left')
266180
const t2 = getTransition(fade, 'opacity')
267181
const onTransitionEnd = () => {
268-
toggleRemoval(id, () => onRemoval(id, REMOVAL.TOUCH))
182+
toggleRemoval(id, () => onRemoval(id, NOTIFICATION_REMOVAL_SOURCE.TOUCH))
269183
}
270184

271185
return this.setState(({ parentStyle }) => ({
@@ -349,7 +263,7 @@ class Notification extends React.Component<iNotificationProps, iNotificationStat
349263
animationPlayState
350264
}
351265

352-
const onAnimationEnd = () => this.removeNotification(REMOVAL.TIMEOUT)
266+
const onAnimationEnd = () => this.removeNotification(NOTIFICATION_REMOVAL_SOURCE.TIMEOUT)
353267
return (
354268
<div className="rnc__notification-timer">
355269
<div

0 commit comments

Comments
 (0)