Friday, November 1, 2024
Google search engine
HomeLanguagesReact Suite Dropdown Dropdown with Icon

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 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' }}>neveropen</h1>
            <h3>React Suite Dropdown Dropdown with Icon</h3>
            <Dropdown title="neveropen" 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' }}>
                neveropen
            </h1>
            <h3>React Suite Dropdown  with Icon</h3>
              
            <Dropdown title="neveropen"
                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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments