Open In App

React Desktop macOS ToolbarNav Component

Improve
Improve
Like Article
Like
Save
Share
Report

React Desktop is a popular library to bring the native desktop experience to the web. This library provides macOS and Windows OS components. ToolbarNav Component is used to allow the users to add. We can use the following approach in ReactJS to use the React Desktop macOS ToolbarNav Component.

ToolbarNav Props:

  • height: It is used to set component height.
  • width: It is used to set component width.

ToolbarNavItem Props:

  • icon: It is used to set the icon element of the item.
  • onClick: It is a callback function that is triggered when the item is clicked.
  • selected: It is used to indicate whether the item is selected or not.
  • title: It is used to set the title for the item.

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 react-desktop

Project Structure: It will look like the following.

Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

App.js




import React, { useState } from 'react'
import { TitleBar, Toolbar, ToolbarNav, ToolbarNavItem } from 'react-desktop/macOs';
  
export default function App() {
  
  // Our State object
  const [currentSelection, setCurrentSelection] = useState(1)
  
  return (
    <div style={{
      display: 'block', width: 700, paddingLeft: 30
    }}>
      <h4>React-Desktop macOS ToolbarNav Component</h4>
      <TitleBar>
        <Toolbar>
          <ToolbarNav>
            <ToolbarNavItem
              title="1st ITEM"
              icon={(
                <svg x="0px" y="0px" width="25px" 
                  height="25px" viewBox="0 0 25 25">
                  <circle cx="12.5" cy="12.5" r="12.5" />
                </svg>
              )}
              selected={currentSelection === 1}
              onClick={() => setCurrentSelection({ selected: 1 })}
            />
            <ToolbarNavItem
              title="2nd ITEM"
              icon={ (
                <svg x="0px" y="0px" width="25px" 
                  height="23.8px" viewBox="0 0 25 23.8">
                  <polygon points="12.5,0 16.4,7.8 25,9.1 18.8,15.2 20.2,23.8 
                                   12.5,19.7 4.8,23.8 6.2,15.2 0,9.1 8.6,7.8 " />
                </svg>
              )}
              selected={currentSelection === 2}
              onClick={() => setCurrentSelection({ selected: 2 })}
            />
          </ToolbarNav>
        </Toolbar>
      </TitleBar>
    </div>
  );
}


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:

Reference: https://reactdesktop.js.org/docs/mac-os/toolbar-nav



Last Updated : 01 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads