Layout & Containers
Top Bar
The bar across the top of an app, with places for a title, search, notifications and the account menu. It stays on screen while the page scrolls.
The top bar holds what every page of an app needs within reach: a way back to the navigation, search, and the signed-in user. It has three places. The start holds a sidebar trigger, a title or a breadcrumb. The middle holds search. The end holds notifications, a theme toggle and the account menu. The middle stretches, so the end always sits at the far edge, whether or not there is a middle.
Preview
Section titled “Preview”<div
style="
width: 100%;
border: 1px solid var(--nana-surface-border);
border-radius: 0.5rem;
overflow: hidden;
"
>
<nana-top-bar sticky="false">
<span slot="start" style="font-weight: 600">Claims desk</span>
<nana-input
type="search"
aria-label="Search claims"
placeholder="Search claims"
style="width: 100%; max-width: 24rem"
>
<nana-icon slot="prefix" name="magnifying-glass"></nana-icon>
</nana-input>
<nana-icon-button
slot="end"
name="bell"
label="Notifications"
></nana-icon-button>
<nana-avatar slot="end" name="Amina Otieno" size="sm"></nana-avatar>
</nana-top-bar>
<div
style="height: 8rem; padding: 1rem; background: var(--nana-surface-subtle)"
>
Page content
</div>
</div> <script lang="ts">
import { bellIcon, magnifyingGlassIcon } from '@nana-tec/ui-core/heroicons';
import { NanaAvatar, NanaIcon, NanaIconButton, NanaInput, NanaTopBar } from '$lib';
</script>
<div class="w-full overflow-hidden rounded-lg border border-line">
<NanaTopBar sticky={false} aria-label="Workspace">
{#snippet start()}
<span class="font-semibold">Claims desk</span>
{/snippet}
<NanaInput
class="w-full max-w-sm"
type="search"
aria-label="Search claims"
placeholder="Search claims"
>
{#snippet prefix()}<NanaIcon icon={magnifyingGlassIcon} />{/snippet}
</NanaInput>
{#snippet end()}
<NanaIconButton icon={bellIcon} label="Notifications" />
<NanaAvatar name="Amina Otieno" size="sm" />
{/snippet}
</NanaTopBar>
<div class="h-32 bg-surface-subtle p-4 text-sm text-foreground-muted">Page content</div>
</div> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add top-bar --framework web-componentsnpx @nana-tec/ui add top-bar --framework svelteLands in src/lib/components/ui/top-bar/ as NanaTopBar.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/top-bar";
Copied in with npx @nana-tec/ui add top-bar? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
Put content in the start and end slots; anything without a slot goes in the middle.
<nana-top-bar> <nana-sidebar-trigger slot="start"></nana-sidebar-trigger> <nana-input type="search" aria-label="Search"></nana-input> <nana-icon-button slot="end" name="bell" label="Notifications"></nana-icon-button> <nana-dropdown slot="end">…</nana-dropdown></nana-top-bar>Fill the start and end snippets; children go in the middle.
<script lang="ts"> import { NanaTopBar } from '$lib/components/ui/top-bar';</script>
<NanaTopBar> {#snippet start()}<NanaSidebarTrigger />{/snippet} <NanaInput type="search" aria-label="Search" /> {#snippet end()} <NanaThemeToggle /> <NanaDropdown …></NanaDropdown> {/snippet}</NanaTopBar>In an app shell
Section titled “In an app shell”Put the top bar first inside the sidebar layout’s page, then the page header and the content. The bar stays at the top while the page scrolls under it, and the sidebar trigger in it works on a phone too.
<nana-sidebar-layout label="Main"> <nana-sidebar-group slot="sidebar" label="Workspace">…</nana-sidebar-group> <nana-top-bar> <nana-sidebar-trigger slot="start"></nana-sidebar-trigger> </nana-top-bar> <div style="padding: 1.5rem"> <nana-page-header heading="Claims"></nana-page-header> </div></nana-sidebar-layout><NanaSidebarLayout label="Main"> <NanaSidebar>…</NanaSidebar> <NanaSidebarInset> <NanaTopBar> {#snippet start()}<NanaSidebarTrigger />{/snippet} </NanaTopBar> <div class="p-6"><NanaPageHeader heading="Claims" /></div> </NanaSidebarInset></NanaSidebarLayout>Sticky
Section titled “Sticky”The bar is sticky by default. Over scrolling content it turns slightly translucent and
blurs what passes under it. It sits on the --nana-z-index-sticky layer, which is below
menus, dialogs and toasts, so they always open over it. Set --nana-top-bar-z to change
its place.
To let the bar scroll away with the page, turn sticky off:
<nana-top-bar sticky="false">…</nana-top-bar><NanaTopBar sticky={false}>…</NanaTopBar>Accessibility
Section titled “Accessibility”- The bar is a
header. Inside the page’smainit adds no landmark of its own; at the top of the page, outsidemain, it is the page’s banner. - Give every icon-only button a label, such as “Notifications”.
- Label the search field, even when a placeholder shows, since a placeholder disappears as soon as someone types.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
sticky | sticky | boolean | true | Keeps the bar at the top while the page scrolls. Set sticky="false" to let it scroll away. |
Slots
| Slot | Description |
|---|---|
(default) | The middle of the bar, usually a search field |
start | The start of the bar, such as a nana-sidebar-trigger and a breadcrumb |
end | The end of the bar, such as a theme toggle, notifications and the account menu |
CSS parts
| Part | Description |
|---|---|
::part(base) | The bar |
::part(start) | The wrapper around the start content |
::part(center) | The wrapper around the middle content |
::part(end) | The wrapper around the end content |
CSS custom properties
| Property | Description |
|---|---|
--nana-top-bar-height | Minimum height of the bar |
--nana-top-bar-bg | Background of the bar |
--nana-top-bar-z | Stacking order while sticky |
NanaTopBar
| Prop | Type | Default |
|---|---|---|
sticky | boolean | true |
start | Snippet | |
end | Snippet | |
children | Snippet |
Also accepts Omit<HTMLAttributes<HTMLElement>, 'class'>.
sticky keeps the bar at the top, on by default. start and end are snippets, and
children fill the middle. Other attributes, such as aria-label, go on the header.