Getting Started with KendoReact Notification

The KendoReact Notification renders a brief message to the user with information about the status of an application process and enables you to animate its rendering and control its position.

The KendoReact Notification component is part of the KendoReact library of React UI components. It is distributed through NPM under the kendo-react-notification package.

Basic Usage

The following example demonstrates the Notification in action.

<style>
  .k-notification-container {
      margin: 6px;
  }
</style>
class App extends React.Component {
    state = { success: false, error: false, warning: false, info: false, none: false };
    onToggle = flag => this.setState({ [flag]: !this.state[flag] });

    render() {
        const { success, error, warning, info, none } = this.state;

        return (
            <React.Fragment>
                <button
                    className="k-button"
                    onClick={() => this.onToggle('success')}
                >
                    {(success ? 'hide ' : 'show ') + 'Success'}
                </button>
                &nbsp;
                <button
                    className="k-button"
                    onClick={() => this.onToggle('error')}
                >
                    {(error ? 'hide ' : 'show ') + 'Error'}
                </button>
                &nbsp;
                <button
                    className="k-button"
                    onClick={() => this.onToggle('warning')}
                >
                    {(warning ? 'hide ' : 'show ') + 'Warning'}
                </button>
                &nbsp;
                <button
                    className="k-button"
                    onClick={() => this.onToggle('info')}
                >
                    {(info ? 'hide ' : 'show ') + 'Info'}
                </button>
                <button
                    className="k-button"
                    onClick={() => this.onToggle('none')}
                >
                    {(none ? 'hide ' : 'show ') + 'Unstyled'}
                </button>
                <NotificationGroup
                    style={{
                        right: 0,
                        bottom: 0,
                        alignItems: 'flex-start',
                        flexWrap: 'wrap-reverse'
                    }}
                >
                    <Fade enter={true} exit={true}>
                        {success && <Notification
                            type={{ style: 'success', icon: true }}
                            closable={true}
                            onClose={() => this.setState({ success: false })}
                        >
                            <span>Your data has been saved.</span>
                        </Notification>}
                    </Fade>
                    <Fade enter={true} exit={true}>
                        {error && <Notification
                            type={{ style: 'error', icon: true }}
                            closable={true}
                            onClose={() => this.setState({ error: false })}
                        >
                            <span>Oops! Something went wrong ...</span>
                        </Notification>}
                    </Fade>
                    <Fade enter={true} exit={true}>
                        {warning && <Notification
                            type={{ style: 'warning', icon: true }}
                            closable={true}
                            onClose={() => this.setState({ warning: false })}
                        >
                            <span>Your password will expire in 2 days!</span>
                        </Notification>}
                    </Fade>
                    <Fade enter={true} exit={true}>
                        {info && <Notification
                            type={{ style: 'info', icon: true }}
                            closable={true}
                            onClose={() => this.setState({ info: false })}
                        >
                            <span>You have 1 new message!</span>
                        </Notification>}
                    </Fade>
                    <Fade enter={true} exit={true}>
                        {none && <Notification
                            type={{ style: 'none', icon: false }}
                            closable={true}
                            onClose={() => this.setState({ none: false })}
                        >
                            <span>Hanna Moos likes your status.</span>
                        </Notification>}
                    </Fade>
                </NotificationGroup>
            </React.Fragment>
        );
    }
}

ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);

Functionality and Features

Installation

  1. Download and install the package. Use Node.js v5.0.0 or later.

    npm install --save @progress/kendo-react-notification
  2. Once installed, import the package module.

    // ES2015 module syntax
    import { Notification } from '@progress/kendo-react-notification';
    // CommonJS format
    const { Notification } = require('@progress/kendo-react-notification');
  3. You are required to install one of the Kendo UI themes to style your components. For more information on how to add the styles, refer to the article on getting started.

Dependencies

The Notification package requires the following peer dependencies that have to be installed by your application:

  • react 16.8.2*
  • react-dom
 /