Navbar Block
The Navbar Component is a fully customizable and accessible navigation bar built with React and TypeScript. It provides a complete website navigation interface with modern design patterns, flexible layout sections, and customizable content areas.
π Installationβ
npm install @nodeblocks/frontend-navbar-block@0.2.0
π Usageβ
import {Navbar} from '@nodeblocks/frontend-navbar-block';
- Basic Usage
- Advanced Usage
function BasicNavbar() { return ( <Navbar leftContent={<Navbar.Logo src="/img/icon-small.png" alt="Company Logo" style={{height: 32}} />} centerContent={ <div style={{display: 'flex', gap: 16}}> <Navbar.Link href="#home">Home</Navbar.Link> <Navbar.Link href="#about">About</Navbar.Link> <Navbar.Link href="#services">Services</Navbar.Link> <Navbar.Link href="#contact">Contact</Navbar.Link> </div> } rightContent={<Navbar.ButtonLink href="#login">Login</Navbar.ButtonLink>} sx={{backgroundColor: 'white', boxShadow: 1}} > <Navbar.Left /> <Navbar.Center /> <Navbar.Right /> </Navbar> ); }
function AdvancedNavbar() { return ( <div style={{ background: 'linear-gradient(135deg, #0f172a 0%, #1e293b 100%)', padding: '24px', borderRadius: 16, }} > <Navbar leftContent={null} centerContent={null} rightContent={null} sx={{ backgroundColor: 'rgba(255,255,255,0.03)', backdropFilter: 'blur(20px)', border: '1px solid rgba(255,255,255,0.08)', borderRadius: 3, py: 1.5, px: 3, }} > {({defaultBlocks, defaultBlockOrder}) => ({ blocks: { ...defaultBlocks, // π’ Brand Section left: { ...defaultBlocks.left, props: { ...defaultBlocks.left.props, sx: {alignItems: 'center'}, children: ( <div style={{display: 'flex', alignItems: 'center', gap: 10}}> <div style={{ width: 36, height: 36, background: 'linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%)', borderRadius: 10, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '1.1rem', boxShadow: '0 4px 12px rgba(59, 130, 246, 0.4)', }} > β‘ </div> <div> <div style={{ color: 'white', fontWeight: 700, fontSize: '1.1rem', lineHeight: 1.2, }} > Velocity </div> <div style={{ color: 'rgba(148,163,184,0.8)', fontSize: '0.7rem', fontWeight: 500, letterSpacing: 1, textTransform: 'uppercase', }} > Platform </div> </div> </div> ), }, }, // π§ Navigation Links center: { ...defaultBlocks.center, props: { ...defaultBlocks.center.props, sx: { alignItems: 'center', flexGrow: 1, justifyContent: 'center', }, children: ( <div style={{display: 'flex', gap: 8}}> {[ {label: 'Features', active: true}, {label: 'Pricing', active: false}, {label: 'Docs', active: false}, {label: 'Blog', active: false}, ].map(item => ( <a key={item.label} href={`#${item.label.toLowerCase()}`} style={{ color: item.active ? 'white' : 'rgba(148,163,184,0.9)', padding: '8px 16px', borderRadius: 8, textDecoration: 'none', fontWeight: 500, fontSize: '0.875rem', backgroundColor: item.active ? 'rgba(59,130,246,0.15)' : 'transparent', border: item.active ? '1px solid rgba(59,130,246,0.3)' : '1px solid transparent', transition: 'all 0.2s', }} > {item.label} </a> ))} </div> ), }, }, // π― Actions Section right: { ...defaultBlocks.right, props: { ...defaultBlocks.right.props, sx: {alignItems: 'center'}, children: ( <div style={{display: 'flex', alignItems: 'center', gap: 12}}> <a href="#signin" style={{ color: 'rgba(148,163,184,0.9)', textDecoration: 'none', fontWeight: 500, fontSize: '0.875rem', padding: '8px 12px', transition: 'color 0.2s', }} > Sign in </a> <a href="#start" style={{ background: 'linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%)', color: 'white', textDecoration: 'none', fontWeight: 600, fontSize: '0.875rem', padding: '10px 20px', borderRadius: 10, boxShadow: '0 4px 16px rgba(59, 130, 246, 0.35)', transition: 'all 0.2s', }} > Get Started β </a> </div> ), }, }, }, blockOrder: defaultBlockOrder, })} </Navbar> </div> ); }
π§ Props Referenceβ
Main Component Propsβ
| Prop | Type | Default | Description |
|---|---|---|---|
leftContent | ReactNode | Required | Content to display in the left section of the navbar (typically logo) |
centerContent | ReactNode | Required | Content to display in the center section of the navbar (typically navigation links) |
rightContent | ReactNode | Required | Content to display in the right section of the navbar (typically user actions/buttons) |
spacing | number | ResponsiveValue | 3 | Spacing between left, center, and right sections |
direction | StackDirection | 'row' | Layout direction of navbar sections |
className | string | undefined | Additional CSS class name for styling the navbar container |
sx | SxProps<Theme> | See below | MUI System prop for custom styling |
children | BlocksOverride | undefined | Function to override default blocks or add custom navbar sections |
Default sx:
{
alignItems: 'center',
px: 3,
py: 1.5
}
Note: The main component inherits all MUI Stack props. It renders as a nav element via component="nav".
Sub-Componentsβ
The Navbar component provides several sub-components. All sub-components receive their default values from the main component's context and can override these values through props.
Navbar.Leftβ
Renders the left section of the navbar, typically containing the logo.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | leftContent from context | Content to display in the left section (overrides context leftContent) |
leftContent | ReactNode | From context | Alternative way to provide left content (overrides context) |
spacing | number | ResponsiveValue | 1 | Spacing between child elements |
direction | StackDirection | 'row' | Layout direction |
sx | SxProps<Theme> | { alignItems: 'center' } | MUI System prop for custom styling |
Note: This component inherits all MUI Stack props.
Navbar.Centerβ
Renders the center section of the navbar, typically containing navigation links.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | centerContent from context | Content to display in the center section (overrides context centerContent) |
centerContent | ReactNode | From context | Alternative way to provide center content (overrides context) |
spacing | number | ResponsiveValue | 2 | Spacing between child elements |
direction | StackDirection | 'row' | Layout direction |
sx | SxProps<Theme> | See below | MUI System prop for custom styling |
Default sx:
{
alignItems: 'center',
flexGrow: 1
}
Note: This component inherits all MUI Stack props. The flexGrow: 1 causes it to take up available space between left and right sections.
Navbar.Rightβ
Renders the right section of the navbar, typically containing user actions/buttons.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | rightContent from context | Content to display in the right section (overrides context rightContent) |
rightContent | ReactNode | From context | Alternative way to provide right content (overrides context) |
spacing | number | ResponsiveValue | 1 | Spacing between child elements |
direction | StackDirection | 'row' | Layout direction |
sx | SxProps<Theme> | See below | MUI System prop for custom styling |
Default sx:
{
alignItems: 'center',
justifyContent: 'flex-end'
}
Note: This component inherits all MUI Stack props.
Navbar.Logoβ
Renders the logo image for the navbar.
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | Required | The source URL of the logo image |
alt | string | Required | Alternative text for the logo image |
component | string | 'img' | The component used for the root node (fixed) |
sx | SxProps<Theme> | undefined | MUI System prop for custom styling |
Note: This component inherits all MUI Box<'img'> props.
Navbar.Linkβ
Renders a navigation link.
| Prop | Type | Default | Description |
|---|---|---|---|
href | string | Required | The destination URL for the link |
children | ReactNode | Required | The content to display inside the link |
spacing | number | ResponsiveValue | 0.5 | Spacing between child elements (for icons) |
direction | StackDirection | 'row' | Layout direction |
underline | 'none' | 'hover' | 'always' | 'hover' | Link underline behavior (from MUI Link) |
color | string | 'inherit' | Link color |
sx | SxProps<Theme> | See below | MUI System prop for custom styling |
Default sx:
{
display: 'inline-flex',
alignItems: 'center'
}
Note: This component uses MUI Stack with component={Link}. It inherits both StackProps and MUI Link props.
Navbar.ButtonLinkβ
Renders a button-styled link.
| Prop | Type | Default | Description |
|---|---|---|---|
href | string | Required | The destination URL for the button link |
children | ReactNode | Required | The content to display inside the button |
variant | 'text' | 'outlined' | 'contained' | 'contained' | Button variant |
size | 'small' | 'medium' | 'large' | 'small' | Button size |
color | string | 'primary' | Button color |
spacing | number | ResponsiveValue | 0.5 | Spacing between child elements (for icons) |
direction | StackDirection | 'row' | Layout direction |
sx | SxProps<Theme> | undefined | MUI System prop for custom styling |
Note: This component uses MUI Stack with component={Button}. It inherits both StackProps and MUI Button props.
π¨ Configuration examplesβ
Custom Logo Stylingβ
<Navbar.Logo
src="/logo.svg"
alt="Company Logo"
sx={{height: 40, width: 'auto'}}
/>
Custom Navigation Linksβ
<Navbar.Link href="#products" sx={{fontWeight: 600, color: 'primary.main'}}>
Products
</Navbar.Link>
Custom Button Linkβ
<Navbar.ButtonLink href="#register" variant="contained" sx={{px: 3, py: 1}}>
Get Started
</Navbar.ButtonLink>
Custom Styled Componentsβ
function StyledNavbarComponents() {
return (
<Navbar
leftContent={<Navbar.Logo src="/logo.svg" alt="Company Logo" sx={{height: 40, width: 'auto'}} />}
centerContent={
<Navbar.Link href="#products" sx={{fontWeight: 600, color: 'primary.main'}}>
Products
</Navbar.Link>
}
rightContent={
<Navbar.ButtonLink href="#register" variant="contained" sx={{px: 3, py: 1}}>
Get Started
</Navbar.ButtonLink>
}
>
<Navbar.Left />
<Navbar.Center />
<Navbar.Right />
</Navbar>
);
}
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import {Stack} from '@mui/material';
import {Navbar} from '@nodeblocks/frontend-navbar-block';
import React from 'react';
// Example with comprehensive typing
function CustomNavbar() {
return (
<Navbar
leftContent={<Navbar.Logo src="/logo.svg" alt="Logo" />}
centerContent={
<Stack direction="row" spacing={2}>
<Navbar.Link href="#home">Home</Navbar.Link>
<Navbar.Link href="#products">Products</Navbar.Link>
<Navbar.Link href="#about">About</Navbar.Link>
</Stack>
}
rightContent={
<Stack direction="row" spacing={1}>
<Navbar.ButtonLink href="#login" variant="text">
Login
</Navbar.ButtonLink>
<Navbar.ButtonLink href="#register">Register</Navbar.ButtonLink>
</Stack>
}
spacing={4}
sx={{
backgroundColor: 'background.paper',
boxShadow: 1,
borderRadius: 2,
}}
>
<Navbar.Left sx={{minWidth: 150}} />
<Navbar.Center justifyContent="center" />
<Navbar.Right sx={{minWidth: 200}} />
</Navbar>
);
}
π Notesβ
- The main component uses MUI
Stackwithcomponent="nav"anddirection="row"withspacing={3}by default. - All section components (
Left,Center,Right) inherit MUIStackprops and support thesxprop for styling. - The
Centersection hasflexGrow: 1by default, causing it to expand and fill available space. - The
Rightsection hasjustifyContent: 'flex-end'by default, aligning its content to the right. Navbar.Logouses MUIBoxwithcomponent="img"for proper image rendering with MUI styling support.Navbar.Linkcombines MUIStacklayout with MUILinknavigation, allowing for icons alongside text.Navbar.ButtonLinkcombines MUIStacklayout with MUIButton, usingvariant="contained"andsize="small"by default.- Context values (
leftContent,centerContent,rightContent) are shared via React Context and can be overridden at the sub-component level.
Built with β€οΈ using React, TypeScript, and MUI.