Open In App

React Desktop macOS ToolbarNav Component

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:



ToolbarNavItem Props:

Creating React Application And Installing Module:



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.




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


Article Tags :