Search results

Positions

Toast position can be updated based on predefined positions or user customizable positions. Predefined position combinations are updated in X and Y position properties.

Predefined

X Positions

  • Left
  • Center
  • Right

Y Positions

  • Top
  • Bottom

In the case of multiple Toast display, new Toast position will not update on dynamic change of property values, until the old Toast messages removed. Toast occupies full width when we set width as ‘100%’, so X positions won’t affect changes when ‘100%’ width.

Custom

Custom X and Y Position can be given as pixels/numbers/percentage. The number value is considered as pixels. based value top and left value updated in the toast.

Source
Preview
index.tsx
index.html
App.css.jsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App  from './App';

ReactDOM.render(<App />, document.getElementById('element'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 React Accordion Sample</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
    <style>
        #multiToast>div>button {
            margin-top: 20px;
        }

        #customChoose {
            display: none;
        }

        #toast_full_Position table {
            width: 100%;
        }

        #toast_full_width,
        #toast_full_Position {
            padding-top: 20px;
            margin: 20px;
        }

        #toast_full_width table td>div,
        #toast_full_Position table td>div {
            padding: 25px 0 0 0;
        }

        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }

        #elementTarget .e-toast-message {
            width: 100%;
        }

        .progress {
            height: 20px;
            position: relative;
            margin: 20px 0 20px 0;
            background: #555;
            -moz-border-radius: 25px;
            -webkit-border-radius: 25px;
            border-radius: 25px;
            box-shadow: inset 0 -1px 1px rgba(255, 255, 255, 0.3);
        }

        .progress span {
            background-color: #f0a3a3;
            background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #f0a3a3), color-stop(1, #f42323));
            display: block;
            height: 100%;
            border-radius: 10px;
            width: 50%;
            position: relative;
            overflow: hidden;
        }

        .progress span::after {
            background-image: -webkit-gradient(linear, 0 0, 100% 100%,
            color-stop(.25, rgba(255, 255, 255, .2)),
            color-stop(.25, transparent), color-stop(.5, transparent),
            color-stop(.5, rgba(255, 255, 255, .2)),
            color-stop(.75, rgba(255, 255, 255, .2)),
            color-stop(.75, transparent), to(transparent));
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            background-size: 50px 50px;
            -webkit-animation: moveAnimate 2s linear infinite;
            overflow: hidden;
        }

        @-webkit-keyframes moveAnimate {
            0% {
                background-position: 0 0;
            }
            100% {
                background-position: 50px 50px;
            }
        }

        #elementToastTime {
            text-align: center;
        }

        #elementToastTime img {
            width: 100px;
            height: 100px;
            border-radius: 50%;
        }

        #elementToastTime .e-toast-message {
            width: inherit;
        }


        body> #template_toast .e-toast {
            width: 400px !important;
        }


        #template_toast .horizontal-align {
            margin: 10px 0;
        }

        #template_toast .horizontal-align .toast-content .toast-message {
            opacity: 0.4;
        }

        #template_toast .horizontal-align .toast-content {
            display: inline-flex;
            flex: 1;
            flex-direction: column;
            margin-left: 10px;
        }
    </style>
</head>

<body>
    <div id='root'>
        <div id='loader'>Loading....</div>
    </div>
    <div id='templateToast' style="display: none;color:red"> System affected by virus !!! </div>
</body>
<script id="template_toast_ele" type="text/x-template">
    <div id='template_toast' style="display: none">
        <div class="horizontal-align">
            <div class='toast-content'>
                <div class='toast-title'>
                    Weekend Alarm
                </div>
                <div class='toast-message'> With traffic, its likely to take 45 minutes to get to jenny's 24th Birthday Bash at Hillside Bar, 454 E.
                    Olive Way by 10:00PM </div>
            </div>
        </div>
        <img src="http://npmci.syncfusion.com/development/demos/src/toast/resource/map.jpg" width="100%" height="70%">
    </div>
</script>

