React Suite Dropdown Dropdown with Icon
Last Updated :
28 Jun, 2022
React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The dropdown component allows the user to provide navigation that uses a select picker if you want to select a value.
Dropdown with Icon will help us to add an image as per the dropdown item. This will add more attractiveness towards our items.
Syntax:
<Dropdown title="GFG">
<Dropdown.Item icon={Icon}>{Options} </Dropdown.Item>
</Dropdown>
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
cd foldername
Step 3: After creating the ReactJS application, Install the required module using the following command:
npm install rsuite
Project Structure: It will look like the following.
Example 1: Now write down the following code in the App.js file. Here, App is our default component where we have written our code. In this example, we will simply create a dropdown menu and add icons to them. We have imported icons from rsuite resources https://rsuitejs.com/resources/icons/
JavaScript
import React from 'react';
import Dropdown from 'rsuite/Dropdown';
import 'rsuite/dist/rsuite.min.css';
import CodeIcon from '@rsuite/icons/Code';
import PageIcon from '@rsuite/icons/Page';
import DetailIcon from '@rsuite/icons/Detail';
import FolderFillIcon from '@rsuite/icons/FolderFill';
import FileDownloadIcon from '@rsuite/icons/FileDownload';
import FileUploadIcon from '@rsuite/icons/FileUpload';
function App() {
return (
<div>
<h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
<h3>React Suite Dropdown Dropdown with Icon</h3>
<Dropdown title="GeeksforGeeks" icon={<CodeIcon />}>
<Dropdown.Item icon={<PageIcon />}>
New File
</Dropdown.Item>
<Dropdown.Item icon={<FolderFillIcon />}>
New File with Current Profile
</Dropdown.Item>
<Dropdown.Item icon={<FileDownloadIcon />}>
Download As...
</Dropdown.Item>
<Dropdown.Item icon={<DetailIcon />}>
Export PDF
</Dropdown.Item>
<Dropdown.Item icon={<FileUploadIcon />}>
File Upload
</Dropdown.Item>
<Dropdown.Item icon={<DetailIcon />}>
Exit
</Dropdown.Item>
</Dropdown>
</div>
)
}
export default App;
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Example 2: In this example, we will learn how can we use a colored icon with the Dropdown menu.
JavaScript
import React from 'react';
import Dropdown from 'rsuite/Dropdown';
import 'rsuite/dist/rsuite.min.css';
import CodeIcon from '@rsuite/icons/Code';
import PageIcon from '@rsuite/icons/Page';
import DetailIcon from '@rsuite/icons/Detail';
import FolderFillIcon from '@rsuite/icons/FolderFill';
import FileDownloadIcon from '@rsuite/icons/FileDownload';
import FileUploadIcon from '@rsuite/icons/FileUpload';
function App() {
return (
<div>
<h1 style={{ color: 'green' }}>
GeeksforGeeks
</h1>
<h3>React Suite Dropdown with Icon</h3>
<Dropdown title="GeeksforGeeks"
icon={<CodeIcon style={{ color: 'red' }} />}>
<Dropdown.Item icon={<PageIcon
style={{ color: 'green' }} />}>New File
</Dropdown.Item>
<Dropdown.Item icon={<FolderFillIcon
style={{ color: 'violet' }} />}>
New File with Current Profile
</Dropdown.Item>
<Dropdown.Item icon={<FileDownloadIcon
style={{ color: 'orange' }} />}>
Download As...
</Dropdown.Item>
<Dropdown.Item icon={<DetailIcon
style={{ color: 'yellow' }} />}>Export PDF
</Dropdown.Item>
<Dropdown.Item icon={<FileUploadIcon
style={{ color: 'blue' }} />}>File Upload
</Dropdown.Item>
<Dropdown.Item icon={<DetailIcon
style={{ color: 'pink' }} />}>Exit
</Dropdown.Item>
</Dropdown>
</div>
)
}
export default App;
Output:
Reference: https://rsuitejs.com/components/dropdown/#dropdown-with-icon
Similar Reads
React Suite Button Icon React Suite Button Icon allows to use of an Icon as a Button. The Button component is used to fire an action when the user clicks the button. React Suite Button IconButton Icon component is used when we want to use an icon as a button, It has an icon property that is used to specify the icon of the
3 min read
React Suite Dropdown Dropdown with Icon React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The dropdown component allows the user to provide navigation that uses a select picker if you want to select a value. Dropdown with Icon will help us to add an
3 min read
React Suite Nav With Icon Pre-requisite: React Suite Introduction A React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll
3 min read
React Suite Icon Size A React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React Suite Icons sizes. Rea
2 min read
React Suite Icon Color A React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React Suite Icons colors. We
2 min read
React Suite Icon Flip and rotate A React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React suite Icon Flip and Ro
3 min read
React Suite Icon Animating A React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React Suite Icon Animating.
2 min read
React Suite Icon <Icon> Props React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. There is a lot of data that gets rendered on a web page. Sometimes we require to represent data using icons. This is when the Icon component allows the user to a
3 min read
React Suite Icon Props A React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React Suite Icon Props. Reac
3 min read
React Suite Custom SVG Icon Extension React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React Suite Custom SVG Icon Ex
4 min read