Code Monkey home page Code Monkey logo

react-s-alert's Introduction

This lib is no longer maintained. It needs major adjustments and rewrites. I hope I'll find some time for it in the future. Sorry.

React sAlert component

sAlert is a React component which provides alerts or notifications with rich configuration possibilities. This is a rewritten version of Meteor/Blaze sAlert package which you can find here: s-alert.meteor.com.

Demo

The demo website and provided source code are the best learning resources.

Usage with React

Here is what you need to do to make it work. Of course you need to have React and ReactDOM installed in your project.

1. Install the package

npm install react-s-alert --save

2. Import component

With ES2015:

import Alert from 'react-s-alert';

With ES5:

var Alert = require('react-s-alert').default;

3. Import (or copy) CSS files

All you need to do is to import (or copy) a default CSS file and some or all CSS files with effects which you want to use. A default CSS file is mandatory. With Webpack you could do something like:

With ES2015:

// mandatory
import 'react-s-alert/dist/s-alert-default.css';

// optional - you can choose the effect you want
import 'react-s-alert/dist/s-alert-css-effects/slide.css';
import 'react-s-alert/dist/s-alert-css-effects/scale.css';
import 'react-s-alert/dist/s-alert-css-effects/bouncyflip.css';
import 'react-s-alert/dist/s-alert-css-effects/flip.css';
import 'react-s-alert/dist/s-alert-css-effects/genie.css';
import 'react-s-alert/dist/s-alert-css-effects/jelly.css';
import 'react-s-alert/dist/s-alert-css-effects/stackslide.css';

With ES5:

// mandatory
require('react-s-alert/dist/s-alert-default.css');

// optional - you can choose the effect you want
require('react-s-alert/dist/s-alert-css-effects/slide.css');
require('react-s-alert/dist/s-alert-css-effects/scale.css');
require('react-s-alert/dist/s-alert-css-effects/bouncyflip.css');
require('react-s-alert/dist/s-alert-css-effects/flip.css');
require('react-s-alert/dist/s-alert-css-effects/genie.css');
require('react-s-alert/dist/s-alert-css-effects/jelly.css');
require('react-s-alert/dist/s-alert-css-effects/stackslide.css');

CDN:

(you can change versions in URL if needed)

You can also copy the files and include it another way in your app. It depends on your workflow.

If you are using CSS Modules for now you need to import these files globally. (You can check the demo website Webpack config file).

4. Place sAlert component in your main app component

You need to place the main sAlert container. The best place for it is at the end of your main app component. For Example:

import React from 'react';
import {Router} from 'react-router';
import Alert from 'react-s-alert';

import 'react-s-alert/dist/s-alert-default.css';
import 'react-s-alert/dist/s-alert-css-effects/slide.css';

class Main extends React.Component {
    constructor(props) {
        super(props);
    }
    render() {
        return (
            <div>
                <span>
                    {this.props.children}
                </span>
                <Alert stack={{limit: 3}} />
            </div>
        )
    }
}

export default Main;

5. Make calls to activate alerts

You can activate your alerts in many different places in the app. You need to call proper methods. For Example:

Methods which you can use:

  • Alert.warning(message, configObj)
  • Alert.error(message, configObj)
  • Alert.info(message, configObj)
  • Alert.success(message, configObj)
  • Alert.close(alertId)
  • Alert.closeAll()

sAlert methods will return the already created alertId.

Example usage:

import React from 'react';
import Alert from 'react-s-alert';

class Home extends React.Component {
    handleClick1(e) {
        e.preventDefault();
        Alert.warning('<h1>Test message 1</h1>', {
            position: 'top-right',
            effect: 'scale',
            onShow: function () {
                console.log('aye!')
            },
            beep: false,
            timeout: 'none',
            offset: 100
        });
    }
    handleClick2(e) {
        e.preventDefault();
        Alert.info('Test message 2', {
            position: 'bottom-left',
            effect: 'bouncyflip',
            timeout: 'none'
        });
    }
    handleClick3(e) {
        e.preventDefault();
        Alert.error('Test message 3', {
            position: 'bottom-right',
            effect: 'slide',
            timeout: 'none'
        });
    }
    handleCloseAll(e) {
        e.preventDefault();
        Alert.closeAll();
    }
    render() {
        return (
            <div>
                <div>
                    <a href="#" onClick={this.handleClick1}>Click 1</a> |
                    <a href="#" onClick={this.handleClick2}>Click 2</a> |
                    <a href="#" onClick={this.handleClick3}>Click 3</a> |
                    <a href="#" onClick={this.handleCloseAll}>Close All</a>
                </div>
            </div>
        )
    }
}

