Demo
App Bar
Documented in App Bar.
App Bar
A header with the salmon-app-bar class around a Toolbar inside a scrolling frame, switching between the default and primary tone, a theme app bar surface, top and bottom position, and sticky or static.
Section 1: scroll this frame to see whether the bar stays in view.
Section 2: scroll this frame to see whether the bar stays in view.
Section 3: scroll this frame to see whether the bar stays in view.
Section 4: scroll this frame to see whether the bar stays in view.
Section 5: scroll this frame to see whether the bar stays in view.
Section 6: scroll this frame to see whether the bar stays in view.
Section 7: scroll this frame to see whether the bar stays in view.
Section 8: scroll this frame to see whether the bar stays in view.
Demo.tsx
'use client';
import { useState } from 'react';
import { Button } from '@salmonui/buttons/button';
import { Checkbox } from '@salmonui/inputs/checkbox';
import { TextField } from '@salmonui/inputs/text-field';
import { Toolbar, ToolbarItem, ToolbarSpacer } from '@salmonui/navigation/toolbar';
import { ThemeStyle } from '@salmonui/core/server';
import { ThemeProvider, type SalmonThemeInput } from '@salmonui/core/theme';
const paragraphs = Array.from({ length: 8 }, (_, index) => `Section ${index + 1}: scroll this frame to see whether the bar stays in view.`);
// A theme with an app bar surface: the bar opts in with data-salmon-surface="app-bar".
const surfaceTheme: SalmonThemeInput = { surfaces: { appBar: '#192225' } };
export default function AppBarRecipeDemo() {
const [primary, setPrimary] = useState(true);
const [surface, setSurface] = useState(false);
const [bottom, setBottom] = useState(false);
const [sticky, setSticky] = useState(true);
const Bar = bottom ? 'footer' : 'header';
const bar = (
<Bar
className="salmon-app-bar"
data-salmon-surface="app-bar"
data-tone={primary && !surface ? 'primary' : undefined}
data-position={bottom ? 'bottom' : undefined}
data-sticky={sticky ? '' : undefined}
>
<Toolbar aria-label="Application" overflow="wrap">
<strong style={{ paddingInline: 8 }}>Acme</strong>
<Button variant="ghost">Products</Button>
<Button variant="ghost">Pricing</Button>
<ToolbarSpacer />
<ToolbarItem overflow="never">
<TextField type="search" aria-label="Search" placeholder="Search" />
</ToolbarItem>
<Button variant="ghost">Sign in</Button>
</Toolbar>
</Bar>
);
// A scrolling frame stands in for the page so the sticky bar can be seen.
const frame = (
<div tabIndex={0} role="region" aria-label="Scrolling page" style={{ maxBlockSize: 240, overflow: 'auto', border: '1px solid var(--salmon-border-subtle)', borderRadius: 'var(--salmon-radius-lg)' }}>
{bottom ? null : bar}
{paragraphs.map((text) => (
<p key={text} style={{ margin: 0, padding: '12px 16px' }}>
{text}
</p>
))}
{bottom ? bar : null}
</div>
);
return (
<div>
<div className="demo-toolbar">
<Checkbox checked={primary} disabled={surface} onCheckedChange={(checked) => setPrimary(checked)}>
Primary tone
</Checkbox>
<Checkbox checked={surface} onCheckedChange={(checked) => setSurface(checked)}>
Theme surface
</Checkbox>
<Checkbox checked={bottom} onCheckedChange={(checked) => setBottom(checked)}>
Bottom position
</Checkbox>
<Checkbox checked={sticky} onCheckedChange={(checked) => setSticky(checked)}>
Sticky
</Checkbox>
</div>
{surface ? (
<>
<ThemeStyle theme={surfaceTheme} />
<ThemeProvider theme={surfaceTheme}>{frame}</ThemeProvider>
</>
) : (
frame
)}
</div>
);
}
The bar is a plain <header> (or <footer> at the bottom) with
.salmon-app-bar; the Toolbar inside provides the keyboard model and the
alignment.
Turn Sticky on and scroll the frame: data-sticky makes the bar
position: sticky, pinned to the top (or to the bottom with
data-position="bottom"). Off, it scrolls away with the content.
The bar always carries data-salmon-surface="app-bar". Turn Theme
surface on to wrap the frame in a theme with surfaces: { appBar: '#192225' }: the bar turns near-black and its buttons and search field
switch to the derived light foreground.