This section briefly explains how to create a simple DropDownButton component and configure its available functionalities in React.
The following list of dependencies are required to use the DropDownButton
component in your application.
|-- @syncfusion/ej2-react-splitbuttons
|-- @syncfusion/ej2-react-base
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-splitbuttons
|-- @syncfusion/ej2-popups
|-- @syncfusion/ej2-buttons
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
create-react-app quickstart
cd quickstart
‘react-scripts-ts’ is used for creating React app with typescript.
All the available Essential JS 2 packages are published in
npmjs.com
public registry.
You can choose the component that you want to install.
To install DropDownButton component, use the following command
npm install @syncfusion/ej2-react-splitbuttons –save
Now, you can start adding DropDownButton component in the application. For getting started, add the
DropDownButton component in src/App.tsx
file using following code.
Add the below code in the src/App.tsx
to initialize the DropDownButton.
import { enableRipple } from '@syncfusion/ej2-base';
import { DropDownButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import './App.css';
enableRipple(true);
// To render DropDownButton.
export default class App extends React.Component<{}, {}> {
public render() {
return (
<div>
<DropDownButtonComponent id="element" />
</div>
);
}
}
import { enableRipple } from '@syncfusion/ej2-base';
import { DropDownButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import './App.css';
enableRipple(true);
// To render DropDownButton.
export default class App extends React.Component {
render() {
return (<div>
<DropDownButtonComponent id="element"/>
</div>);
}
}
Import the DropDownButton component required CSS references as follows in src/App.css
.
/* import the DropDownButton dependency styles */
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
After initialization, populate the DropDownButton with data using
the items
property.
Here, an array of string values is passed to the DropDownButton component.
import { enableRipple } from '@syncfusion/ej2-base';
import { DropDownButtonComponent, ItemModel } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import './App.css';
enableRipple(true);
// To render DropDownButton.
export default class App extends React.Component<{}, {}> {
public items: ItemModel[] = [
{
text: 'Cut',
},
{
text: 'Copy',
},
{
text: 'Paste',
}];
public render() {
return (
<div>
<DropDownButtonComponent id="element" items={this.items}> Clipboard </DropDownButtonComponent>
</div>
);
}
}
import { enableRipple } from '@syncfusion/ej2-base';
import { DropDownButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import './App.css';
enableRipple(true);
// To render DropDownButton.
export default class App extends React.Component {
constructor() {
super(...arguments);
this.items = [
{
text: 'Cut',
},
{
text: 'Copy',
},
{
text: 'Paste',
}
];
}
render() {
return (<div>
<DropDownButtonComponent id="element" items={this.items}> Clipboard </DropDownButtonComponent>
</div>);
}
}
After completing the configuration required to render a basic DropDownButton, run the following command to display the output in your default browser.
npm start
import { enableRipple } from '@syncfusion/ej2-base';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DropDownButtonComponent, ItemModel } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
// To render DropDownButton.
class App extends React.Component<{}, {}> {
public items: ItemModel[] = [
{
text: 'Cut',
},
{
text: 'Copy',
},
{
text: 'Paste',
}];
public render() {
return (
<div>
<DropDownButtonComponent id="element" items = {this.items}> Clipboard </DropDownButtonComponent>
</div>
);
}
}
ReactDom.render(<App />,document.getElementById('button'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React DropDownButton</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-buttons/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<link href="styles.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='button'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>
import { enableRipple } from '@syncfusion/ej2-base';
import { DropDownButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
// To render DropDownButton.
class App extends React.Component {
constructor() {
super(...arguments);
this.items = [
{
text: 'Cut',
},
{
text: 'Copy',
},
{
text: 'Paste',
}
];
}
render() {
return (<div>
<DropDownButtonComponent id="element" items={this.items}> Clipboard </DropDownButtonComponent>
</div>);
}
}
ReactDom.render(<App />, document.getElementById('button'));