export default Home;

You always need to provide a message. For example

Alert.error('Test message 3');

You can also provide a react component:

Alert.error(<MyComponent props1={props1} props2={props2}/>);

You don't need to provide the configuration object here, just remember to provide it globally.

Configuration details

With sAlert you can place your configuration as a global config in the main sAlert container, for example:

<Alert stack={{limit: 3}} html={true} />

You can also overwrite these global settings in the particular method call. For example, here we will overwrite the global settings for 'html' in our error alert call:

Alert.error('Error message...', {
    position: 'bottom-right',
    effect: 'slide',
    html: false
});

All possible configuration options:

First - only global configuration options

You can set it up only in the main sAlert component props

1. stack

You can stack your alerts or just display them in the same place.

Possible stack values:

  • true or false
  • object with:
    • limit (you can limit your alerts displayed on screen)
    • spacing (you can change the space around your alerts)

Examples:

<Alert stack={{limit: 3, spacing: 50}} />

or

<Alert stack={true} />
2. contentTemplate

You can prepare your own content template even with additional fields (More details can be found later on in this README.)

Examples:

<Alert contentTemplate={MyContentTemplate} />

Here you can also use all configuration options listed below.

Configuration options with a single sAlert method call

1. effect

You can provide the name of the animations effect, you also need to import proper CSS file.

Example:

In method call:

Alert.success('Message...', {
    effect: 'genie'
});

In global config:

<Alert effect='genie' />

Possible effects names:

  • slide
  • scale
  • bouncyflip
  • flip
  • genie
  • jelly
  • stackslide

Remember that you need to import the CSS files for the effects. See above.

2. position

Where the alert should appear.

Example:

In method call:

Alert.success('Message...', {
    position: 'top-right'
});

In global config:

<Alert position='top-right' />

Possible positions:

  • top (full width)
  • bottom (full width)
  • top-right
  • top-left
  • bottom-right
  • bottom-left
3. timeout

You can set up the timeout in ms.

Example:

In method call:

Alert.success('Message...', {
    timeout: 5000
});

In global config:

<Alert timeout={5000} />

Possible timeout values:

  • (Number - ms)
  • 'none'
4. html

You can configure if your alert should display HTML formated messages.

Example:

In method call:

Alert.success('<h1>Message...</h1>', {
    html: true
});

In global config:

<Alert html={true} />

Possible 'html' values:

  • true
  • false
5. offset

In px. Will be added to first alert (bottom or top - depends on the position in config).

Example:

In method call:

Alert.success('Message...', {
    offset: 150
});

In global config:

<Alert offset={150} />

Possible offset values:

  • (Number - px)
6. beep

You can set up your audio 'beeps'. Just configure your audio file path. (.mp3 files should work in every browser.) You can also configure 4 paths for 4 conditions.

There is no default audio sample in the package. You should use sound samples which you know that you have the right to use it.

Example:

In method call:

Alert.success('Message...', {
    beep: '/path-to-audio/file.mp3'
});

In global config:

<Alert beep={{
    info: '/path-to-audio/file-info.mp3',
    error: '/path-to-audio/file-error.mp3',
    warning: '/path-to-audio/file-warning.mp3',
    success: '/path-to-audio/file-success.mp3'}} />

or just one for all:

<Alert beep='/path-to-audio/file.mp3' />

Possible 'beep' values:

  • (String - audio file path) (one audio file for all alerts)
  • (Object)
    • {info: '/path/file.mp3', error: '/path/file.mp3', warning: '/path/file.mp3', success: '/path/file.mp3'}
7. preserveContext

