|
1 |
| -# react-side-navbar |
| 1 | +Side Navbar is an additional navigation component that provides extensive support and a clear way for navigating through complex websites with hundreds of links and subpages. |
| 2 | + |
| 3 | +Check out [React Side Navbar Documentation](https://mdbootstrap.com/docs/react/extended/side-navbar/) for detailed instructions & even more examples. |
| 4 | + |
| 5 | +## Basic example |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +```js |
| 10 | +import React, { useState } from 'react'; |
| 11 | +import { |
| 12 | + MDBContainer, |
| 13 | + MDBNavbar, |
| 14 | + MDBNavbarBrand, |
| 15 | + MDBNavbarToggler, |
| 16 | + MDBIcon, |
| 17 | + MDBNavbarNav, |
| 18 | + MDBNavbarItem, |
| 19 | + MDBNavbarLink, |
| 20 | + MDBDropdown, |
| 21 | + MDBDropdownToggle, |
| 22 | + MDBDropdownMenu, |
| 23 | + MDBDropdownItem, |
| 24 | + MDBDropdownLink, |
| 25 | + MDBCollapse, |
| 26 | + MDBRipple, |
| 27 | + MDBBadge, |
| 28 | + MDBInput, |
| 29 | + MDBListGroup, |
| 30 | + MDBListGroupItem |
| 31 | +} from 'mdb-react-ui-kit'; |
| 32 | + |
| 33 | +export default function Basic() { |
| 34 | + const [showShow, setShowShow] = useState(false); |
| 35 | + |
| 36 | + const toggleShow = () => setShowShow(!showShow); |
| 37 | + |
| 38 | + return ( |
| 39 | + <> |
| 40 | + <link |
| 41 | + href="https://use.fontawesome.com/releases/v5.15.1/css/all.css" |
| 42 | + rel="stylesheet" |
| 43 | + /> |
| 44 | + <MDBCollapse show={showShow} tag="nav" className="d-lg-block bg-white sidebar"> |
| 45 | + <div className="position-sticky"> |
| 46 | + <MDBListGroup flush className="mx-3 mt-4"> |
| 47 | + |
| 48 | + <MDBRipple rippleTag='span'> |
| 49 | + <MDBListGroupItem tag='a' href='#' action className='border-0 border-bottom rounded rounded'> |
| 50 | + <MDBIcon fas icon="tachometer-alt me-3" /> |
| 51 | + Main Dashboard |
| 52 | + </MDBListGroupItem> |
| 53 | + </MDBRipple> |
| 54 | + |
| 55 | + <MDBRipple rippleTag='span'> |
| 56 | + <MDBListGroupItem tag='a' href='#' action className='border-0 border-bottom rounded' active aria-current='true'> |
| 57 | + <MDBIcon fas icon="chart-area me-3" /> |
| 58 | + Website traffic |
| 59 | + </MDBListGroupItem> |
| 60 | + </MDBRipple> |
| 61 | + |
| 62 | + <MDBRipple rippleTag='span'> |
| 63 | + <MDBListGroupItem tag='a' href='#' action className='border-0 border-bottom rounded'> |
| 64 | + <MDBIcon fas icon="lock me-3" /> |
| 65 | + Password |
| 66 | + </MDBListGroupItem> |
| 67 | + </MDBRipple> |
| 68 | + |
| 69 | + <MDBRipple rippleTag='span'> |
| 70 | + <MDBListGroupItem tag='a' href='#' action className='border-0 border-bottom rounded'> |
| 71 | + <MDBIcon fas icon="chart-line me-3" /> |
| 72 | + Analitics |
| 73 | + </MDBListGroupItem> |
| 74 | + </MDBRipple> |
| 75 | + |
| 76 | + <MDBRipple rippleTag='span'> |
| 77 | + <MDBListGroupItem tag='a' href='#' action className='border-0 border-bottom rounded'> |
| 78 | + <MDBIcon fas icon="chart-pie me-3" /> |
| 79 | + SEO |
| 80 | + </MDBListGroupItem> |
| 81 | + </MDBRipple> |
| 82 | + |
| 83 | + <MDBRipple rippleTag='span'> |
| 84 | + <MDBListGroupItem tag='a' href='#' action className='border-0 border-bottom rounded'> |
| 85 | + <MDBIcon far icon="chart-bar me-3" /> |
| 86 | + Orders |
| 87 | + </MDBListGroupItem> |
| 88 | + </MDBRipple> |
| 89 | + |
| 90 | + <MDBRipple rippleTag='span'> |
| 91 | + <MDBListGroupItem tag='a' href='#' action className='border-0 border-bottom rounded'> |
| 92 | + <MDBIcon fas icon="globe me-3" /> |
| 93 | + International |
| 94 | + </MDBListGroupItem> |
| 95 | + </MDBRipple> |
| 96 | + |
| 97 | + <MDBRipple rippleTag='span'> |
| 98 | + <MDBListGroupItem tag='a' href='#' action className='border-0 border-bottom rounded'> |
| 99 | + <MDBIcon fas icon="building me-3" /> |
| 100 | + Partners |
| 101 | + </MDBListGroupItem> |
| 102 | + </MDBRipple> |
| 103 | + |
| 104 | + <MDBRipple rippleTag='span'> |
| 105 | + <MDBListGroupItem tag='a' href='#' action className='border-0 border-bottom rounded'> |
| 106 | + <MDBIcon fas icon="calendar me-3" /> |
| 107 | + Calendar |
| 108 | + </MDBListGroupItem> |
| 109 | + </MDBRipple> |
| 110 | + |
| 111 | + <MDBRipple rippleTag='span'> |
| 112 | + <MDBListGroupItem tag='a' href='#' action className='border-0 border-bottom rounded'> |
| 113 | + <MDBIcon fas icon="users me-3" /> |
| 114 | + User |
| 115 | + </MDBListGroupItem> |
| 116 | + </MDBRipple> |
| 117 | + |
| 118 | + <MDBRipple rippleTag='span'> |
| 119 | + <MDBListGroupItem tag='a' href='#' action className='border-0 rounded'> |
| 120 | + <MDBIcon fas icon="money-bill me-3" /> |
| 121 | + Sales |
| 122 | + </MDBListGroupItem> |
| 123 | + </MDBRipple> |
| 124 | + </MDBListGroup> |
| 125 | + </div> |
| 126 | + </MDBCollapse> |
| 127 | + |
| 128 | + <MDBNavbar expand='lg' light bgColor='light'> |
| 129 | + <MDBContainer fluid> |
| 130 | + <MDBNavbarNav className="d-flex flex-row align-items-center w-auto"> |
| 131 | + <MDBNavbarToggler |
| 132 | + type='button' |
| 133 | + aria-label='Toggle navigation' |
| 134 | + onClick={toggleShow} |
| 135 | + > |
| 136 | + <MDBIcon icon='bars' fas /> |
| 137 | + </MDBNavbarToggler> |
| 138 | + <MDBNavbarBrand href='#'> |
| 139 | + <img |
| 140 | + src='https://mdbootstrap.com/img/logo/mdb-transaprent-noshadows.webp' |
| 141 | + height='30' |
| 142 | + alt='' |
| 143 | + loading='lazy' |
| 144 | + /> |
| 145 | + </MDBNavbarBrand> |
| 146 | + |
| 147 | + <MDBCollapse navbar> |
| 148 | + <MDBNavbarItem className="d-flex align-items-center"> |
| 149 | + <MDBInput label='Search (ctrl + "/" to focus)' id='form1' type='text' /> |
| 150 | + <MDBIcon fas icon="search mx-2" /> |
| 151 | + </MDBNavbarItem> |
| 152 | + </MDBCollapse> |
| 153 | + |
| 154 | + |
| 155 | + </MDBNavbarNav> |
| 156 | + <MDBNavbarNav className="d-flex flex-row justify-content-end w-auto"> |
| 157 | + |
| 158 | + <MDBNavbarItem className='me-3 me-lg-0 d-flex align-items-center'> |
| 159 | + <MDBDropdown> |
| 160 | + |
| 161 | + <MDBDropdownToggle tag="a" href="#!" className="hidden-arrow nav-link"> |
| 162 | + <MDBIcon fas icon="bell" /> |
| 163 | + <MDBBadge color='danger' notification pill> |
| 164 | + 1 |
| 165 | + </MDBBadge> |
| 166 | + </MDBDropdownToggle> |
| 167 | + |
| 168 | + <MDBDropdownMenu> |
| 169 | + <MDBDropdownItem> |
| 170 | + <MDBDropdownLink href="#">Some news</MDBDropdownLink> |
| 171 | + </MDBDropdownItem> |
| 172 | + <MDBDropdownItem> |
| 173 | + <MDBDropdownLink href="#">Another news</MDBDropdownLink> |
| 174 | + </MDBDropdownItem> |
| 175 | + <MDBDropdownItem> |
| 176 | + <MDBDropdownLink href="#">Something else here</MDBDropdownLink> |
| 177 | + </MDBDropdownItem> |
| 178 | + </MDBDropdownMenu> |
| 179 | + </MDBDropdown> |
| 180 | + </MDBNavbarItem> |
| 181 | + |
| 182 | + |
| 183 | + <MDBNavbarItem className='me-3 me-lg-0'> |
| 184 | + <MDBNavbarLink href='#'> |
| 185 | + <MDBIcon fas icon='fill-drip' /> |
| 186 | + </MDBNavbarLink> |
| 187 | + </MDBNavbarItem> |
| 188 | + <MDBNavbarItem className='me-3 me-lg-0'> |
| 189 | + <MDBNavbarLink href='#'> |
| 190 | + <MDBIcon fab icon='github' /> |
| 191 | + </MDBNavbarLink> |
| 192 | + </MDBNavbarItem> |
| 193 | + |
| 194 | + <MDBNavbarItem className='me-3 me-lg-0 d-flex align-items-center'> |
| 195 | + <MDBDropdown> |
| 196 | + |
| 197 | + <MDBDropdownToggle tag="a" href="#!" className="hidden-arrow nav-link"> |
| 198 | + <img src="https://mdbootstrap.com/img/Photos/Avatars/img (31).jpg" className="rounded-circle" height="22" alt="" loading="lazy" /> |
| 199 | + </MDBDropdownToggle> |
| 200 | + |
| 201 | + <MDBDropdownMenu> |
| 202 | + <MDBDropdownItem> |
| 203 | + <MDBDropdownLink href="#">My profile</MDBDropdownLink> |
| 204 | + </MDBDropdownItem> |
| 205 | + <MDBDropdownItem> |
| 206 | + <MDBDropdownLink href="#">Settings</MDBDropdownLink> |
| 207 | + </MDBDropdownItem> |
| 208 | + <MDBDropdownItem> |
| 209 | + <MDBDropdownLink href="#">Logout</MDBDropdownLink> |
| 210 | + </MDBDropdownItem> |
| 211 | + </MDBDropdownMenu> |
| 212 | + </MDBDropdown> |
| 213 | + </MDBNavbarItem> |
| 214 | + </MDBNavbarNav> |
| 215 | + |
| 216 | + </MDBContainer> |
| 217 | + </MDBNavbar> |
| 218 | + </> |
| 219 | + ); |
| 220 | +} |
| 221 | +``` |
| 222 | + |
| 223 | +```css |
| 224 | +body { |
| 225 | + background-color: #fbfbfb; |
| 226 | +} |
| 227 | + |
| 228 | +@media (min-width: 992px) { |
| 229 | + .sidebar { |
| 230 | + height: unset!important; |
| 231 | + } |
| 232 | +} |
| 233 | + |
| 234 | +/* Sidebar */ |
| 235 | +.sidebar { |
| 236 | + position: fixed; |
| 237 | + top: 0; |
| 238 | + bottom: 0; |
| 239 | + left: 0; |
| 240 | + padding: 58px 0 0; |
| 241 | + /* Height of navbar */ |
| 242 | + box-shadow: 0 2px 5px 0 rgb(0 0 0 / 5%), 0 2px 10px 0 rgb(0 0 0 / 5%); |
| 243 | + width: 240px; |
| 244 | + /* z-index: 600; */ |
| 245 | +} |
| 246 | + |
| 247 | +.sidebar.show { |
| 248 | + height: 100vh; |
| 249 | +} |
| 250 | + |
| 251 | +@media (max-width: 992px) { |
| 252 | + .sidebar { |
| 253 | + width: 100%; |
| 254 | + } |
| 255 | +} |
| 256 | + |
| 257 | +.sidebar .active { |
| 258 | + border-radius: 5px; |
| 259 | + box-shadow: 0 2px 5px 0 rgb(0 0 0 / 16%), 0 2px 10px 0 rgb(0 0 0 / 12%); |
| 260 | +} |
| 261 | + |
| 262 | +.sidebar-sticky { |
| 263 | + position: relative; |
| 264 | + top: 0; |
| 265 | + height: calc(100vh - 48px); |
| 266 | + padding-top: 0.5rem; |
| 267 | + overflow-x: hidden; |
| 268 | + overflow-y: auto; |
| 269 | + /* Scrollable contents if viewport is shorter than content. */ |
| 270 | +} |
| 271 | +``` |
| 272 | + |
| 273 | +## How to use? |
| 274 | + |
| 275 | +1. Download MDB React - free UI KIT |
| 276 | + |
| 277 | +2. Choose your favourite customized component and click on the image |
| 278 | + |
| 279 | +3. Copy & paste the code into your MDB project |
| 280 | + |
| 281 | +[▶️ Subscribe to YouTube channel for web development tutorials & resources](https://www.youtube.com/MDBootstrap?sub_confirmation=1) |
| 282 | + |
| 283 | +## More examples |
| 284 | + |
| 285 | +[React Side Navbar Collapse: |
| 286 | +](https://mdbootstrap.com/docs/react/extended/side-navbar/#section-collapse) |
0 commit comments