</html>
import { ButtonComponent, RadioButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as React from "react";
import './App.css';
class App extends React.Component {
    constructor(props) {
        super(props);
        this.timeOutDelay = 600;
        this.dropdownDB = ['Top Left', 'Top Right', 'Top Center', 'Bottom Left', 'Bottom Right', 'Bottom Center'];
        this.state = {
            position: { X: 'Center', Y: "Bottom" },
            target: document.body,
            width: 300
        };
    }
    toastCreated() {
        this.toastShow(600);
    }
    toastShow(timeOutDelay) {
        setTimeout(() => {
            this.toastInstance.show();
        }, timeOutDelay);
    }
    valueChange(e) {
        this.toastInstance.hide('All');
        this.setToastPosValue(e.value);
        this.toastShow(1000);
    }
    radioChange(e) {
        if (this.radioInstance.element.checked) {
            this.toastInstance.hide('All');
            document.getElementById('dropdownChoose').style.display = 'table-cell';
            document.getElementById('customChoose').style.display = 'none';
            this.setToastPosValue(this.dropDownInstance.value.toString());
            this.customFlag = true;
            this.toastShow(1000);
        }
    }
    radioChange3(e) {
        if (this.radioInstance3.element.checked) {
            this.toastInstance.hide('All');
            this.setState({ target: document.body });
            this.toastShow(1000);
        }
    }
    radioChange2(e) {
        if (this.radioInstance2.element.checked) {
            this.toastInstance.hide('All');
            this.setState({ target: '#toast_pos_target' });
            this.toastShow(1000);
        }
    }
    radioChange1(e) {
        if (this.radioInstance1.element.checked) {
            this.toastInstance.hide('All');
            document.getElementById('dropdownChoose').style.display = 'none';
            document.getElementById('customChoose').style.display = 'table-cell';
            this.setCustomPosValue();
            this.customFlag = true;
            this.toastShow(1000);
        }
    }
    setCustomPosValue() {
        this.setState({
            position: {
                X: parseInt(document.getElementById('xPos').value, 10),
                Y: parseInt(document.getElementById('yPos').value, 10)
            }
        });
    }
    setToastPosValue(value) {
        value = value.toLowerCase().replace(' ', '');
        switch (value) {
            case 'topleft':
                this.setState({ position: { X: 'Left', Y: 'Top' } });
                break;
            case 'topright':
                this.setState({ position: { X: 'Right', Y: 'Top' } });
                break;
            case 'topcenter':
                this.setState({ position: { X: 'Center', Y: 'Top' } });
                break;
            case 'topfullwidth':
                this.setState({ position: { X: 'Center', Y: 'Top' }, width: '100%' });
                break;
            case 'bottomleft':
                this.setState({ position: { X: 'Left', Y: 'Bottom' } });
                break;
            case 'bottomright':
                this.setState({ position: { X: 'Right', Y: 'Bottom' } });
                break;
            case 'bottomcenter':
                this.setState({ position: { X: 'Center', Y: 'Bottom' } });
                break;
            case 'bottomfullwidth':
                this.setState({ position: { X: 'Center', Y: 'Bottom' }, width: '100%' });
                break;
        }
    }
    render() {
        return (<div id="toast_pos_target">
        <div id="toast_full_Position" className='row'>
          <table>
            <tbody>
              <tr>
                <td>
                  <div>
                    <RadioButtonComponent ref={custom => this.radioInstance = custom} checked={true} label='Position' name="position" change={this.radioChange = this.radioChange.bind(this)}/>
                  </div>
                </td>
                <td>
                  <div>
                    <RadioButtonComponent ref={custom => this.radioInstance1 = custom} label='Custom' name="position" change={this.radioChange1 = this.radioChange1.bind(this)}/>
                  </div>
                </td>
              </tr>
              <tr>
                <td id="dropdownChoose" colSpan={2}>
                  <div>
                    <DropDownListComponent ref={drop => this.dropDownInstance = drop} id="ddlelement" dataSource={this.dropdownDB} placeholder="Select a Position" change={this.valueChange = this.valueChange.bind(this)} index='4'/>
                  </div>
                </td>
              </tr>
              <tr>
                <td id='customChoose'>
                  <div className='e-row'>
                    <div className='e-float-input'>
                      <input type='text' className='e-input' id='xPos' defaultValue={'50'} required={true}/>
                      <span className='e-float-line'/>
                      <label className="e-float-text">X Position</label>
                    </div>
                  </div>
                  <div className='e-row'>
                    <div className='e-float-input'>
                      <input type='text' className='e-input' id='yPos' defaultValue={'50'} required={true}/>
                      <span className='e-float-line'/>
                      <label className="e-float-text">Y Position</label>
                    </div>
                  </div>
                </td>
              </tr>
              <tr>
                <td>
                  <div>
                    <RadioButtonComponent ref={custom => this.radioInstance2 = custom} checked={true} label='Target' name="toast" change={this.radioChange2 = this.radioChange2.bind(this)}/>
                  </div>
                </td>
                <td>
                  <div>
                    <RadioButtonComponent ref={custom => this.radioInstance3 = custom} checked={true} label='Global' name="toast" change={this.radioChange3 = this.radioChange3.bind(this)}/>
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
        <ButtonComponent cssClass="e-primary" onClick={this.toastShow = this.toastShow.bind(this, 500)}> Show Toast </ButtonComponent>
        <ToastComponent ref={toast => this.toastInstance = toast} title="Matt sent you a friend request" content="Hey, wanna dress up as wizards and ride our hoverboards?" target={this.state.target} width={this.state.width} position={this.state.position} created={this.toastCreated = this.toastCreated.bind(this)}/>
      </div>);
    }
}
;
export default App;

See Also