Makes sure that your Alert always has the parent's context. It is needed because the Alert's height, which is needed for calculating the position of each element in the stack, is measured by directly mounting an Alert into DOM by using ReactDOM.render. If you want to include any custom JSX inside your Alert, e.g. for Material UI, which uses context for passing theme configuration, you will need this option to be set to true.

This options enables the usage of the new ReactDOM.unstable_renderSubtreeIntoContainer function, which works exactly the same as ReactDOM.render, but keeps the context from the parent's component. Even though this option is named as "unstable", it works perfectly fine.

Possible preserveContext values:

  • true or false (Defaults to false)

Example:

In method call:

Alert.success('Message...', {
    preserveContext: true
});

In global config:

<Alert preserveContext />
8. onShow

Execute a callback function. onShow will fire the function when the alert appears.

Example:

In method call:

Alert.success('Message...', {
    onShow: function () {
        console.log('onShow Fired!');
    }
});

In global config:

<Alert onShow={this.handleOnShow} />

Possible 'onShow' values:

  • (Function)
9. onClose

Execute a callback function. Will fire the function when the alert is closed.

Example:

In method call:

Alert.success('Message...', {
    onClose: function () {
        console.log('onClose Fired!');
    }
});

In global config:

<Alert onClose={this.handleOnClose} />

Possible 'onClose' values:

  • (Function)
10. customFields

You can pass a customFields object for your custom content template component. You need to prepare the component to be able to display customFields values. You'll read more about it below.

Example:

In global config you need to provide custom content template component:

<Alert contentTemplate={MyContentTemplate} />

In method call you can provide custom fields used in your custom template:

Alert.success('Message...', {
    customFields: {
        specialInfo: this.getSpecialInfo();
    }
});

Possible 'customFields' values:

  • (Object)

Overwrite content template component

With sAlert you have the possibility to overwrite the SAlertContentTmpl core component. This is useful when you want to provide more dynamic data in your alerts or just when you want to rebuild the HTML structure of the alert. This is very useful, but might not be trivial. Standard sAlerts will take only the message you want to display and some configuration. There will be use cases when you want to display some more dynamic data or just some more HTML structures.

I'll try to explain it by example:

Let's say that we want to have an alert with the additional dynamic data. We want the name of the customer, and a confirmation button which will close the alert.

Here is what we could do.

In our main app component we will use sAlert component (see above) with a custom content component:

import MyCustomContentTemplate from './MyCustomContentTemplate';
(...)
<Alert contentTemplate={MyCustomContentTemplate} />
(...)

We have just told our sAlert component that we will use a custom content component instead the core one which is called SAlertContentTmpl. (You should copy the content of the SAlertContentTmpl in your custom one and add your own modifications to it).

For example our MyCustomContentTemplate component could look like:

import React from 'react';
import Alert from 'react-s-alert';

class MyCustomContentTemplate extends React.Component {
    constructor(props) {
        super(props);
    }
    handleConfirm() {
        console.log('Customer confirmation!');
        Alert.close(this.props.id);
    }
    render() {
        return (
            <div className={this.props.classNames} id={this.props.id} style={this.props.styles}>
                <div className='s-alert-box-inner'>
                    {this.props.message}

                    {/* use this api to customize alert style */}
                    {this.props.condition}
                </div>
                <h3>{this.props.customFields.customerName}</h3>
                <button onClick={this.handleConfirm.bind(this)}>Confirm</button>
                <span className='s-alert-close' onClick={this.props.handleClose}></span>
            </div>
        )
    }
}

export default MyCustomContentTemplate;

Then you just need to pass the customerName value somewhere in your app. For example:

Alert.warning('Customer confirmation needed.', {
    customFields: {
        customerName: 'Stefan Kowalski'
    }
});

As you can see you should keep the other props here. These are the props which are needed to provide proper behaviour of your alerts. You need to be careful with custom content components.

Testing and Development

Clone and install it first:

git clone https://github.com/juliancwirko/react-s-alert.git
cd react-s-alert
npm install

If you want to test (Node.js 4.0 or newer):

npm test

or

npm run testonly

If you want to transpile from ES2015 to ES5:

