React Desktop is a popular library to bring the native desktop experience to the web. This library provides macOS and Windows OS components. NavPane Component is used to allow the users to easily navigate between elements as it is a Navigation Pane. We can use the following approach in ReactJS to use the React Desktop Windows NavPane Component.
NavPane Props:
- canPaneToggle: It is used to set whether the pane can be compacted.
- color: It is used to set the text color.
- defaultIsPaneExpanded: It is used to set whether the pane is expanded by default.
- onPaneToggle: It is a callback function that is triggered when the pane is compacted or expanded.
- paneCompactedLength: It is used to set the pane length when it is compacted.
- paneExpandedLength: It is used to set the pane length when it is expanded.
- theme: It is used to set the UI theme and this theme is then used by this component and its children elements.
NavPaneItem Props:
- background: It is used to set the background color.
- color: It is used to set the text color.
- horizontalAlignment: It is used to set the horizontal alignment of the content of the component.
- icon: It is used to set the item icon element.
- margin: It is used to set the outer margin of the component.
- onSelect: It is a callback function that is triggered when an item is selected.
- padding: It is used to set the padding inside a component.
- push: It is used to display a push animation when the button is pressed.
- selected: It is used to indicate whether the item is selected or not.
- title: It is used to set the title of the element.
- theme: It is used to set the UI theme and this theme is then used by this component and its children elements.
- verticalAlignment: It is used to set the vertical alignment of the content of the component.
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.
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 from 'react' import { NavPane, NavPaneItem } from 'react-desktop/windows' ; export default function App() { return ( <div style={{ display: 'block' , width: 700, paddingLeft: 30 }}> <h4>React Desktop Windows NavPane Component</h4> <NavPane push> <NavPaneItem title= "Item One" push > NavItem One </NavPaneItem> <NavPaneItem title= "Item Two" push> NavItem Two </NavPaneItem> <NavPaneItem title= "Item Three" push> NavItem Three </NavPaneItem> </NavPane> </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: http://reactdesktop.js.org/docs/windows/nav-pane