1.0.1 • Published 7 years ago

react-ios-alert v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

react-alert

Alert component imitated iOS build with react

Demo

You can find demo in folder example

demo

Usage with React

1、Install the package

npm install react-alert --save

2、Using as your need

// Example 1:

import React, { Component } from 'react'
import Alert from 'react-alert'

import 'react-ios-alert/dist/react-ios-alert.min.css'

class Main extends Component {
    state = {
        showAlert: false
    }
    render() {
        const alertOpt = {
                title: 'Alert',
                content: 'This is a demo!',
                confirmText: 'Yes',
                cancelText: 'Cancel',
                callback: function(){alert('yes callback called!')},
                cancelCallback: function(){alert('cancel callback called!')},
                close: this.hide.bind(this)
            };
        return (
            <div>
                {
                    !!this.state.showAlert && <Alert {...alertOpt} />
                }
                <button onClick={e=>this.show()}>click me to show Alert</button>
            </div>
        )
    }
    show() {
        this.setState({
            showAlert: true
        })
    }
    hide() {
        this.setState({
            showAlert: false
        })
    }
}

// Example 2:

import { SingleAlert } from 'react-alert'

// You can call SingleAlert.show anywhere and anytime, there will be only one Alert DOM node be added.

SingleAlert.show({
    content: 'Alert实例',
    confirmText: '知道了'
});

setTimeout(() => {
    SingleAlert.hide();
}, 3000)

Configuration

ParamTypeDescription
titlestringThe brief description of purpose
contentstring / JSXThe detail statement of purpose
confirmTextstringThe text in CONFIRM button
cancelTextstringThe text in CANCEL button
confirmAtRightboolThe CONFIRM is at the right of CANCEL button or not
callbackfunctionEvents called after CONFIRM button is clicked
cancelCallbackfunctionEvents called after CANCEL button is clicked
closefunctionUse container's method to close the Alert Dialog
useTapboolUse Tap event as default, not Click

License

Copyright(c) 2016-2017 AlloyTeam. Licensed under MIT license.