1.3.2 • Published 2 days ago

react-status-alert v1.3.2

Weekly downloads
89
License
MIT
Repository
github
Last release
2 days ago

React Status Alert

npm version Build Status codebeat badge codecov

Simple React Status Alert component with Typescript support (Demo)

Project inspired by jQuery-FlashingNotifications

Installation

To install run:

npm i react-status-alert

or

yarn add react-status-alert

Basic usage with build systems (webpack, parcel etc.):

import React from 'react'
import StatusAlert, { StatusAlertService } from 'react-status-alert'
import 'react-status-alert/dist/status-alert.css'

function ExampleApp() {
  const showSuccessAlert = (): void => {
    StatusAlertService.showSuccess('Default success alert!');
  }
  
  return (
    <div>
      <StatusAlert/>
        
      <button onClick={showSuccessAlert}>Show success alert</button>
    </div>
  )
}

More complex usage:

import React from 'react'
import StatusAlert, { StatusAlertService } from 'react-status-alert'
import 'react-status-alert/dist/status-alert.css'

function ExampleApp() {
  const [alertId, setAlertId] = useState<string>('')
  
  const showSuccessAlert = (): void => {
    const alertId = StatusAlertService.showSuccess('Default success alert!');
    setAlertId(alertId)
  }
  
  const removeAlert = (): void => {
    StatusAlertService.removeAlert(this.state.alertId);
  }
  
  return (
    <div>
      <StatusAlert/>
        
      <button onClick={showSuccessAlert}>Show success alert</button> 
      <button onClick={removeAlert}>Remove alert</button>
    </div>
  )
}

The same with class component:

import React from 'react'
import StatusAlert, { StatusAlertService } from 'react-status-alert'
import 'react-status-alert/dist/status-alert.css'

export class ExampleApp extends React.Component {
  constructor(props) {
    super(props);
    
    this.state = {
      alertId: ''
    };
    
    this.showSuccessAlert = this.showSuccessAlert.bind(this);
    this.removeAlert = this.removeAlert.bind(this);
  }
  
  showSuccessAlert() {
    const alertId = StatusAlertService.showSuccess('Default success alert!');
    this.setState({ alertId });
  }
  
  removeAlert() {
    StatusAlertService.removeAlert(this.state.alertId);
  }
  
  render() {
    return (
      <div>
        <StatusAlert/>
        
        <button onClick={this.showSuccessAlert}>Show success alert</button> 
        <button onClick={this.removeAlert}>Remove alert</button>
      </div>
    )
  }
}

StatusAlertService API

StatusAlertService.showAlert(message: JSX.Element | string, type: AlertType, options?: AlertOptions)

StatusAlertService.showSuccess(message: JSX.Element | string, options?: AlertOptions): string

StatusAlertService.showError(message: JSX.Element | string, options?: AlertOptions): string

StatusAlertService.showInfo(message: JSX.Element | string, options?: AlertOptions): string

StatusAlertService.showWarning(message: JSX.Element | string, options?: AlertOptions): string

StatusAlertService.removeAlert(alertId: string): void

StatusAlertService.removeAllAlerts(): void

AlertType

'success' | 'error' | 'info' | 'warning'

AlertOptions

All options are optional

NameTypeDefaultDescription
autoHidebooleantrueAuto hide alert after timeout
autoHideTimenumber3500Auto hide timeout in ms
withIconbooleantrueShow status icon
withCloseIconbooleantrueShow close icon
colorstringundefinedText color
backgroundColorstringundefinedBackground color
removeAllBeforeShowbooleanfalseRemove all alerts before showing new

Example

View demo or docs folder.

1.3.2

2 days ago

1.3.1

2 months ago

1.2.2

3 months ago

1.3.0

2 months ago

1.2.0

1 year ago

1.1.6

1 year ago

1.2.1

1 year ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.2

2 years ago

1.1.0

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago