Web development basic and advance tutorial, php basic tutorial, laravel basic tutorial, React Native tutorial

Saturday, August 28, 2021

How To Integrate Bootstrap/HTML Template In ReactJS

0 comments

 

How To Integrate Bootstrap/HTML Template In ReactJS

 Introduction

 In this article, we will explain how to integrate HTML template in a React.js project.

 Prerequisites

We should have the basic knowledge of React.js

  • Visual Studio Code IDE should be installed on your system.
  • Bootstrap need to install and node js need to install.

Let's first download a Bootstrap template. You can download a free template from the following Link. I am going to use sb Admin Bootstrap template.

To create a new React.js project, open the command prompt and enter the following command. 

npx create-react-app fallenloves

Open the newly created project in Visual Studio Code and install Bootstrap in this project by using the following command.

npm install --save bootstrap   

Now, open the index.js file and add import Bootstrap.

  1. import 'bootstrap/dist/css/bootstrap.min.css';  

 

After finish install import then create new folder assets, and copy css, js and img folder from the template



Now open index.html file and add reference of css and js. Add the following code in index.html.

  1. <!DOCTYPE html>  
  2. <html lang="en">  
  3.   <head>  
  4.     <meta charset="utf-8" />  
  5.     <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />  
  6.     <meta name="viewport" content="width=device-width, initial-scale=1" />  
  7.     <meta name="theme-color" content="#000000" />  
  8.     <meta  
  9.       name="description"  
  10.       content="Web site created using create-react-app"  
  11.     />  
  12.     <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />  
  13.     <link href="./assets/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">  
  14.     <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">  
  15.     <link href="./assets/css/sb-admin-2.min.css" rel="stylesheet">  
  16.     <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />  
  17.     <title>React App</title>  
  18.   </head>  
  19.   <body>  
  20.     <noscript>You need to enable JavaScript to run this app.</noscript>  
  21.     <div id="root"></div>  
  22.     <script src="./assets//vendor/jquery/jquery.min.js"></script>  
  23.     <script src="./assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>  
  24.     <script src="./assets/vendor/jquery-easing/jquery.easing.min.js"></script>  
  25.     <script src="./assets/js/sb-admin-2.min.js"></script>  
  26.     <script src="./assets/vendor/chart.js/Chart.min.js"></script>  
  27.     <script src="./assets/js/demo/chart-area-demo.js"></script>  
  28.     <script src="./assets/js/demo/chart-pie-demo.js"></script>  
  29.   </body>  
  30. </html>   

Now, go to the src folder, create a new folder named 'Layout 'and inside this folder, add 4 new components, 

  • Footer.js
  • Header.js
  • Layout.js
  • Leftside.js 

Now open Header.js component and add the following code.

 