npm run prepublish

Also check out

License

MIT

react-s-alert's People

Contributors

fabpico avatar fredericheem avatar ignatevdev avatar juliancwirko avatar kerryboyko avatar khardenstine avatar poops avatar yongzhoulu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-s-alert's Issues

Slide out by touch?

s-alert is almost the standard choice of alert solution! how about support touch slide out the alert? this is very useful for mobile users

Run build without React

I'm developing a Meteor app which includes React, and I'm getting the error that there are two copies of React

how can I remove the reference and build a new source in ./dist?

thank you!

Type definition

Does anyone has planned to have the type definition for TypeScript?

I am a big fan of this project. and I am using this a lot.
Thanks!!

Project use redux cannot work ?

Hi, my project use reactjs + redux,but it seems that cannot work?

My base component code:

import React, { PropTypes } from 'react';
import Alert from 'react-s-alert';
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';

import Header from './Header';
import Sidebar from './Sidebar';
import Footer from './Footer';

class Base extends React.Component {
  static propTypes = {
    children: PropTypes.node,
  };
  render() {
    const animationName = 'rag-fadeIn';
    return (
      <div className="wrapper">
        <Header />
        <Sidebar />
        <ReactCSSTransitionGroup
          component="section"
          transitionName={animationName}
          transitionEnterTimeout={500}
          transitionLeaveTimeout={500}
        >
        { this.props.children }
        </ReactCSSTransitionGroup>
        <Footer />
        <Alert stack={{ limit: 3 } } />
      </div>
    );
  }
}

export default Base;

I can find '.react-alert-wrapper' in my page, and my action code:

...
import Alert from 'react-s-alert';

export function submitIdentify(formData, workitemId) {
   return (dispatch) => {
       return fetch(xxx).then((res) => {
           // Alert.error cannot work.
          Alert.error('some error');
          // other code below can work well..
          ....
       })
   }
}

add useJSX support

It would be great if we could add a useJsx param instead of only useHtml

Alert is not displaying

Hi,

I have implemented react-s-alert. In my application but when i am triggering the alert its not displaying in my page.

I am using sweet alert, material ui snackbar also, everything is working fine. I tried to increase the z-index, but no luck.

My application is a react, redux, router with google maps component implemented web app.

React-s-alert not working in IE 11.

As far as I can see react-s-alert does not work in IE 11. Object.assign() is used in the code, and I don't think that is supported in ie11. Do you have a workaround for this?
We want to use react-s-alert in our project but we need to support internet explorer 11.

Thanks in advance!

specify default `configObject` for all alerts

There needs to be a way to set default values for the alert configObject so every call to Alert.success(), Alert.info(),Alert.warning(),Alert.error() need not pass in the same object.
If a configObject is passed, it should override the default values set.

Error: Cannot read property '_bound' of undefined

Receiving this error on React 0.14.6

Error: Cannot read property '_bound' of undefined
TypeError: Cannot read property '_bound' of undefined
    at SAlertContent.handleCloseAlert (SAlertContent.js:75)
    at SAlertContent.js:121

Expose an .update function [feature request]

Dear @juliancwirko,

S-Alert already exposes several functions to interact with alerts such as:
Alert.success(message, configObj)
Alert.close(alertId)

However, we have a use-case in which it is required to update a generated Alert.
We use a custom contentTemplate and provide customFields.
In our use-case, we would like the Alert to be rerendered with updated customFields.
A method with this signature would be sufficient:
Alert.update(alertId, updatedCustomFields)

Do you think this would fit for S-Alert?

Kind regards.

SyntaxError: Unexpected token . (.s-alert-box)

Building in Meteor 1.4.1.2 and getting the following error when importing s-alert.

