Getting Started
30 Jan 20234 minutes to read
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
```bash
create-react-app quickstart --scripts-version=react-scripts-ts
cd quickstart
```
```bash
create-react-app quickstart
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 insrc/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 * as ReactDOM from "react-dom";
import './App.css';
function App() {
return (
<span>Badge Component <span className="e-badge">New</span></span>
);
}
export default App;
ReactDOM.render(<App />, document.getElementById("element"));
- Run the application in the browser using the following command.
npm start
Output will be as follows:
import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
return (<h1>Badge Component <span className="e-badge e-badge-primary">New</span></h1>);
}
export default App;
ReactDOM.render(<App />, document.getElementById("element"));
import * as React from "react";
import * as ReactDOM from "react-dom";
function App() {
return (
<h1>Badge Component <span className="e-badge e-badge-primary">New</span></h1>
);
}
export default App;
ReactDOM.render(<App />, 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="https://cdn.syncfusion.com/ej2/20.4.48/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/20.4.48/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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='element'>
<div id='loader'>Loading....</div></div>
</body>
</html>