Search results

Getting Started

The following section explains how to create a simple badge component using styles and badge’s basic usage.

Dependencies

Install the following required dependent package to render the Badge component.

|-- @syncfusion/ej2-notifications

Set up your development environment

You can use Create-react-app to setup the applications. To install create-react-app run the following command.

npm install -g create-react-app

Start a new project using create-react-app command as follows

create-react-app quickstart --scripts-version=react-scripts-ts

cd quickstart

Install the below required dependency package in order to use the Badge component in your application.

npm install @syncfusion/ej2-notifications –save
  • Badge CSS files are available in the ej2-notifications package folder. Import the Badge component’s required CSS references as follows in src/App.css.
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-notifications/styles/material.css";

We can also use CRG to generate combined component styles.

Initialize the Badge Component

Add an HTML span element with e-badge class inside any wrapper element (h1) into your return method.

import * as React from 'react';
import './App.css';

export default class App extends React.Component<{}, {}> {
  render() {
    return (
        <span>Badge Component <span className="e-badge">New</span></span>
    );
  }
}
  • Run the application in the browser using the following command.
npm start

Output will be as follows:

Source
Preview
index.tsx
index.html
index.css
import * as React from "react";
import * as ReactDOM from "react-dom";

class ReactApp extends React.Component<{}, {}> {
  render() {
       return (
        <h1>Badge Component <span className="e-badge e-badge-primary">New</span></h1>
       );
  }
}
ReactDOM.render(<ReactApp/>, document.getElementById("element"));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 React Badge 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/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-notifications/styles/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>
    <link rel="stylesheet" href="index.css" />
    <style>
        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }
    </style>
</head>

<body>
    <div id='element'>
        <div id='loader'>Loading....</div></div>
</body>
</html>
#container {
    visibility: hidden;
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  font-family: 'Helvetica Neue','calibiri';
  font-size: 14px;
  top: 45%;
  left: 45%;
}

#element {
    display: flex;
    width: 400px;
    margin: auto;
    border: 1px solid #dddddd;
    border-radius: 3px;
    justify-content: center;
}

See Also

Types of Badge