learning_ai_common_plat/packages/dashboard-shell/src/TopBar.tsx
saravanakumardb1 f1ebff5514 feat(scripts+ui): Tier 2 complete \u2014 common_plat 0 hex findings (was 59)
Scanner refinements:
- Exclude services/<svc>/src/        (Fastify backends, not UI)
- Exclude packages/config/           (schema/defaults, not UI)
- Exclude packages/devops/           (internal tooling)
- Exclude packages/create-app/.../templates (scaffolder templates)
- Exclude *.storybook/, /stories/, *.stories.{ts,tsx} (demo/docs)
- Exclude SVG fill=, stroke= hex (brand-mandated, e.g. Google G logo)
- Exclude ThemeEditor.tsx, theme-defaults.* (their content IS hex)
- Exclude /api/themes/ routes (server-side defaults)

Source fixes in shared packages (high leverage \u2014 consumed by every product):
- packages/auth-ui/src/*Form*.tsx + OnboardingShell + MfaChallenge (7)
- packages/dashboard-shell/src/{TopBar,ProfilePage}.tsx (3)
- dashboards/tracker-web/src/app/health/page.tsx (6)

All use the canonical var(--bl-<token>, #fallback) pattern that:
- Lets product themes override (e.g., each product sets --bl-danger differently)
- Falls back to a sensible default if tokens haven't loaded yet (defensive)

common_plat hex: 59 \u2192 0 \u2713 (Tier 2 complete)
Ecosystem total: 1569 \u2192 1402

Tier progress:
  Tier 1 (critical):       13 \u2192 0 \u2713
  Tier 2 (common_plat hex): 59 \u2192 0 \u2713
  Tier 3 (mac_tooling, efforise): NEXT
  Tier 4 (mindlyst, fastgap, flowmonk)
  Tier 5 (non-hex rules)
2026-05-23 14:37:51 -07:00

245 lines
7.5 KiB
TypeScript

import { useState, type ReactNode } from 'react';
import type { TopBarProps } from './types.js';
export function TopBar({
user,
features = {},
onSignOut,
onNavigate,
actions,
onToggleSidebar,
}: TopBarProps): ReactNode {
const [menuOpen, setMenuOpen] = useState(false);
const handleNav = (href: string) => {
setMenuOpen(false);
if (onNavigate) onNavigate(href);
};
const initials = user
? user.name
.split(' ')
.map(w => w[0])
.join('')
.toUpperCase()
.slice(0, 2)
: '?';
return (
<header
data-testid="bl-shell-topbar"
style={{
height: 56,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
padding: '0 24px',
borderBottom: '1px solid var(--bl-shell-border, var(--color-border, #e5e7eb))',
background: 'var(--bl-shell-topbar-bg, var(--color-surface, #fff))',
flexShrink: 0,
}}
>
{/* Left: mobile hamburger */}
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
{onToggleSidebar && (
<button
data-testid="bl-shell-hamburger"
onClick={onToggleSidebar}
style={{
background: 'none',
border: 'none',
cursor: 'pointer',
fontSize: 20,
padding: 4,
color: 'var(--bl-shell-nav-text, var(--color-muted-foreground, #6b7280))',
}}
aria-label="Toggle sidebar"
>
</button>
)}
</div>
{/* Right: actions + user menu */}
<div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
{actions}
{features.notifications && (
<button
data-testid="bl-shell-notifications"
style={{
background: 'none',
border: 'none',
cursor: 'pointer',
fontSize: 18,
padding: 4,
color: 'var(--bl-shell-nav-text, var(--color-muted-foreground, #6b7280))',
}}
aria-label="Notifications"
>
🔔
</button>
)}
{user && (
<div style={{ position: 'relative' }}>
<button
data-testid="bl-shell-user-menu-trigger"
onClick={() => setMenuOpen(!menuOpen)}
style={{
display: 'flex',
alignItems: 'center',
gap: 8,
background: 'none',
border: 'none',
cursor: 'pointer',
padding: '4px 8px',
borderRadius: 8,
}}
>
{user.avatarUrl ? (
<img
src={user.avatarUrl}
alt={user.name}
style={{ width: 32, height: 32, borderRadius: '50%' }}
/>
) : (
<div
data-testid="bl-shell-user-avatar"
style={{
width: 32,
height: 32,
borderRadius: '50%',
background: 'var(--bl-shell-accent, var(--color-primary, #2563eb))',
color: 'var(--bl-accent-foreground, #fff)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 13,
fontWeight: 600,
}}
>
{initials}
</div>
)}
<span
style={{
fontSize: 14,
color: 'var(--color-foreground, #111827)',
}}
>
{user.name}
</span>
<span style={{ fontSize: 10 }}></span>
</button>
{menuOpen && (
<div
data-testid="bl-shell-user-menu"
style={{
position: 'absolute',
right: 0,
top: '100%',
marginTop: 4,
minWidth: 180,
background: 'var(--bl-shell-topbar-bg, var(--color-surface, #fff))',
border: '1px solid var(--bl-shell-border, var(--color-border, #e5e7eb))',
borderRadius: 8,
boxShadow: '0 4px 12px rgba(0,0,0,0.1)',
zIndex: 50,
overflow: 'hidden',
}}
>
<div
style={{
padding: '12px 16px',
borderBottom: '1px solid var(--bl-shell-border, var(--color-border, #e5e7eb))',
}}
>
<div style={{ fontSize: 14, fontWeight: 600 }}>{user.name}</div>
<div style={{ fontSize: 12, color: 'var(--color-muted-foreground, #6b7280)' }}>
{user.email}
</div>
</div>
{features.profile !== false && (
<a
data-testid="bl-shell-menu-profile"
href="/profile"
onClick={e => {
e.preventDefault();
handleNav('/profile');
}}
style={menuItemStyle}
>
Profile
</a>
)}
{features.billing && (
<a
data-testid="bl-shell-menu-billing"
href="/billing"
onClick={e => {
e.preventDefault();
handleNav('/billing');
}}
style={menuItemStyle}
>
Billing
</a>
)}
{features.settings !== false && (
<a
data-testid="bl-shell-menu-settings"
href="/settings"
onClick={e => {
e.preventDefault();
handleNav('/settings');
}}
style={menuItemStyle}
>
Settings
</a>
)}
{onSignOut && (
<button
data-testid="bl-shell-menu-signout"
onClick={() => {
setMenuOpen(false);
onSignOut();
}}
style={{
...menuItemStyle,
width: '100%',
textAlign: 'left',
borderTop: '1px solid var(--bl-shell-border, var(--color-border, #e5e7eb))',
color: 'var(--color-destructive, #dc2626)',
background: 'none',
border: 'none',
borderTopStyle: 'solid',
borderTopWidth: 1,
borderTopColor: 'var(--bl-shell-border, var(--color-border, #e5e7eb))',
}}
>
Sign Out
</button>
)}
</div>
)}
</div>
)}
</div>
</header>
);
}
const menuItemStyle: React.CSSProperties = {
display: 'block',
padding: '10px 16px',
fontSize: 14,
color: 'var(--color-foreground, #111827)',
textDecoration: 'none',
cursor: 'pointer',
};