RNS Redux
A reimagining of React-Notification-System in Typescript, with an API that supports React Hooks.
Github: https://github.com/justindujardin/rns-redux/
Website: https://justindujardin.github.io/rns-redux/
Project Health
Check Type
Status
Master Build
Code Coverage
Dependency Updater
Up-to-date Dependencies
Up-to-date DevDependencies
Contributors
Usage
Install the library:
npm install
Add the NotifyProvider
near the top of your app. By default this will include a component NotifyPortal
as a child that will render the notifications. This can be disabled if the NotifyPortal is manually placed elsewhere.
<NotifyProvider>
<YourApp/>
</NotifyProvider>
Under the covers React's useReducer
API is the default store for notifications state, which is local to the provider component instance.
Show a notification:
export function MyHookComponent ( ) {
const { api } = useNotify()
api.showNotification({
level: 'info' ,
message: 'hi'
})
}
Credits
Typescript library starter by @alexjoverm
React Components based on React-Notification-System
Thanks to the wonderful people that contribute to this project (emoji key ):
This project follows the all-contributors specification. Contributions of any kind welcome!
Type aliases
NotifyCallback
Notify
Callback: ( notification: NotifyOpts ) => void
NotifyDismissable
NotifyDismissable: "button" | "both" | "none" | "click" | boolean
NotifyLevel
NotifyLevel: "success" | "warning" | "error" | "info"
NotifyPosition
NotifyPosition: "tl" | "tr" | "tc" | "bl" | "br" | "bc"
Variables
Const NotifyClearType
NotifyClearType: "@clearNotifications" = "@clearNotifications"
Const NotifyContext
Notify
Context: Context < null | INotifyContext > = React.createContext<INotifyContext | null>(null)
Const NotifyEditType
NotifyEditType: "@editNotification" = "@editNotification"
Const NotifyRemoveType
NotifyRemoveType: "@removeNotification" = "@removeNotification"
Const NotifyShowType
NotifyShowType: "@showNotification" = "@showNotification"
Const defaultShadowOpacity
defaultShadowOpacity: "0.9" = "0.9"
Const defaultWidth
defaultWidth: 320 = 320
Let uidCounter
uidCounter: number = 0
Functions
NotifyPortal
Parameters
Returns Element
NotifyProvider
Parameters
Returns Element
NotifyReducer
Parameters
Default value state: NotifyState = getInitialNotifyState()
_allowHTML
_allowHTML( input: any ) : { __html: any }
Parameters
Returns { __html: any }
exhaustiveCheck
exhaustiveCheck( _action: never ) : void
invariant
invariant( expression: any , message: string ) : void
Parameters
expression: any
message: string
Returns void
shallowCompare
shallowCompare( obj1: any , obj2: any ) : boolean
Parameters
Returns boolean
whichTransitionEvent
whichTransitionEvent( ) : string
Object literals
Const CONSTANTS
CONSTANTS: object
levels
levels: object
error
error: string = "error"
info
info: string = "info"
success
success: string = "success"
warning
warning: string = "warning"
notification
notification: object
action
action: undefined = undefined
autoDismiss
autoDismiss: number = 5
dismissible
dismissible: "both" = "both"
message
message: string = ""
position
position: "tr" = "tr"
positions
positions: object
testing
testing: object
itemTestId
itemTestId: string = "notify-item"
portalTestId
portalTestId: string = "notify-portal"
containerTestId
Parameters
Returns string
itemId
itemId( id: number ) : string
Parameters
Returns string
Const STYLES
STYLES: object
Action
Action: object
DefaultStyle
DefaultStyle: object
background
background: string = "#ffffff"
border
border: number = 0
borderRadius
borderRadius: string = "2px"
fontWeight
fontWeight: string = "bold"
margin
margin: string = "10px 0 0 0"
padding
padding: string = "6px 20px"
error
error: object
backgroundColor
backgroundColor: string = defaultColors.error.hex
color
color: string = "#ffffff"
info
info: object
backgroundColor
backgroundColor: string = defaultColors.info.hex
color
color: string = "#ffffff"
success
success: object
backgroundColor
backgroundColor: string = defaultColors.success.hex
color
color: string = "#ffffff"
warning
warning: object
backgroundColor
backgroundColor: string = defaultColors.warning.hex
color
color: string = "#ffffff"
ActionWrapper
ActionWrapper: object
DefaultStyle
DefaultStyle: object
margin
margin: number = 0
padding
padding: number = 0
Containers
Containers: object
DefaultStyle
DefaultStyle: object
MozBoxSizing
MozBoxSizing: string = "border-box"
WebkitBoxSizing
WebkitBoxSizing: string = "border-box"
boxSizing
boxSizing: string = "border-box"
fontFamily
fontFamily: string = "inherit"
height
height: string = "auto"
padding
padding: string = "0 10px 10px 10px"
position
position: string = "fixed"
width
width: number = defaultWidth
zIndex
zIndex: number = 9998
bc
bc: object
bottom
bottom: string = "0px"
left
left: string = "50%"
margin
margin: string = "0 auto"
marginLeft
marginLeft: number = -(defaultWidth / 2)
bl
bl: object
bottom
bottom: string = "0px"
left
left: string = "0px"
right
right: string = "auto"
br
br: object
bottom
bottom: string = "0px"
left
left: string = "auto"
right
right: string = "0px"
tc
tc: object
bottom
bottom: string = "auto"
left
left: string = "50%"
margin
margin: string = "0 auto"
marginLeft
marginLeft: number = -(defaultWidth / 2)
tl
tl: object
bottom
bottom: string = "auto"
left
left: string = "0px"
right
right: string = "auto"
tr
tr: object
bottom
bottom: string = "auto"
left
left: string = "auto"
right
right: string = "0px"
Dismiss
Dismiss: object
DefaultStyle
DefaultStyle: object
backgroundColor
backgroundColor: string = "#dededf"
borderRadius
borderRadius: string = "50%"
color
color: string = "#ffffff"
cursor
cursor: string = "pointer"
fontFamily
fontFamily: string = "Arial"
fontSize
fontSize: string = "17px"
fontWeight
fontWeight: string = "bold"
height
height: string = "14px"
lineHeight
lineHeight: string = "15px"
position
position: string = "absolute"
right
right: string = "5px"
textAlign
textAlign: string = "center"
width
width: string = "14px"
error
error: object
backgroundColor
backgroundColor: string = "#e4bebe"
color
color: string = "#f4e9e9"
info
info: object
backgroundColor
backgroundColor: string = "#a4becb"
color
color: string = "#e8f0f4"
success
success: object
backgroundColor
backgroundColor: string = "#b0ca92"
color
color: string = "#f0f5ea"
warning
warning: object
backgroundColor
backgroundColor: string = "#e1cfac"
color
color: string = "#f9f6f0"
MessageWrapper
MessageWrapper: object
DefaultStyle
DefaultStyle: object
margin
margin: number = 0
padding
padding: number = 0
NotificationItem
NotificationItem: object
DefaultStyle
DefaultStyle: object
MozBoxSizing
MozBoxSizing: string = "border-box"
WebkitBoxSizing
WebkitBoxSizing: string = "border-box"
WebkitTransform
WebkitTransform: string = "translate3d(0, 0, 0)"
borderRadius
borderRadius: string = "2px"
boxSizing
boxSizing: string = "border-box"
cursor
cursor: string = "pointer"
display
display: string = "block"
fontSize
fontSize: string = "13px"
margin
margin: string = "10px 0 0"
opacity
opacity: number = 0
padding
padding: string = "10px"
position
position: string = "relative"
transform
transform: string = "translate3d(0, 0, 0)"
transition
transition: string = "0.3s ease-in-out"
width
width: string = "100%"
willChange
willChange: string = "transform, opacity"
isHidden
isHidden: object
opacity
opacity: number = 0
isVisible
isVisible: object
opacity
opacity: number = 1
error
error: object
MozBoxShadow
MozBoxShadow: string = '0 0 1px rgba(' + defaultColors.error.rgb + ',' + defaultShadowOpacity + ')'
WebkitBoxShadow
WebkitBoxShadow: string = '0 0 1px rgba(' + defaultColors.error.rgb + ',' + defaultShadowOpacity + ')'
backgroundColor
backgroundColor: string = "#f4e9e9"
borderTop
borderTop: string = '2px solid ' + defaultColors.error.hex
boxShadow
boxShadow: string = '0 0 1px rgba(' + defaultColors.error.rgb + ',' + defaultShadowOpacity + ')'
color
color: string = "#412f2f"
info
info: object
MozBoxShadow
MozBoxShadow: string = '0 0 1px rgba(' + defaultColors.info.rgb + ',' + defaultShadowOpacity + ')'
WebkitBoxShadow
WebkitBoxShadow: string = '0 0 1px rgba(' + defaultColors.info.rgb + ',' + defaultShadowOpacity + ')'
backgroundColor
backgroundColor: string = "#e8f0f4"
borderTop
borderTop: string = '2px solid ' + defaultColors.info.hex
boxShadow
boxShadow: string = '0 0 1px rgba(' + defaultColors.info.rgb + ',' + defaultShadowOpacity + ')'
color
color: string = "#41555d"
success
success: object
MozBoxShadow
MozBoxShadow: string = '0 0 1px rgba(' + defaultColors.success.rgb + ',' + defaultShadowOpacity + ')'
WebkitBoxShadow
WebkitBoxShadow: string = '0 0 1px rgba(' + defaultColors.success.rgb + ',' + defaultShadowOpacity + ')'
backgroundColor
backgroundColor: string = "#f0f5ea"
borderTop
borderTop: string = '2px solid ' + defaultColors.success.hex
boxShadow
boxShadow: string = '0 0 1px rgba(' + defaultColors.success.rgb + ',' + defaultShadowOpacity + ')'
color
color: string = "#4b583a"
warning
warning: object
MozBoxShadow
MozBoxShadow: string = '0 0 1px rgba(' + defaultColors.warning.rgb + ',' + defaultShadowOpacity + ')'
WebkitBoxShadow
WebkitBoxShadow: string = '0 0 1px rgba(' + defaultColors.warning.rgb + ',' + defaultShadowOpacity + ')'
backgroundColor
backgroundColor: string = "#f9f6f0"
borderTop
borderTop: string = '2px solid ' + defaultColors.warning.hex
boxShadow
boxShadow: string = '0 0 1px rgba(' + defaultColors.warning.rgb + ',' + defaultShadowOpacity + ')'
color
color: string = "#5a5343"
Title
Title: object
DefaultStyle
DefaultStyle: object
fontSize
fontSize: string = "14px"
fontWeight
fontWeight: string = "bold"
margin
margin: string = "0 0 5px 0"
padding
padding: number = 0
error
error: object
color
color: string = defaultColors.error.hex
info
info: object
color
color: string = defaultColors.info.hex
success
success: object
color
color: string = defaultColors.success.hex
warning
warning: object
color
color: string = defaultColors.warning.hex
Const defaultColors
defaultColors: object
error
error: object
hex
hex: string = "#ec3d3d"
rgb
rgb: string = "236, 61, 61"
info
info: object
hex
hex: string = "#369cc7"
rgb
rgb: string = "54, 156, 199"
success
success: object
hex
hex: string = "#5ea400"
rgb
rgb: string = "94, 164, 0"
warning
warning: object
hex
hex: string = "#ebad1a"
rgb
rgb: string = "235, 173, 23"
Legend
Module
Object literal
Variable
Function
Function with type parameter
Index signature
Type alias
Type alias with type parameter
Enumeration
Enumeration member
Property
Method
Interface
Interface with type parameter
Constructor
Property
Method
Index signature
Class
Class with type parameter
Constructor
Property
Method
Accessor
Index signature
Inherited constructor
Inherited property
Inherited method
Inherited accessor
Protected property
Protected method
Protected accessor
Private property
Private method
Private accessor
Static property
Static method
Tagged union types (note the convenience functions that set levels are not here because they share an action type with IShowNotification)