Now open Header.js component and add the following code.

  1. import React, { Component } from 'react'  
  2.   
  3. export class Header extends Component {  
  4.     render() {  
  5.         return (  
  6.             <div>  
  7.                 <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">  
  8.   
  9.          
  10. <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">  
  11.   <i class="fa fa-bars"></i>  
  12. </button>  
  13.   
  14.   
  15. <form class="d-none d-sm-inline-block form-inline mr-auto ml-md-3 my-2 my-md-0 mw-100 navbar-search">  
  16.   <div class="input-group">  
  17.     <input type="text" class="form-control bg-light border-0 small" placeholder="Search for..." aria-label="Search" aria-describedby="basic-addon2"/>  
  18.     <div class="input-group-append">  
  19.       <button class="btn btn-primary" type="button">  
  20.         <i class="fas fa-search fa-sm"></i>  
  21.       </button>  
  22.     </div>  
  23.   </div>  
  24. </form>  
  25.   
  26.   
  27. <ul class="navbar-nav ml-auto">  
  28.   
  29.   
  30.   <li class="nav-item dropdown no-arrow d-sm-none">  
  31.     <a class="nav-link dropdown-toggle" href="#" id="searchDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">  
  32.       <i class="fas fa-search fa-fw"></i>  
  33.     </a>  
  34.    
  35.     <div class="dropdown-menu dropdown-menu-right p-3 shadow animated--grow-in" aria-labelledby="searchDropdown">  
  36.       <form class="form-inline mr-auto w-100 navbar-search">  
  37.         <div class="input-group">  
  38.           <input type="text" class="form-control bg-light border-0 small" placeholder="Search for..." aria-label="Search" aria-describedby="basic-addon2"/>  
  39.           <div class="input-group-append">  
  40.             <button class="btn btn-primary" type="button">  
  41.               <i class="fas fa-search fa-sm"></i>  
  42.             </button>  
  43.           </div>  
  44.         </div>  
  45.       </form>  
  46.     </div>  
  47.   </li>  
  48.   
  49.    
  50.   <li class="nav-item dropdown no-arrow mx-1">  
  51.     <a class="nav-link dropdown-toggle" href="#" id="alertsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">  
  52.       <i class="fas fa-bell fa-fw"></i>  
  53.       <span class="badge badge-danger badge-counter">3+</span>  
  54.     </a>  
  55.   
  56.     <div class="dropdown-list dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="alertsDropdown">  
  57.       <h6 class="dropdown-header">  
  58.         Alerts Center  
  59.       </h6>  
  60.       <a class="dropdown-item d-flex align-items-center" href="#">  
  61.         <div class="mr-3">  
  62.           <div class="icon-circle bg-primary">  
  63.             <i class="fas fa-file-alt text-white"></i>  
  64.           </div>  
  65.         </div>  
  66.         <div>  
  67.           <div class="small text-gray-500">December 12, 2019</div>  
  68.           <span class="font-weight-bold">A new monthly report is ready to download!</span>  
  69.         </div>  
  70.       </a>  
  71.       <a class="dropdown-item d-flex align-items-center" href="#">  
  72.         <div class="mr-3">  
  73.           <div class="icon-circle bg-success">  
  74.             <i class="fas fa-donate text-white"></i>  
  75.           </div>  
  76.         </div>  
  77.         <div>  
  78.           <div class="small text-gray-500">December 7, 2019</div>  
  79.           $290.29 has been deposited into your account!  
  80.         </div>  
  81.       </a>  
  82.       <a class="dropdown-item d-flex align-items-center" href="#">  
  83.         <div class="mr-3">  
  84.           <div class="icon-circle bg-warning">  
  85.             <i class="fas fa-exclamation-triangle text-white"></i>  
  86.           </div>  
  87.         </div>  
  88.         <div>  
  89.           <div class="small text-gray-500">December 2, 2019</div>  
  90.           Spending Alert: We've noticed unusually high spending for your account.  
  91.         </div>  
  92.       </a>  
  93.       <a class="dropdown-item text-center small text-gray-500" href="#">Show All Alerts</a>  
  94.     </div>  
  95.   </li>  
  96.   
  97.   
  98.   <li class="nav-item dropdown no-arrow mx-1">  
  99.     <a class="nav-link dropdown-toggle" href="#" id="messagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">  
  100.       <i class="fas fa-envelope fa-fw"></i>  
  101.     
  102.       <span class="badge badge-danger badge-counter">7</span>  
  103.     </a>  
  104.   
  105.     <div class="dropdown-list dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="messagesDropdown">  
  106.       <h6 class="dropdown-header">  
  107.         Message Center  
  108.       </h6>  
  109.       <a class="dropdown-item d-flex align-items-center" href="#">  
  110.         <div class="dropdown-list-image mr-3">  
  111.           <img class="rounded-circle" src="https://source.unsplash.com/fn_BT9fwg_E/60x60" alt=""/>  
  112.           <div class="status-indicator bg-success"></div>  
  113.         </div>  
  114.         <div class="font-weight-bold">  
  115.           <div class="text-truncate">Hi there! I am wondering if you can help me with a problem I've been having.</div>  
  116.           <div class="small text-gray-500">Emily Fowler · 58m</div>  
  117.         </div>  
  118.       </a>  
  119.       <a class="dropdown-item d-flex align-items-center" href="#">  
  120.         <div class="dropdown-list-image mr-3">  
  121.           <img class="rounded-circle" src="https://source.unsplash.com/AU4VPcFN4LE/60x60" alt=""/>  
  122.           <div class="status-indicator"></div>  
  123.         </div>  
  124.         <div>  
  125.           <div class="text-truncate">I have the photos that you ordered last month, how would you like them sent to you?</div>  
  126.           <div class="small text-gray-500">Jae Chun · 1d</div>  
  127.         </div>  
  128.       </a>  
  129.       <a class="dropdown-item d-flex align-items-center" href="#">  
  130.         <div class="dropdown-list-image mr-3">  
  131.           <img class="rounded-circle" src="https://source.unsplash.com/CS2uCrpNzJY/60x60" alt=""/>  
  132.           <div class="status-indicator bg-warning"></div>  
  133.         </div>  
  134.         <div>  
  135.           <div class="text-truncate">Last month's report looks great, I am very happy with the progress so far, keep up the good work!</div>  
  136.           <div class="small text-gray-500">Morgan Alvarez · 2d</div>  
  137.         </div>  
  138.       </a>  
  139.       <a class="dropdown-item d-flex align-items-center" href="#">  
  140.         <div class="dropdown-list-image mr-3">  
  141.           <img class="rounded-circle" src="https://source.unsplash.com/Mv9hjnEUHR4/60x60" alt=""/>  
  142.           <div class="status-indicator bg-success"></div>  
  143.         </div>  
  144.         <div>  
  145.           <div class="text-truncate">Am I a good boy? The reason I ask is because someone told me that people say this to all dogs, even if they aren't good...</div>  
  146.           <div class="small text-gray-500">Chicken the Dog · 2w</div>  
  147.         </div>  
  148.       </a>  
  149.       <a class="dropdown-item text-center small text-gray-500" href="#">Read More Messages</a>  
  150.     </div>  
  151.   </li>  
  152.   
  153.   <div class="topbar-divider d-none d-sm-block"></div>  
  154.   
  155.   
  156.   <li class="nav-item dropdown no-arrow">  
  157.     <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">  
  158.       <span class="mr-2 d-none d-lg-inline text-gray-600 small">Valerie Luna</span>  
  159.       <img class="img-profile rounded-circle" src="https://source.unsplash.com/QAB-WJcbgJk/60x60"/>  
  160.     </a>  
  161.   
  162.     <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="userDropdown">  
  163.       <a class="dropdown-item" href="#">  
  164.         <i class="fas fa-user fa-sm fa-fw mr-2 text-gray-400"></i>  
  165.         Profile  
  166.       </a>  
  167.       <a class="dropdown-item" href="#">  
  168.         <i class="fas fa-cogs fa-sm fa-fw mr-2 text-gray-400"></i>  
  169.         Settings  
  170.       </a>  
  171.       <a class="dropdown-item" href="#">  
  172.         <i class="fas fa-list fa-sm fa-fw mr-2 text-gray-400"></i>  
  173.         Activity Log  
  174.       </a>  
  175.       <div class="dropdown-divider"></div>  
  176.       <a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">  
  177.         <i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-gray-400"></i>  
  178.         Logout  
  179.       </a>  
  180.     </div>  
  181.   </li>  
  182.   
  183. </ul>  
  184.   
  185. </nav>  
  186.             </div>  
  187.         )  
  188.     }  
  189. }  
  190.   
  191. export default Header  

