Navbar
The <smart-navbar> component renders a top navigation bar with a logo, primary nav items, optional secondary row, search, action, notification and user-menu slots, plus a mobile menu toggle. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract NavbarBaseComponent defines the shared API — options (INavbarOptions), cssClass (alias class), mobileMenuOpen (two-way ModelSignal<boolean>), and the itemClick output. NavbarStandardComponent is a barebones placeholder using native <nav>, <a>, <button>, <ul> and <li> elements. NavbarComponent is the public wrapper that renders NavbarStandardComponent by default and accepts a custom replacement via NAVBAR_STANDARD_COMPONENT_TOKEN.
Usage
<smart-navbar [options]="options()" (itemClick)="onItemClick($event)" />
The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Components
NavbarComponent (<smart-navbar>)
Main wrapper. Delegates to NavbarStandardComponent by default. When NAVBAR_STANDARD_COMPONENT_TOKEN is provided (or provideSmartPresets() registers the preset), renders the injected component via NgComponentOutlet. In both cases it forwards options and the class, re-emits itemClick and keeps the two-way mobileMenuOpen in sync. Items with an href render as plain <a [href]> links (no routerLink, so a click loads the URL); items without href are buttons reported through itemClick.
NavbarStandardComponent (<smart-navbar-standard>)
Barebones placeholder using native HTML. Renders an outer wrapper with cssClass, a <nav class="navbar"> containing a mobile menu toggle button, optional logo (logoTpl as is, or an <img> from logoUrl/logoAlt, wrapped in <a> when logoHref is provided), a primary <ul> of items (each rendered as <a class="item-link"> when href is provided, otherwise <button class="item-button"> emitting itemClick; gets current class when item.current === true; iconTpl before the label), and template-ref slots searchTpl / actionTpl / notificationTpl / userMenuTpl. Optionally renders a <nav class="navbar-secondary"> row when options.secondaryItems is non-empty, and a .mobile-menu panel when mobileMenuOpen() is true.
NavbarPresetComponent (<smart-navbar-preset>)
Fully-styled, drop-in concrete implementation extending NavbarBaseComponent, translating the Preline collapsible navbar look to smart:-prefixed Tailwind classes with explicit dark: variants. Renders a <header> with a brand/logo slot (logoTpl, or <img> from logoUrl/logoAlt, either wrapped in <a> when logoHref is set), a responsive primary link row (anchors for items with href, otherwise buttons emitting itemClick; current items get the active/aria-current="page" styling), the searchTpl / actionTpl / notificationTpl / userMenuTpl slots, an optional secondary link row from secondaryItems, and a mobile menu toggle. The mobile collapse is driven entirely by the two-way mobileMenuOpen signal (@if + (click)), so no Preline JS runtime is needed. options.dark switches to the solid dark color variant and options.menuButtonOnLeft moves the toggle ahead of the brand.
Register it via NAVBAR_STANDARD_COMPONENT_TOKEN (or with provideSmartPresets()) to restyle every <smart-navbar>, or use the <smart-navbar-preset> selector directly. The preset declares cssClass without the class alias: on the <smart-navbar-preset> selector bind [cssClass]; on <smart-navbar> pass class as usual.
NavbarBaseComponent (abstract)
Abstract base directive. Exposes:
options: InputSignal<INavbarOptions | undefined>cssClass: InputSignal<string>(aliasclass)mobileMenuOpen: ModelSignal<boolean>(defaultfalse)itemClick: OutputEmitterRef<INavbarItemClick>
INavbarItemClick = { itemId: string }.
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
options | InputSignal<INavbarOptions | undefined> | - | Navbar configuration |
class | InputSignal<string> | '' | External CSS classes (alias for cssClass) |
mobileMenuOpen | ModelSignal<boolean> | false | Two-way bindable mobile menu open state |
Outputs
| Output | Type | Description |
|---|---|---|
itemClick | OutputEmitterRef<INavbarItemClick> | Emitted when a button-type nav item is clicked |
INavbarOptions
| Field | Type | Default | Description |
|---|---|---|---|
logoTpl | TemplateRef<unknown> | - | The brand as a template; wins over the logo image. |
logoUrl | string | - | Logo image URL. |
logoAlt | string | '' | Alt text of the logo image. |
logoHref | string | - | Link of the logo (the standard links the image only, the preset links logoTpl too). |
items | INavbarItem[] | [] | The primary links (also listed in the mobile menu of the standard). |
secondaryItems | INavbarItem[] | [] | A second row of links. |
searchTpl | TemplateRef<unknown> | - | Search slot. |
actionTpl | TemplateRef<unknown> | - | Quick-action slot (e.g. a "New" button). |
notificationTpl | TemplateRef<unknown> | - | Notifications slot. |
userMenuTpl | TemplateRef<unknown> | - | User menu slot (e.g. an avatar dropdown). |
dark | boolean | false | Preset only: the solid dark colour variant. |
menuButtonOnLeft | boolean | false | Preset only: places the mobile menu button before the brand. |
layout | SmartNavbarLayout | - | Not read by the built-in implementations; available to a custom implementation. |
SmartNavbarLayout is 'simple' | 'simple-with-menu-on-left' | 'with-quick-action' | 'with-search' | 'with-centered-search' | 'with-secondary-links' | 'with-column-layout'.
INavbarItem
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Reported as itemId by itemClick. |
label | string | - | Link text. |
href | string | - | Renders a plain <a [href]>; without it the item is a button (itemClick). |
current | boolean | - | Marks the current page (current class; aria-current="page" in the preset). |
iconTpl | TemplateRef<unknown> | - | Icon before the label (primary row only). |
The wrapper does not move current itself: to highlight the clicked item, keep the current id in your component and rebuild items with current: item.id === activeId in the (itemClick) handler.
NAVBAR_STANDARD_COMPONENT_TOKEN
InjectionToken from @smartsoft001/angular that allows replacing the default NavbarStandardComponent with a custom implementation. Provide a Type<NavbarBaseComponent> in your application or component providers; provideSmartPresets() provides NavbarPresetComponent for it together with every other preset.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
computed,
ViewEncapsulation,
} from '@angular/core';
import {
INavbarOptions,
NAVBAR_STANDARD_COMPONENT_TOKEN,
NavbarBaseComponent,
NavbarComponent,
} from '@smartsoft001/angular';
/**
* A custom navbar built on `NavbarBaseComponent`.
*
* The base contributes the `options` and `class` inputs, the `mobileMenuOpen`
* model and the `itemClick` output; the implementation owns the markup and
* decides when to emit.
*/
@Component({
selector: 'docs-custom-navbar',
template: `
<nav [class]="containerClasses()">
@if (options()?.logoUrl) {
<a class="docs-navbar__logo" [href]="options()?.logoHref ?? '#'">
<img [src]="options()!.logoUrl" [alt]="options()?.logoAlt ?? ''" />
</a>
}
<ul class="docs-navbar__items">
@for (item of options()?.items ?? []; track item.id) {
<li>
<a
class="docs-navbar__item"
[href]="item.href ?? '#'"
[attr.aria-current]="item.current ? 'page' : null"
(click)="itemClick.emit({ itemId: item.id })"
>
{{ item.label }}
</a>
</li>
}
</ul>
<button
type="button"
class="docs-navbar__toggle"
aria-label="Toggle navigation"
[attr.aria-expanded]="mobileMenuOpen()"
(click)="mobileMenuOpen.set(!mobileMenuOpen())"
>
☰
</button>
@if (mobileMenuOpen()) {
<ul class="docs-navbar__mobile">
@for (item of options()?.items ?? []; track item.id) {
<li>
<a [href]="item.href ?? '#'">{{ item.label }}</a>
</li>
}
</ul>
}
</nav>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomNavbarComponent extends NavbarBaseComponent {
containerClasses = computed(() => {
const classes = ['docs-navbar'];
if (this.options()?.dark) classes.push('docs-navbar--dark');
if (this.options()?.menuButtonOnLeft) {
classes.push('docs-navbar--menu-left');
}
const extra = this.cssClass();
if (extra) classes.push(extra);
return classes.join(' ');
});
}
/**
* Registering the implementation against `NAVBAR_STANDARD_COMPONENT_TOKEN`
* makes every `<smart-navbar>` in this injector render it instead of the
* standard variation. The wrapper forwards the `itemClick` output and the
* `mobileMenuOpen` model of the custom navbar, so `(itemClick)` and
* `[(mobileMenuOpen)]` on `<smart-navbar>` keep working.
*/
@Component({
selector: 'docs-navbar-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [NavbarComponent],
providers: [
{
provide: NAVBAR_STANDARD_COMPONENT_TOKEN,
useValue: CustomNavbarComponent,
},
],
template: `<smart-navbar [options]="options" />`,
})
export class NavbarCustomExampleComponent {
options: INavbarOptions = {
dark: false,
logoUrl: 'https://avatars.githubusercontent.com/u/10416742?s=200&v=4',
logoAlt: 'Brand',
logoHref: '#',
items: [
{ id: 'landing', label: 'Landing', href: '#', current: true },
{ id: 'account', label: 'Account', href: '#' },
{ id: 'work', label: 'Work', href: '#' },
{ id: 'blog', label: 'Blog', href: '#' },
],
};
}
Source
The component lives in packages/shared/angular/src/lib/components/navbar and is documented for Claude Code by the angular-components-navbar skill.
SmartNavbar is the top navigation bar: a logo (logoTpl, or logoUrl / logoAlt / logoHref), a row of primary links (items), an optional row of secondary links, slots for search, a quick action, notifications and the user menu, and a mobile menu toggle. Items with an internal href render through the navigation adapter's linkComponent (e.g. your router's Link) when one is set, external ones as <a>; items without href are buttons reported through onItemClick({ itemId }). The mobile menu state is controlled (mobileMenuOpen + onMobileMenuOpenChange) or kept inside.
Usage
import { useState } from 'react';
import {
INavbarItemClick,
INavbarOptions,
SmartNavbar,
} from '@smartsoft001/react';
const items = [
{ id: 'dashboard', label: 'Dashboard' },
{ id: 'team', label: 'Team' },
{ id: 'projects', label: 'Projects' },
];
export function NavbarUsageExample() {
const [activeItem, setActiveItem] = useState('dashboard');
const options: INavbarOptions = {
logoUrl:
'https://tailwindcss.com/plus-assets/img/logos/mark.svg?color=indigo&shade=600',
logoAlt: 'Acme',
logoHref: '#',
items: items.map((item) => ({
...item,
current: item.id === activeItem,
})),
};
// Items without `href` are buttons reported through onItemClick.
const onItemClick = ({ itemId }: INavbarItemClick) => setActiveItem(itemId);
return <SmartNavbar options={options} onItemClick={onItemClick} />;
}
The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Exports
All from @smartsoft001/react.
| Export | Kind | What it is |
|---|---|---|
SmartNavbar | component | Renders the implementation registered as components.navbar on SmartProvider, SmartNavbarStandard by default. |
SmartNavbarPreset | component | Styled navbar variation (preset). |
SmartNavbarStandard | component | The default navbar rendering. |
useNavbar | hook | The behaviour every navbar variant shares: the mobile menu state, controlled through mobileMenuOpen or kept internally when that prop is undefined, and the item click. |
The preset's class helpers (getNavbarHeaderClasses, getNavbarBrandClasses, getNavbarToggleClasses, getNavbarCollapseClasses, getNavbarItemClasses, getNavbarSecondaryNavClasses, NAVBAR_NAV_CONTAINER, NAVBAR_BRAND_ROW, NAVBAR_LINKS_CONTAINER, NAVBAR_SECONDARY_CONTAINER) are exported too, for a custom implementation that wants the preset look.
Props and Types
SmartNavbarProps
| Prop | Type | Default | Description |
|---|---|---|---|
options? | INavbarOptions | — | Logo, links and slots. |
className? | string | — | Classes on the root element. |
mobileMenuOpen? | boolean | — | Whether the mobile menu is open. Leave it undefined to let the component keep the state itself. |
defaultMobileMenuOpen? | boolean | false | The initial state of an uncontrolled mobile menu. |
onMobileMenuOpenChange? | (mobileMenuOpen: boolean) => void | — | Called when the mobile menu opens or closes. |
onItemClick? | (event: INavbarItemClick) => void | — | A click on an item without href. |
INavbarOptions
| Field | Type | Default | Description |
|---|---|---|---|
layout? | SmartNavbarLayout | — | Declared (SmartNavbarLayout); neither the standard nor the preset rendering reads it. |
dark? | boolean | — | Preset: the solid dark colour variant. |
menuButtonOnLeft? | boolean | — | Preset: places the mobile menu button on the left. |
logoTpl? | ReactNode | — | The brand as a node; wins over the logo image. |
logoUrl? | string | — | Logo image URL. |
logoAlt? | string | '' | Alt text of the logo image. |
logoHref? | string | — | Link of the logo. |
items? | INavbarItem[] | [] | The primary links. |
secondaryItems? | INavbarItem[] | [] | A second row of links. |
searchTpl? | ReactNode | — | Search slot. |
actionTpl? | ReactNode | — | Quick-action slot (e.g. a "New" button). |
notificationTpl? | ReactNode | — | Notifications slot. |
userMenuTpl? | ReactNode | — | User menu slot (e.g. an avatar dropdown). |
INavbarItemClick
| Field | Type | Default | Description |
|---|---|---|---|
itemId | string | required | The id of the clicked item. |
INavbarItem
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Reported as itemId. |
label? | string | — | Link text. |
href? | string | — | Renders a link (through the navigation adapter for internal paths). |
current? | boolean | — | Marks the current page. |
iconTpl? | ReactNode | — | Icon before the label. |
Related types
SmartNavbarLayout:'simple' \| 'simple-with-menu-on-left' \| 'with-quick-action' \| 'with-search' \| 'with-centered-search' \| 'with-secondary-links' \| 'with-column-layout'
Replacing the Implementation
SmartNavbar renders the component registered under the 'navbar' key of SmartProvider's components, and SmartNavbarStandard when nothing is registered there. Every SmartNavbar below the provider then renders the registered component, which receives the same props.
SmartNavbarPreset is the styled (preset) implementation: register it under the 'navbar' key of SmartProvider's components, render it directly in place of SmartNavbar, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.
The useNavbar hook
The behaviour every navbar variant shares: the mobile menu state, controlled through mobileMenuOpen or kept internally when that prop is undefined, and the item click.
| Returns | Type | Description |
|---|---|---|
mobileMenuOpen | boolean | The mobile menu state (controlled or internal). |
setMobileMenuOpen | (next: boolean) => void | Sets the state and calls onMobileMenuOpenChange. |
toggleMobileMenu | () => void | Opens or closes the mobile menu. |
itemClick | (itemId: string) => void | undefined | Reports a click on an item without href. |
import {
INavbarOptions,
SmartNavbar,
SmartNavbarProps,
SmartProvider,
useNavbar,
} from '@smartsoft001/react';
/**
* A custom navbar built on `useNavbar`: the hook keeps the mobile menu state
* (controlled through `mobileMenuOpen` or kept inside) and reports item clicks
* through `itemClick(id)`; the implementation owns the markup.
*/
export function CustomNavbar(props: SmartNavbarProps) {
const { options, className } = props;
const { mobileMenuOpen, toggleMobileMenu, itemClick } = useNavbar(props);
const items = options?.items ?? [];
const classes = [
'docs-navbar',
options?.dark && 'docs-navbar--dark',
options?.menuButtonOnLeft && 'docs-navbar--menu-left',
className,
]
.filter(Boolean)
.join(' ');
return (
<nav className={classes}>
{options?.logoUrl && (
<a className="docs-navbar__logo" href={options.logoHref ?? '#'}>
<img src={options.logoUrl} alt={options.logoAlt ?? ''} />
</a>
)}
<ul className="docs-navbar__items">
{items.map((item) => (
<li key={item.id}>
<a
className="docs-navbar__item"
href={item.href ?? '#'}
aria-current={item.current ? 'page' : undefined}
onClick={() => itemClick(item.id)}
>
{item.label}
</a>
</li>
))}
</ul>
<button
type="button"
className="docs-navbar__toggle"
aria-label="Toggle navigation"
aria-expanded={mobileMenuOpen}
onClick={toggleMobileMenu}
>
☰
</button>
{mobileMenuOpen && (
<ul className="docs-navbar__mobile">
{items.map((item) => (
<li key={item.id}>
<a href={item.href ?? '#'}>{item.label}</a>
</li>
))}
</ul>
)}
</nav>
);
}
// A module constant: a new object on every render would change the context.
const components = { navbar: CustomNavbar };
const options: INavbarOptions = {
dark: false,
logoUrl: 'https://avatars.githubusercontent.com/u/10416742?s=200&v=4',
logoAlt: 'Brand',
logoHref: '#',
items: [
{ id: 'landing', label: 'Landing', href: '#', current: true },
{ id: 'account', label: 'Account', href: '#' },
{ id: 'work', label: 'Work', href: '#' },
{ id: 'blog', label: 'Blog', href: '#' },
],
};
/**
* Every `SmartNavbar` below this provider renders `CustomNavbar` instead of
* the standard rendering.
*/
export function NavbarCustomExample() {
return (
<SmartProvider components={components}>
<SmartNavbar options={options} />
</SmartProvider>
);
}
Styling
SmartNavbarStandardis semantic markup with class hooks (navbar,mobile-menu-toggle,item-link,current,search,user-menu, ...).SmartNavbarPresetis a collapsible navbar driven only bymobileMenuOpen;options.darkpicks the dark colour variant, and light mode carriessmart:dark:variants.
Source
The component lives in packages/shared/react/src/lib/components/navbar and is documented for Claude Code by the react-components-navbar skill.