TopBar
The bar at the top of every signed-in page: the brand, where the person is, and the tools on the right. AppShell draws it; use it on its own when the frame is the app's own.
import { TopBar, OrgSwitcher, ProjectSwitcher, UserMenu, NotificationBell } from '@sypnia/ui/react'
The bar of a console
Code
import { useState } from 'react';
import { Logo, NotificationBell, OrgSwitcher, ProjectSwitcher, TopBar, UserMenu } from '@sypnia/ui/react';
// The bar of a console on its own: brand, where you are (organization / project), and the tools on the right.
export default function Console() {
const [org, setOrg] = useState('acme');
const [project, setProject] = useState('shop');
return (
<TopBar brand={<Logo product="Data" />}
where={<div className="sy-row"><OrgSwitcher current={org} onChange={setOrg} options={[{ id: 'acme', name: 'Acme' }, { id: 'north', name: 'Northwind' }]} /><span className="sy-text--muted">/</span>
<ProjectSwitcher current={project} onChange={setProject} options={[{ id: 'shop', name: 'shop' }, { id: 'analytics', name: 'analytics' }]} /></div>}
tools={<><NotificationBell items={[{ id: '1', title: 'Backup finished', at: new Date(), unread: true, icon: 'backup', tone: 'ok' }]} /><UserMenu name="Ana Ruiz" email="ana@northwind.io" onSignOut={() => {}} /></>} />
);
} When to use it
Use it when
- Apps that do not use AppShell but want the same top bar.
- Put the organization and project switchers in
where, and the bell and the account menu intools.
Do not use it when
- Inside AppShell: it already has one.
- Many buttons in the bar: keep it to search, notifications and the account.
For everyone
- It is a
headerlandmark. - Each tool has a name; the switchers say what they switch.
Props
| TopBar | Type | Default |
|---|---|---|
brandrequired | ReactNode | |
tools | ReactNode | |
where | ReactNode |
| OrgSwitcher | Type | Default |
|---|---|---|
currentrequired | string | |
onChangerequired | (id: string) => void | |
optionsrequired | SwitcherOption[] | |
compact | boolean | |
createLabelThe thing to create: «organization». Defaults to `kind`. | string | |
kind | string | |
onCreateAdds «Create …» at the end of the list. | (() => void) | |
onSettingsAdds a settings entry at the end of the list («Organization settings» on the OrgSwitcher). | (() => void) | |
settingsLabelThe words of that entry. | string |
| ProjectSwitcher | Type | Default |
|---|---|---|
currentrequired | string | |
onChangerequired | (id: string) => void | |
optionsrequired | SwitcherOption[] | |
compact | boolean | |
createLabelThe thing to create: «organization». Defaults to `kind`. | string | |
kind | string | |
onCreateAdds «Create …» at the end of the list. | (() => void) | |
onSettingsAdds a settings entry at the end of the list («Organization settings» on the OrgSwitcher). | (() => void) | |
settingsLabelThe words of that entry. | string |
| UserMenu | Type | Default |
|---|---|---|
namerequired | string | |
onSignOutrequired | () => void | |
childrenItems between the header and Sign out, as MenuItem: «Account», «Preferences». | ReactNode | |
email | string | |
onAction | ((key: Key) => void) | |
src | string |
| NotificationBell | Type | Default |
|---|---|---|
itemsrequired | NotificationEntry[] | |
labelDefaults to «Notifications». | string | |
onOpen | ((id: string) => void) | |
onReadAll | (() => void) |