Navbar
import React, { useState } from 'react';
import {
Collapse,
Navbar,
NavbarToggler,
NavbarBrand,
Nav,
NavItem,
NavLink,
UncontrolledDropdown,
DropdownToggle,
DropdownMenu,
DropdownItem,
NavbarText
} from 'reactstrap';
const Example = (props) => {
const [isOpen, setIsOpen] = useState(false);
const toggle = () => setIsOpen(!isOpen);
return (
<div>
<Navbar color="light" light expand="md">
<NavbarBrand href="/">reactstrap</NavbarBrand>
<NavbarToggler onClick={toggle} />
<Collapse isOpen={isOpen} navbar>
<Nav className="mr-auto" navbar>
<NavItem>
<NavLink href="/components/">Components</NavLink>
</NavItem>
<NavItem>
<NavLink href="https://github.com/reactstrap/reactstrap">GitHub</NavLink>
</NavItem>
<UncontrolledDropdown nav inNavbar>
<DropdownToggle nav caret>
Options
</DropdownToggle>
<DropdownMenu right>
<DropdownItem>
Option 1
</DropdownItem>
<DropdownItem>
Option 2
</DropdownItem>
<DropdownItem divider />
<DropdownItem>
Reset
</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
</Nav>
<NavbarText>Simple Text</NavbarText>
</Collapse>
</Navbar>
</div>
);
}
export default Example;
Navbar Properties
See also Navs for additional components and PropTypes.
Navbar.propTypes = {
light: PropTypes.bool,
dark: PropTypes.bool,
fixed: PropTypes.string,
color: PropTypes.string,
role: PropTypes.string,
expand: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
// pass in custom element to use
}
NavbarBrand Properties
NavbarBrand.propTypes = {
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
// pass in custom element to use
}
NavbarText Properties
NavbarText.propTypes = {
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
// pass in custom element to use
}
NavbarToggler
Place the NavbarToggler
after NavbarBrand
to have it appear on the right (typical setup). Reverse the order to have it appear on the left
import React, { useState } from 'react';
import { Collapse, Navbar, NavbarToggler, NavbarBrand, Nav, NavItem, NavLink } from 'reactstrap';
const Example = (props) => {
const [collapsed, setCollapsed] = useState(true);
const toggleNavbar = () => setCollapsed(!collapsed);
return (
<div>
<Navbar color="faded" light>
<NavbarBrand href="/" className="mr-auto">reactstrap</NavbarBrand>
<NavbarToggler onClick={toggleNavbar} className="mr-2" />
<Collapse isOpen={!collapsed} navbar>
<Nav navbar>
<NavItem>
<NavLink href="/components/">Components</NavLink>
</NavItem>
<NavItem>
<NavLink href="https://github.com/reactstrap/reactstrap">GitHub</NavLink>
</NavItem>
</Nav>
</Collapse>
</Navbar>
</div>
);
}
export default Example;
NavbarToggler Properties
NavbarToggler.propTypes = {
type: PropTypes.string,
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
// pass in custom element to use
}