W20161019-03:16:20.432(-4)? (STDERR) .s-alert-box,
W20161019-03:16:20.433(-4)? (STDERR) ^        
W20161019-03:16:20.433(-4)? (STDERR)          
W20161019-03:16:20.433(-4)? (STDERR) SyntaxError: Unexpected token .
W20161019-03:16:20.434(-4)? (STDERR)     at exports.runInThisContext (vm.js:53:16)
W20161019-03:16:20.434(-4)? (STDERR)     at Module._compile (module.js:373:25)
W20161019-03:16:20.434(-4)? (STDERR)     at Object.Module._extensions..js (module.js:416:10)
W20161019-03:16:20.435(-4)? (STDERR)     at Module.load (module.js:343:32)
W20161019-03:16:20.435(-4)? (STDERR)     at Module.Mp.load (/Users/mattmacpherson/.meteor/packages/babel-compiler/.6.9.1_1.15j1r1l++os+web.browser+web.cordova/npm/node_modules/reify/node/runtime.js:16:23)
W20161019-03:16:20.435(-4)? (STDERR)     at Function.Module._load (module.js:300:12)
W20161019-03:16:20.435(-4)? (STDERR)     at Module.require (module.js:353:17)
W20161019-03:16:20.436(-4)? (STDERR)     at require (internal/module.js:12:17)
W20161019-03:16:20.436(-4)? (STDERR)     at npmRequire (/Users/mattmacpherson/Code/edabit/.meteor/local/build/programs/server/npm-require.js:129:10)
W20161019-03:16:20.436(-4)? (STDERR)     at Module.Mp.useNode (packages/modules-runtime/modules-runtime.js:69:1)

Alert not working using require

I am importing Alert with require but I got this error

warning.js:45Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components)

Otherwise how to migrate from ES5 to ES2015 ?

Cannot use Component instead of string message

Using react-s-alert version 1.2.0

Warning:
Invalid prop message of type object supplied to SAlertContent, expected string.

What I found is that the SAlertContent propTypes have different values than the ones in the master branch
message: _react2.default.PropTypes.string.isRequired,.

It seems that the code on npm was not updated only the version.

Thank you for your time!

Multiple instances

It would be great to have multiple instances of Alert to fire them independently. I didn't found anything in the docs for realizing this, i must do this with workarounds.

Use case: Global alert for all types of alerts, and a separate alert for Forms in a modal.

Feature Request:

// entry.jsx. The global alert.
import Alert from 'react-s-alert';
// ...
<div>
    <Alert/>
    <BrowserRouter>
        <Routing/>
    </BrowserRouter>
</div>
// ...
// Is fired with Alert.error('global error');
// Created component in a modal. The separate alert.
import FormAlert from "react-s-alert";
// ...
render() {
        if (this.props.errors) {
            FormAlert.error('form error');
        }
        return <div>
            <FormAlert/>
            // .. the form
        </div>;
    }

When i do this right now, all alerts are fired in both places.

Default position not working

I must be doing an obvious mistake. Using

<Alert onRouteClose={false} position="bottom" />

The alerts still appear on the top right.

UNMET PEER DEPENDENCY prop-types@^15.5.4

I get this error Message, i think it´s because i use the new REACT Version.

Failed to compile.

Error in ./~/react-s-alert/dist/SAlert.js
Module not found: 'prop-types' in /Users/davidbiller/curious_web/node_modules/react-s-alert/dist

@ ./~/react-s-alert/dist/SAlert.js 3:8-181

After Alert.success, it always show after Alert.error

Hi, i have this code on my "Container"

import React from 'react';
import {connect} from 'react-redux';

import Alert from 'react-s-alert';
import * as Constants from '../../webservices/Constants'

// mandatory
import 'react-s-alert/dist/s-alert-default.css';

// optional - you can choose the effect you want
import 'react-s-alert/dist/s-alert-css-effects/slide.css';
import 'react-s-alert/dist/s-alert-css-effects/scale.css';
import 'react-s-alert/dist/s-alert-css-effects/bouncyflip.css';
import 'react-s-alert/dist/s-alert-css-effects/flip.css';
import 'react-s-alert/dist/s-alert-css-effects/genie.css';
import 'react-s-alert/dist/s-alert-css-effects/jelly.css';
import 'react-s-alert/dist/s-alert-css-effects/stackslide.css';

class ErrorDialog extends React.Component {