Now open Leftside.js component and add the following code.

  1. import React, { Component } from 'react'  
  2. import { Link } from 'react-router-dom';  
  3. export class Leftside extends Component {  
  4.     render() {  
  5.         return (  
  6.             <div>  
  7.                 <ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">  
  8.                     <a class="sidebar-brand d-flex align-items-center justify-content-center" href="index.html">  
  9.                         <div class="sidebar-brand-text mx-3">React Routing </div>  
  10.                     </a>  
  11.   
  12.                     <hr class="sidebar-divider my-0" />  
  13.   
  14.                     <li class="nav-item active">  
  15.                         <a class="nav-link" href="index.html">  
  16.                             <i class="fas fa-fw fa-tachometer-alt"></i>  
  17.                             <span>Dashboard</span></a>  
  18.                     </li>  
  19.                     <hr class="sidebar-divider" />  
  20.                     <div class="sidebar-heading">  
  21.                         Interface  
  22.                     </div>  
  23.                     <li class="nav-item">  
  24.                         <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">  
  25.                             <i class="fas fa-fw fa-cog"></i>  
  26.                             <span>Components</span>  
  27.                         </a>  
  28.                         <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionSidebar">  
  29.                             <div class="bg-white py-2 collapse-inner rounded">  
  30.                                 <h6 class="collapse-header">Custom Components:</h6>  
  31.                                 <Link class="collapse-item" to="/home">Buttons</Link>  
  32.                                 <Link class="collapse-item" to="/button">Chart</Link>  
  33.                             </div>  
  34.                         </div>  
  35.                     </li>  
  36.                     <li class="nav-item">  
  37.                         <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseUtilities" aria-expanded="true" aria-controls="collapseUtilities">  
  38.                             <i class="fas fa-fw fa-wrench"></i>  
  39.                             <span>Utilities</span>  
  40.                         </a>  
  41.                         <div id="collapseUtilities" class="collapse" aria-labelledby="headingUtilities" data-parent="#accordionSidebar">  
  42.                             <div class="bg-white py-2 collapse-inner rounded">  
  43.                                 <h6 class="collapse-header">Custom Utilities:</h6>  
  44.                                 <a class="collapse-item" href="utilities-color.html">Colors</a>  
  45.                                 <a class="collapse-item" href="utilities-border.html">Borders</a>  
  46.                                 <a class="collapse-item" href="utilities-animation.html">Animations</a>  
  47.                                 <a class="collapse-item" href="utilities-other.html">Other</a>  
  48.                             </div>  
  49.                         </div>  
  50.                     </li>  
  51.                     <hr class="sidebar-divider" />  
  52.   
  53.                     <div class="sidebar-heading">  
  54.                         Addons  
  55. </div>  
  56.                     <li class="nav-item">  
  57.                         <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapsePages" aria-expanded="true" aria-controls="collapsePages">  
  58.                             <i class="fas fa-fw fa-folder"></i>  
  59.                             <span>Pages</span>  
  60.                         </a>  
  61.                         <div id="collapsePages" class="collapse" aria-labelledby="headingPages" data-parent="#accordionSidebar">  
  62.                             <div class="bg-white py-2 collapse-inner rounded">  
  63.                                 <h6 class="collapse-header">Login Screens:</h6>  
  64.                                 <a class="collapse-item" href="login.html">Login</a>  
  65.                                 <a class="collapse-item" href="register.html">Register</a>  
  66.                                 <a class="collapse-item" href="forgot-password.html">Forgot Password</a>  
  67.                                 <div class="collapse-divider"></div>  
  68.                                 <h6 class="collapse-header">Other Pages:</h6>  
  69.                                 <a class="collapse-item" href="404.html">404 Page</a>  
  70.                                 <a class="collapse-item" href="blank.html">Blank Page</a>  
  71.                             </div>  
  72.                         </div>  
  73.                     </li>  
  74.                     <li class="nav-item">  
  75.                         <Link class="nav-link" to="/color"> <i class="fas fa-fw fa-chart-area"></i>Colors</Link>  
  76.                         {/* <a class="nav-link" href="charts.html"> 
  77.                             <i class="fas fa-fw fa-chart-area"></i> 
  78.                             <span>Charts</span></a> */}  
  79.                     </li>  
  80.                     <li class="nav-item">  
  81.                         <Link class="nav-link" to="/table">  <i class="fas fa-fw fa-table"></i>Tables</Link>  
  82.                         {/* <a class="nav-link" href="tables.html"> 
  83.                             <i class="fas fa-fw fa-table"></i> 
  84.                             <span>Tables</span></a> */}  
  85.                     </li>  
  86.                     <hr class="sidebar-divider d-none d-md-block" />  
  87.                     <div class="text-center d-none d-md-inline">  
  88.                         <button class="rounded-circle border-0" id="sidebarToggle"></button>  
  89.                     </div>  
  90.   
  91.                 </ul>  
  92.             </div>  
  93.         )  
  94.     }  
  95. }  
  96.   
  97. export default Leftside  

