# Topbar Implementation Install, theme-hook wiring, and composition for the Aura Topbar (`@cognite/aura/components/topbar`). Run the interview ([INTERVIEW.md](INTERVIEW.md)) first. --- ## Step 3 — Install The Topbar ships inside the published **`@cognite/aura`** package and is imported from the `@cognite/aura/components/topbar` subpath. There is **no shadcn registry step**: do not run `shadcn init` / `shadcn add`, and do not add a `components.json` registry entry. (The old `@aura` registry at `cognitedata.github.io/aura/r/` is no longer served.) ### 3a — Check if already installed Check `package.json` for `@cognite/aura`. If present, confirm the installed version ships the Topbar: ```bash ls node_modules/@cognite/aura/dist/components/ui/core/topbar/topbar.d.ts ``` The file should exist (`@cognite/aura/package.json` is not in the package `exports`, so do not `require('@cognite/aura/package.json')`). If it is missing, upgrade `@cognite/aura` to the latest version. Aura declares `react` ^18 as a peer, plus `tailwindcss`, `recharts` and `@tanstack/react-table` / `react-virtual` — install any that are missing. ### 3b — Install (only if missing) Detect the package manager, then install `@cognite/aura`: - `pnpm-lock.yaml` → `pnpm add @cognite/aura` - `yarn.lock` → `yarn add @cognite/aura` - `package-lock.json` → `npm install @cognite/aura` > **If the import still cannot be resolved**, stop. Tell the user exactly what failed (package missing, version too old, registry/auth error) and ask them to resolve it. Do not build a custom header as a workaround. ### 3c — Styles Import Aura's stylesheet once at the app entry (before app CSS). Aura ships Tailwind v4 CSS; the app does **not** need its own `tailwind.config` for Aura tokens, so tools like `shadcn init` will not detect Tailwind here and are not needed. ```ts import '@cognite/aura/colors.css'; import '@cognite/aura/styles.css'; ``` `styles.css` is precompiled and carries the tokens and utilities. `colors.css` contains Tailwind v4 `@theme` source, so a build without Tailwind may print an `Unknown at rule: @theme` warning from the CSS minifier — it is harmless, and the Topbar renders correctly either way. --- ## Step 4 — Dark mode hook Always implement theme switching (light / dark). Check for an existing theme system first: - Search for `useDarkMode`, `useTheme`, `useColorScheme`, or a `ThemeProvider` in `src/` - If found, wire into it and skip creating a new hook. If none exists, create `src/hooks/use-theme-mode.ts` (or extend your existing hook) so the Topbar menu can **set** light or dark explicitly: ```ts import { useEffect, useState } from 'react'; export type ThemeMode = 'light' | 'dark'; export function useThemeMode() { const [mode, setMode] = useState(() => { const stored = localStorage.getItem('theme'); if (stored === 'dark' || stored === 'light') return stored; return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; }); useEffect(() => { const isDark = mode === 'dark'; document.documentElement.classList.toggle('dark', isDark); localStorage.setItem('theme', isDark ? 'dark' : 'light'); }, [mode]); return { mode, isDark: mode === 'dark', setTheme: (next: ThemeMode) => setMode(next), }; } ``` Apply the initial class on page load in `main.tsx` / `index.tsx`: ```ts const stored = localStorage.getItem('theme'); const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; if (stored === 'dark' || (!stored && prefersDark)) { document.documentElement.classList.add('dark'); } ``` Pass `mode` and `setTheme` to `TopbarThemeSwitcher` (`theme` / `onThemeChange`); it renders the sun/moon trigger and the checkmarked Light/Dark menu itself. --- ## Step 5 — Implement the Topbar The Topbar is a set of **compound components**, not a single props-driven component. Always confirm exact names and props against the installed package types (`node_modules/@cognite/aura/dist/components/ui/core/topbar/topbar.d.ts`) before writing code. Exports of `@cognite/aura/components/topbar`: `Topbar`, `TopbarLeft`, `TopbarIcon`, `TopbarBreadcrumbs`, `TopbarMetadata`, `TopbarCenter`, `TopbarRight`, `TopbarThemeSwitcher`, `TopbarAction`, and the `TopbarTheme` type. - **Share, Notifications and Atlas are not built-in.** Compose each from `TopbarAction` (`variant="ghost" size="icon-sm"` for Share / Notifications, `variant="secondary" size="sm"` with icon + "Atlas" for Atlas). - **Theme** is `TopbarThemeSwitcher` (`theme`, `onThemeChange`) — it renders the sun/moon trigger and Light/Dark radio menu itself. - **Atlas** has no built-in sidebar: its `onClick` opens the EOS sidebar via `sendAgentLayoutMode` (see `integrate-fusion-agent`). Aura has no Atlas icon; use the inline SVG below. ```tsx import { Avatar, AvatarFallback, AvatarImage } from '@cognite/aura/components/avatar'; // Also import BreadcrumbPage / BreadcrumbSeparator when an object is open import { BreadcrumbItem, BreadcrumbLink, BreadcrumbList, } from '@cognite/aura/components/breadcrumb'; import { Topbar, TopbarAction, TopbarBreadcrumbs, TopbarIcon, TopbarLeft, TopbarRight, TopbarThemeSwitcher, } from '@cognite/aura/components/topbar'; // also TopbarCenter / TopbarMetadata when used import { IconBell, IconShare } from '@cognite/aura/icons'; // re-exports Tabler icons import { useThemeMode } from '@/hooks/use-theme-mode'; function AtlasIcon() { return ( ); } export function AppShell({ children }: { children: React.ReactNode }) { const { mode, setTheme } = useThemeMode(); const api = useFusionAgentApi(); // the agent API from integrate-fusion-agent Step 2 return ( <> {/* Left — app mark → breadcrumbs → optional inline metadata */} {/* App name: a link only when an object is open; otherwise BreadcrumbPage */} Application Name {/* When an object is open: {objectName} */} {/* Updated 3 hours ago */} {/* Middle — optional Tabs (routes) OR Segmented control (modes); size small; omit if unused */} {/* */} {/* Right — fixed order: Share → Notifications → Theme → Atlas → user Avatar */} void api.sendAgentLayoutMode({ mode: 'sidebar' })} // see integrate-fusion-agent > Atlas {userInitials}
{children}
); } ``` Drop the controls the app does not need (Share, Notifications) — keep the order for the ones that remain. **Layout wrapper:** The parent element must allow the Topbar to be full-width and sticky: ```tsx
{/* page content — primary actions for the current screen live here */}
``` --- ## Additional resources - Full Topbar architecture rules: [RULES.md](RULES.md) - Atlas wiring (`sendAgentLayoutMode`, context): `integrate-fusion-agent` - Aura package README (import paths, stylesheet setup): `@cognite/aura` on npm - Flows community components: https://cognitedata.github.io/flows-community-components/