  componentDidUpdate(prevProps, prevState){
    if(this.props.error && !prevProps.error){

      if(Constants.LOG_ENABLED){
        console.error("ErrorDialog error: ", this.props.error)
        console.error("ErrorDialog section: ", this.props.label)
        console.error("ErrorDialog url: ", this.props.url)
        console.error("ErrorDialog func: ", this.props.func)
      }

      let errorLabel = this.props.label ? this.props.label : 'Ha ocurrido un error'
      Alert.error(errorLabel, {
          onShow: () => this.props.removeError(),
      });
    }
  }

  render() {
    return (
      <Alert effect='slide' position='top-right' offset={40} stack={{limit: 3}} />
    )
  }
}

let mapStateToProps = (state) => {
  return {
    error: state.error.error,
    label: state.error.label,
    url: state.error.url,
    func: state.error.func,
  }
}

let mapDispatchToProps = (dispatch) => {
  return {
    removeError: () => {
      dispatch({type: 'REMOVE_ERROR'})
    },
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(ErrorDialog);

Works fine, but if in other view i do: "Alert.success('bla bla bla')", after that whenever I make an alert.error, it also shows the Alert.success also.

How can i fix it? Thanks!

onClick is missing [Feature request]

I think an onClick handler should be added to the possible configuration options.

We currently have onClose and onShow.

I surely know one can supply confirmation button in html or modify template(I'm currently doing this) in order to achieve this, but it would be great if we can have native support.

Expected default template with onClick support:

import React from 'react';
import PropTypes from 'prop-types';

class SAlertContentTmpl extends React.Component {
  render() {
    return (
      <div role="button" tabIndex="-1" onClick={this.props.handleClick} className={this.props.classNames} id={this.props.id} style={this.props.styles}>
        <div className="s-alert-box-inner">
          {this.props.message}
        </div>
        <span role="button" tabIndex="-1" className="s-alert-close" onClick={this.props.handleClose} />
      </div>
    );
  }
}

SAlertContentTmpl.defaultProps = {
  customFields: null
};

SAlertContentTmpl.propTypes = {
  id: PropTypes.string.isRequired,
  classNames: PropTypes.string.isRequired,
  styles: PropTypes.object.isRequired,
  message: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.object
  ]).isRequired,
  handleClick: PropTypes.func.isRequired,
  handleClose: PropTypes.func.isRequired,
  customFields: PropTypes.object // eslint-disable-line react/no-unused-prop-types
};

export default SAlertContentTmpl;

Allow setting of contentTemplate in configObj

It would be neat if I were able to use different templates for different alerts, by setting the contentTemplate in the configObj, like this:

Alert.success('Alert message', {
    contentTemplate: AnotherTemplate,
});

the cross of the alert does not work

Hi,

I have a simple error alert i am not able to close the alert on click of the cross.Will I have to make a custom template to do this.I mean am i doing something wrong.

this is my jsx

import Alert from 'react-s-alert';

onClickHandler = () => {
           Alert.closeAll();
       Alert.error('Cannot Edit', {
        position: 'bottom-right',
        effect: 'slide',
        timeout: 3000
    });
}

render()=>{
<div>
  <a onClick={this.clickHandler}>Edit</a>
  <Alert stack={{limit: 3}} />
</div>
}

and i have added the css in my index.html,Also it does not close on the timeout as well

Warning: Failed prop type: Invalid prop `timeout` supplied to `SAlertContent`.

firstly, thank you for this component :)

I'm getting an error when I try to fire an alert. I am invoking the following:

Alert.success('
	<p>Success</p><p>Classification updated</p>' , {
		position: 'top-right',
		effect: 'jelly',
		beep: false,
		timeout: '4000',
		html: true
		}
)

and the component is being rendered as follows:
<Alert stack={{limit: 3}} />

The alert is firing successfully, however it's having a problem with the props.

I'm using the following versions:
[email protected]
[email protected]
[email protected]

Any ideas on what I'm doing wrong?

Error: Firefox.

Hi.
In the firefox browser, it does not disappear after the animation effect.
(You can also check the demo page.)

Kind regards,

UMD build?

Your library looks great! Would you be open to providing a UMD build for use in non-Node environments (like via a CDN)?

_renderNewRootComponent

