Files
PaperClipAI/ui/src/components/SidebarNavItem.tsx
T
7b9334cd10 Draft: Build agent-ready design proposal system (#16875)
## Thinking Path

> - Paperclip helps people manage AI agents and their work.
> - People need consistent UI patterns to review and control that work.
> - The current board uses related layouts and controls with different
spacing, type, and behavior.
> - That drift makes it hard for a designer or an agent to build a new
page from a reliable reference.
> - Storybook can show the shared patterns and the states they need to
support.
> - This pull request adds design proposals, a local sandbox, and
reusable UI controls so people can compare the patterns in context.
> - The benefit is a clearer design system that agents can use to build
consistent UI.

## Linked Issues or Issue Description

**Subsystem affected**

`ui/` — React board UI and Storybook.

**Problem or motivation**

Board pages repeat visual and interaction decisions. Storybook did not
provide a complete reference for task views, conversation states,
typography, toolbars, tabs, and light/dark colors. People could not
compare a proposed pattern with the running board in one place.

**Proposed solution**

Add a staged Design Proposals catalog with foundations, components,
layouts, and page specimens. Add an opt-in sandbox. Reuse production
components where possible. Include synthetic conversation states and
shared controls so reviewers can compare and refine them.

**Alternatives considered**

Separate static mockups would not show keyboard behavior, responsive
layout, or real component states. Rebuilding each page only in Storybook
would allow the reference to drift from the board.

**Roadmap alignment**

This improves existing board UI and Skills Manager surfaces. It does not
add a new control-plane capability.

## What Changed

- Added dark and light color references, typography and conversation
specimens, and component stories for buttons, tabs, toolbars, sidebar,
popovers, activity, and task lists.
- Added a local design sandbox with synthetic task conversation playback
and representative states.
- Shared collection toolbars and navigation patterns across task, agent,
project, routine, skill, connector, and artifact pages.
- Added the streamlined Skills tabs and a My Skills collection that uses
the shared skill cards.
- Restored saved-thread access during synthetic playback, kept connector
searchbox semantics, and updated reproduction checks after moving trial
stories.
- Documented the proposed patterns and added focused UI, catalog, and
browser checks.

## Verification

- `pnpm check:token-gates`, `node scripts/check-maps.mjs`, and `node
scripts/storybook-catalog.mjs --check` passed.
- Full workspace `pnpm -r typecheck` and `pnpm build` passed after
merging master. After the review fixes, focused UI typecheck, `pnpm
build-storybook`, 23 Skills Sources tests, and all 15 Storybook
typography browser tests passed.
- Focused task-thread and system-notice suites passed: 251 tests.
Connector Browse passed 84 tests; the connector, attachment, recovery,
and Storybook flyout browser journeys passed locally.
- A local full Vitest run hit one intermittent chat-channels integration
failure; that test passed in isolation. GitHub CI
[39347996059](https://github.com/paperclipai/paperclip/actions/runs/39347996059)
passed on the exact latest commit: 55 successful checks and two skipped
draft-only Storybook jobs.
- Greptile reviewed the exact latest commit at 5/5 with no new comments
or open review threads. GitHub reports the branch as cleanly mergeable.

## Risks

- This PR changes 206 files and exceeds the repository's 100-file review
target. Review by commit and consider a scoped split before merge.
- Design Proposals are staged references. Fixture interactions do not
prove API behavior, permissions, or provider execution.
- UI changes to shared controls may affect pages outside the proposal
sandbox. Focused browser checks and the full CI matrix passed.

## Model Used

- OpenAI Codex, GPT-6 family. The exact runtime model ID and context
window are not exposed in this session. The model used reasoning, code
execution, browser inspection, and local tests. Earlier branch commits
were also AI-assisted in this Codex conversation.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details available in this session)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above where applicable
- [x] I have either linked existing issues or described the issue in-PR
following the relevant issue template
- [x] I have not referenced internal or instance-local Paperclip issues
or links
- [x] My branch name describes the change and contains no internal
ticket id
- [x] I have run focused tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Scott Tong <scott@scotts-mbp-m5-max.local>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-19 17:45:26 -07:00

233 lines
8.8 KiB
TypeScript

import { createContext, useContext, type ReactNode } from "react";
import { NavLink } from "@/lib/router";
import { SIDEBAR_SCROLL_RESET_STATE } from "../lib/navigation-scroll";
import { cn, SIDEBAR_RAIL_HIDDEN_LABEL } from "../lib/utils";
import { useSidebar } from "../context/SidebarContext";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import type { LucideIcon } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { TruncatedText } from "./TruncatedText";
/**
* Forces the full-label (non-rail) presentation for any `SidebarNavItem`
* rendered beneath it, regardless of the global `useSidebar().collapsed` state.
*
* Contextual takeover routes replace the global navigation inside the same
* sidebar shell. The user's saved global collapse preference can still be
* `collapsed=true`, so this provider keeps contextual navigation readable
* without mutating that preference.
*/
const SidebarNavExpandedContext = createContext(false);
export function SidebarNavExpandedProvider({ children }: { children: ReactNode }) {
return (
<SidebarNavExpandedContext.Provider value={true}>
{children}
</SidebarNavExpandedContext.Provider>
);
}
export function useSidebarNavExpanded() {
return useContext(SidebarNavExpandedContext);
}
interface SidebarNavItemProps {
to: string;
label: string;
icon?: LucideIcon;
/**
* Pre-rendered icon element for rows whose icon isn't a plain Lucide
* component (e.g. the agent rows' `AgentIcon`). Takes precedence over `icon`;
* the caller owns its sizing/color classes.
*/
iconNode?: ReactNode;
end?: boolean;
className?: string;
labelClassName?: string;
badge?: number;
badgeTone?: "default" | "danger" | "warning";
/**
* Accessible noun for the numeric badge when collapsed to the rail, where the
* count is rendered as a dot (e.g. `badgeLabel="unread"` → "Inbox, 28 unread").
*/
badgeLabel?: string;
textBadge?: string;
textBadgeTone?: "default" | "amber";
alert?: boolean;
liveCount?: number;
/**
* Overrides NavLink's own route matching for rows whose active state is
* computed externally (agent rows match `/agents/:ref` across tab suffixes).
*/
active?: boolean;
/** Rendered after the label, before the right-aligned status cluster. */
trailing?: ReactNode;
/** Accessible text for `trailing` status content, surfaced in the collapsed rail (where `trailing` is hidden). */
trailingLabel?: string;
/** Rendered inside the right-aligned status cluster, before the live dot. */
liveAccessory?: ReactNode;
}
export function SidebarNavItem({
to,
label,
icon: Icon,
iconNode,
end,
className,
labelClassName,
badge,
badgeTone = "default",
badgeLabel,
textBadge,
textBadgeTone = "default",
alert = false,
liveCount,
active,
trailing,
trailingLabel,
liveAccessory,
}: SidebarNavItemProps) {
const { isMobile, setSidebarOpen, collapsed, peeking } = useSidebar();
// A contextual takeover forces full labels even when the saved global app
// sidebar preference is collapsed.
const forceExpanded = useSidebarNavExpanded();
// The icon-only rail presentation only applies when pinned collapsed and not
// peeking; a peek/expanded panel — or a contextual takeover — restores
// the full label + badge.
const rail = collapsed && !peeking && !forceExpanded;
const hasBadge = badge != null && badge > 0;
const hasLive = liveCount != null && liveCount > 0;
const showIconSlot = Boolean(iconNode || Icon || alert || (rail && (hasLive || hasBadge)));
// Accessible text equivalent for the collapsed dot indicator. The visible
// label is `sr-only` in the rail, so the count must be surfaced here.
const railStatusText = hasLive
? `${liveCount} live`
: hasBadge
? `${badge}${badgeLabel ? ` ${badgeLabel}` : ""}`
: alert
? "attention needed"
: undefined;
const railAriaLabel = !rail || (!railStatusText && !trailingLabel)
? undefined
: `${label}${railStatusText ? `, ${railStatusText}` : ""}${trailingLabel ? `, ${trailingLabel}` : ""}`;
const link = (
<NavLink
to={to}
state={SIDEBAR_SCROLL_RESET_STATE}
end={end}
aria-label={railAriaLabel}
onClick={() => { if (isMobile) setSidebarOpen(false); }}
className={({ isActive }) =>
cn(
// One rhythm and one inset pill highlight: mx-2 floats the row off
// the sidebar edges, rounded-lg matches the card anchor, px-2 gives
// the icon breathing room inside the pill. Rows with hover menus
// (agents/projects) reserve extra right padding via className.
"flex items-center gap-2.5 mx-2 rounded-lg px-2 py-1.5 pointer-coarse:py-1 text-(length:--text-compact) font-medium transition-colors",
(active ?? isActive)
? "bg-sidebar-accent text-sidebar-accent-foreground"
: "text-foreground/80 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
className,
)
}
>
{showIconSlot ? (
<span data-slot="sidebar-nav-icon" className="relative shrink-0">
{iconNode ?? (Icon ? <Icon className="h-4 w-4" /> : null)}
{alert && (
<span
data-slot="sidebar-icon-alert-badge"
className="absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-red-500 shadow-(--shadow-sidebar-icon-badge)"
aria-hidden="true"
/>
)}
{/* Collapsed rail: numeric badge / live count collapse to a dot on the
icon. The icon markup is untouched so it stays pixel-aligned. */}
{rail && !alert && hasLive && (
<span className="absolute -right-0.5 -top-0.5 flex h-2 w-2" aria-hidden="true">
<span className="animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-600 dark:bg-blue-400 opacity-75" />
<span className="relative inline-flex h-2 w-2 rounded-full bg-blue-600 dark:bg-blue-400 shadow-(--shadow-sidebar-icon-badge)" />
</span>
)}
{rail && !alert && !hasLive && hasBadge && (
<span
className={cn(
"absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full shadow-(--shadow-sidebar-icon-badge)",
badgeTone === "danger"
? "bg-red-600"
: badgeTone === "warning"
? "bg-amber-500"
: "bg-primary",
)}
aria-hidden="true"
/>
)}
</span>
) : null}
<TruncatedText className={rail ? SIDEBAR_RAIL_HIDDEN_LABEL : cn("min-w-0 flex-1 truncate", labelClassName)}>{label}</TruncatedText>
{!rail && trailing}
{!rail && textBadge && (
<Badge variant="ghost"
className={cn(
"ml-auto px-1.5 text-(length:--text-nano) leading-none",
textBadgeTone === "amber"
? "bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-400"
: "bg-muted text-muted-foreground",
)}
>
{textBadge}
</Badge>
)}
{!rail && (hasLive || liveAccessory) && (
<span className="ml-auto flex shrink-0 items-center gap-1.5 whitespace-nowrap">
{liveAccessory}
{hasLive && (
<>
<span className="relative flex h-2 w-2">
<span className="animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-600 dark:bg-blue-400 opacity-75" />
<span className="relative inline-flex rounded-full h-2 w-2 bg-blue-600 dark:bg-blue-400" />
</span>
<span className="text-(length:--text-micro) font-medium text-blue-600 dark:text-blue-400">{liveCount} live</span>
</>
)}
</span>
)}
{!rail && hasBadge && (
<Badge variant="ghost"
className={cn(
"ml-auto px-1.5 leading-none",
badgeTone === "danger"
? "bg-red-600/90 text-red-50"
: badgeTone === "warning"
? "bg-amber-500/90 text-amber-50"
: "bg-primary text-primary-foreground",
)}
>
{badge}
</Badge>
)}
</NavLink>
);
if (!rail) return link;
// The tooltip wraps a plain block element rather than the NavLink directly:
// Radix `asChild` (Slot) drops React Router's *function* className, which would
// strip `flex` off the <a> and render it as a block — the in-flow label would
// then stack under the icon and the row would grow. Anchoring the tooltip to a
// wrapper keeps the <a> rendering normally (flex), so the row stays 1:1 with
// the expanded state and the icon never moves (PAP-10676).
return (
<Tooltip>
<TooltipTrigger asChild>
<div>{link}</div>
</TooltipTrigger>
<TooltipContent side="right">{label}</TooltipContent>
</Tooltip>
);
}