Now open the Footer.js component and add the following code.

  1. import React, { Component } from 'react'  
  2.   
  3. export class Footer extends Component {  
  4.     render() {  
  5.         return (  
  6.             <div>  
  7.                  <footer class="sticky-footer bg-white">  
  8.         <div class="container my-auto">  
  9.           <div class="copyright text-center my-auto">  
  10.             <span>Copyright © Your Website 2019</span>  
  11.           </div>  
  12.         </div>  
  13.       </footer>  
  14.             </div>  
  15.         )  
  16.     }  
  17. }  
  18.   
  19. export default Footer  

Now open Layout.js component and  import Header, Footer and Leftside component, add the following code in this component.

  1. import React, { Component, Suspense } from 'react';  
  2. import Leftside from './Leftside';  
  3. import Header from './Header'  
  4. import Footer from './Footer'  
  5. import Home from '../Home'  
  6. import {  
  7.     Route, Switch, Redirect  
  8. } from 'react-router-dom';  
  9. export class Layout extends Component {  
  10.     loading = () => <div className="animated fadeIn pt-1 text-center">Loading...</div>  
  11.     render() {  
  12.         return (  
  13.             <div>  
  14.                 <div id="wrapper">  
  15.                     <Leftside></Leftside>  
  16.                     <div id="content-wrapper" class="d-flex flex-column">  
  17.                         <div id="content">  
  18.                             <Header />  
  19.                             <Home/>  
  20.                         </div>  
  21.                         <Footer />  
  22.                     </div>  
  23.                 </div>  
  24.             </div>  
  25.         )  
  26.     }  
  27. }  
  28.   
  29. export default Layout  

 Now open app.js file and following code 

  1. import React from 'react';  
  2. import logo from './logo.svg';  
  3. import './App.css';  
  4. import Layout  from './Layout/Layout'  
  5. import Login from "./Login";  
  6. import { HashRouter, Route, Switch } from 'react-router-dom';  
  7. function App() {  
  8.   return (  
  9.      <div className="App">  
  10.       <Layout/>   
  11.      </div>  
  12.   );  
  13. }  
  14.   
  15. export default App;  

Now run the project by using 'npm start' and check the result.

 





No comments:

Post a Comment