Im using meteor to display alerts when some vars changes.

trackNewOrders(){

    Tracker.autorun( (thisTracker) =>{
        var oldest = _.max(this.props.orders,(order) => {
          return order.clock;
        });
        if(oldest.clock){
          if (!_.findWhere(this.state.array, {'_id':oldest._id})) {
            Alert.success('New order, {
              position: 'top-right'
            });
            this.state.array.push(oldest);
          }
        }
    });
  } 

_renderNewRootComponent(): Render methods should be a pure function of props and state; triggering nested component updates from render is not allowed. If necessary, trigger nested updates in componentDidUpdate.

I dont understand that error

Keep alert when redirect page.

Hi guys,

After user login success, I did the following two things:

  • Alert success message by react-s-alert
  • Redirect to /profile page

But redirect page has caused react-s-alert not working. Because the component has destroyed.

class Login extends React.Component {
...
 login = () => {
   apiLogin().then(() => {
    Alert.success('login success');
    return Router.push('/profile');
   })
 }
...

Thanks

JSX as Message

Hi,

is it possible to add JSX a message. I tried the following, but it's showing [object Object]. It's kind of obvious to use jsx so I'd kindly like to ask if you would consider adding support for jsx? (Or did I miss something and it's already possible?)

        Alert.error(<div>
          {response.errors.map((error, index) => {(
            <div key={`ticket-error-${index}`}>
              {error.message}
            </div>
          )})}
        </div>, {
          position: 'top-right',
          effect: 'slide',
          beep: '/media/pop.mp3',
          html: true,
        });

Preact rendering issue

Every second attempt to show Alert renders an invisible element (style=display:none) when using Preact instead of React.
image

How do you get the AlertId?

Hi, how do you get the alertid in order to pass it to the close method? The documentation says "sAlert methods will return the already created alertId.", but I'm not sure how to get this id and pass it to the close method.

context not passed correctly to contentTemplate

I'm using material-ui (http://www.material-ui.com) which is using context to pass theme around to components.
I'm also using the contentTemplate and I pass a react component to it.
The bug is that this react Component that i'm passing doesn't have access to the context of the app therefore I can't use any material-ui's component in it.

tiny ex:

class myContentTemplate extends React.Component {
static contextTypes = {
 myVal: PropTypes.object
}

 render() {
  this.context.myVal // This will be undefined.
 }
}

Alert leaves colored strip after it goes away

Im using react and meteor.js, i have this problem where sometimes a stripe of the alert color will stay on screen, dunno if it is a rendering mistake by me or a problem with the alerts. but it kinda kills the alerts and i love them

Question about security

@juliancwirko you've created a really nice component here. I had a question for you about security. What's to prevent someone from using a <script> tag when loading something like:

Alert.error('Test message 3');

I'm concerned about XSS attacks.

Get `condition` in content template?

Is there anyway I can get condition in content template? I can extract it from class names passed in props, but if there is anyway to do it without hacking it would be great.

nothing happen on meteor 1.3 app

hi, I've created a meteor 1.3 app, and try to use react-s-alert, but nothing happen

this is app layout

import React from 'react';
import Alert from 'react-s-alert';

const Layout = ({content = ()=>null})=> {
    return <div>
        <header>

        </header>

        <div>
            {content()}
            <Alert stack={{limit: 3}}/>
        </div>

        <footer>

        </footer>
    </div>
};

export default Layout

this is test page

import React from 'react';
import Container from '/client/modules/core/components/container';
import {PageHeader, Button} from 'react-bootstrap';
import Alert from 'react-s-alert'

const Page = (props) => {
    return <Container>
        <PageHeader>测试页</PageHeader>
        <Button onClick={onClick}>alert</Button>
    </Container>;

    function onClick() {
        console.log('before');
        const id = Alert.info('hi');
        console.log('after ', id);
    }
};

export default Page

window.Alert = Alert;

Place alerts in center of screen or in center of top of screen

I would like functionality in react-s-alert to place alerts in the center of the screen, but not with full width.
The modes
top-center and center-center would be very good!
Maybe one of the states could be done with an offset..
But a "top-center" would be great to have.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.