refactor: extract <ScrollAffordance> from four duplicate chevron sites

The mobile right-edge chevron pattern (relative wrapper + absolute
pointer-events-none ChevronRight + drop-shadow halo + sm:hidden) had
grown copy-pasted across four scroll surfaces in four sessions:
- Today SummaryBar (4cb018c)
- Settings tab strip (7ab36d6)
- Projects status filter chips (0523927)
- Prompts CategoryBar (a017df8)

Each call site had reinvented the same JSX with minor threshold
variations. Adding a fifth surface meant copy-pasting again — and
any tweak to the chevron icon, drop-shadow, or threshold semantics
would need touching four files.

Extract src/components/ui/scroll-affordance.tsx — a layout-only
wrapper that takes children + childCount + optional threshold (default 4).
Caller still owns the scroll container's overflow/fade classes; the
component only contributes the relative wrapper + conditional chevron.

Behavior is preserved at every site:
- Skeleton SummaryBar: childCount={0} (no chevron, matches old)
- Real SummaryBar: childCount={totalChipCount} threshold={3}
- Settings tabs: childCount={TABS.length} threshold={4}
- Projects status chips: childCount={statuses.length} threshold={4}
- Prompts categories: childCount={visibleCats.length+1} threshold={4}

Settings outer wrapper keeps its border-bottom so the underline spans
full width even when the inner scroll container is scrolled. No
imports lost; lucide-react ChevronRight now imported in exactly one
place (the new component).
This commit is contained in:
g-but committed 2026-05-31 03:51:00 +02:00
1 parent a017df89fa
commit 042972801d
5 files changed
+78 -77

No files matched your search

+4 -15
View File
@@ -2,7 +2,8 @@
import { useState, useMemo } from "react";
import { useSearchParams } from "next/navigation";
import { ArrowRight, GitBranch, Globe, ShieldAlert, AlertTriangle, Search, X, ChevronRight } from "lucide-react";
import { ArrowRight, GitBranch, Globe, ShieldAlert, AlertTriangle, Search, X } from "lucide-react";
import { ScrollAffordance } from "@/components/ui/scroll-affordance";
import { IvyDispatchButton } from "@/components/shared/IvyDispatchButton";
import { useEscapeKey } from "@/hooks/use-escape-key";
import { ProjectDetail } from "./ProjectDetail";
@@ -247,7 +248,7 @@ export function ProjectGrid({ projects }: { projects: Project[] }) {
</div>
{statuses.length > 1 && (
<div className="relative">
<ScrollAffordance childCount={statuses.length} threshold={4}>
<div className="flex gap-1.5 overflow-x-auto ui-scroll-fade-right [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden sm:flex-wrap sm:overflow-x-visible">
{statuses.map((s) => (
<button
@@ -265,19 +266,7 @@ export function ProjectGrid({ projects }: { projects: Project[] }) {
</button>
)}
</div>
{/* Mobile-only scroll affordance — third horizontal-scroll surface
after Today SummaryBar (4cb018c) and Settings tab strip
(7ab36d6). 4+ status chips reliably overflow at 414px and the
ui-scroll-fade-right mask alone is too subtle on iOS. */}
{statuses.length >= 4 && (
<span
aria-hidden
className="pointer-events-none absolute inset-y-0 right-0 z-10 flex items-center pr-1 text-text-tertiary sm:hidden"
>
<ChevronRight className="h-4 w-4 drop-shadow-[0_0_4px_var(--surface-page)]" />
</span>
)}
</div>
</ScrollAffordance>
)}
{withIssues.length > 0 && (
+3 -18
View File
@@ -1,7 +1,7 @@
"use client";
import { ChevronRight } from "lucide-react";
import { cn } from "@/lib/utils";
import { ScrollAffordance } from "@/components/ui/scroll-affordance";
import { ALL_CATEGORIES, CATEGORY_META, type PromptCategory, type PromptTemplate } from "@/config/prompt-library";
/** Filter chips: "All (n)" + one chip per category that has at least one template. */
@@ -19,15 +19,8 @@ export function CategoryBar({
);
const visibleCats = ALL_CATEGORIES.filter((cat) => (counts.get(cat) ?? 0) > 0);
// Fourth horizontal-scroll surface in this codebase needing a mobile
// affordance — Today SummaryBar (4cb018c), Settings tab strip (7ab36d6),
// Projects status chips (0523927), now Prompts categories. Same pattern:
// ui-scroll-fade-right mask + ChevronRight pinned to the right edge of
// the relative wrapper, hidden on sm+ where chips wrap. Adds the fade
// mask that was previously missing here too. Threshold of 4 chips
// matches the pattern (1 All + 4 categories ≈ first overflow point).
return (
<div className="relative">
<ScrollAffordance childCount={visibleCats.length + 1} threshold={4}>
<div className="flex gap-2 overflow-x-auto ui-scroll-fade-right [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden sm:flex-wrap sm:overflow-x-visible">
<button
onClick={() => onSelect("all")}
@@ -52,14 +45,6 @@ export function CategoryBar({
);
})}
</div>
{visibleCats.length >= 3 && (
<span
aria-hidden
className="pointer-events-none absolute inset-y-0 right-0 z-10 flex items-center pr-1 text-text-tertiary sm:hidden"
>
<ChevronRight className="h-4 w-4 drop-shadow-[0_0_4px_var(--surface-page)]" />
</span>
)}
</div>
</ScrollAffordance>
);
}
+19 -25
View File
@@ -1,7 +1,7 @@
"use client";
import { useState, Suspense } from "react";
import { ChevronRight } from "lucide-react";
import { ScrollAffordance } from "@/components/ui/scroll-affordance";
import { ProfileSettings } from "./ProfileSettings";
import { AccountSettings } from "./AccountSettings";
import { LocationSettings } from "./LocationSettings";
@@ -76,31 +76,25 @@ export function SettingsTabs({ user, userPrefs, projects, teamProjects, projectL
return (
<div>
{/* Tab nav — relative wrapper so the mobile scroll-affordance chevron
sits outside the ui-scroll-fade-right mask. Same pattern as the
Today SummaryBar fix (4cb018c): 7-tab strip reliably overflows at
414px and the fade alone is too subtle on iOS where native
scrollbars hide at rest. */}
<div className="relative border-b border-border-subtle -mx-4 px-4 mb-6">
<div className="overflow-x-auto ui-scroll-fade-right [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden">
<div className="flex min-w-max">
{TABS.map((tab) => (
<button
key={tab.id}
onClick={() => setActiveTab(tab.id)}
className={`ui-tab ${activeTab === tab.id ? "ui-tab-active" : ""}`}
>
{tab.label}
</button>
))}
{/* Tab nav — ScrollAffordance handles the mobile chevron-outside-fade
pattern. The outer border + horizontal padding/margin stay on the
wrapper so the border-bottom spans the full width even when scrolled. */}
<div className="border-b border-border-subtle -mx-4 px-4 mb-6">
<ScrollAffordance childCount={TABS.length} threshold={4}>
<div className="overflow-x-auto ui-scroll-fade-right [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden">
<div className="flex min-w-max">
{TABS.map((tab) => (
<button
key={tab.id}
onClick={() => setActiveTab(tab.id)}
className={`ui-tab ${activeTab === tab.id ? "ui-tab-active" : ""}`}
>
{tab.label}
</button>
))}
</div>
</div>
</div>
<span
aria-hidden
className="pointer-events-none absolute inset-y-0 right-0 z-10 flex items-center pr-1 text-text-tertiary sm:hidden"
>
<ChevronRight className="h-4 w-4 drop-shadow-[0_0_4px_var(--surface-page)]" />
</span>
</ScrollAffordance>
</div>
{/* Tab content */}
+6 -19
View File
@@ -1,4 +1,5 @@
import { Target, Bell, Inbox, AlertCircle, Clock, Calendar, Users, Repeat2, Bot, Activity, CirclePause, ChevronRight } from "lucide-react";
import { Target, Bell, Inbox, AlertCircle, Clock, Calendar, Users, Repeat2, Bot, Activity, CirclePause } from "lucide-react";
import { ScrollAffordance } from "@/components/ui/scroll-affordance";
import Link from "next/link";
import { IvyDispatchButton } from "@/components/shared/IvyDispatchButton";
import { getTodaySummary, getFleetSummary } from "@/db/queries/today";
@@ -9,7 +10,7 @@ import { APP_LOCALE } from "@/lib/constants";
export function SummaryBarSkeleton() {
const widths = ["5rem", "7rem", "6rem", "5rem", "5rem"];
return (
<div className="relative">
<ScrollAffordance childCount={0}>
<div className="flex gap-3 overflow-x-auto ui-scroll-fade-right [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden sm:flex-wrap sm:overflow-x-visible">
{widths.map((w, i) => (
<div
@@ -19,7 +20,7 @@ export function SummaryBarSkeleton() {
/>
))}
</div>
</div>
</ScrollAffordance>
);
}
@@ -88,23 +89,10 @@ export async function SummaryBar() {
<span aria-hidden className="hidden sm:inline-block h-6 w-px bg-border-subtle self-center mx-1" />
);
// Mobile-only scroll affordance: a small chevron pinned to the right edge
// tells the user "more chips this way." ui-scroll-fade-right alone is too
// subtle on iOS (native scrollbars hide at rest). pointer-events-none so
// it never blocks a chip tap underneath. Hidden on sm+ where chips wrap.
const scrollHint = (
<span
aria-hidden
className="pointer-events-none absolute inset-y-0 right-0 z-10 flex items-center pr-1 text-text-tertiary sm:hidden"
>
<ChevronRight className="h-4 w-4 drop-shadow-[0_0_4px_var(--surface-page)]" />
</span>
);
const totalChipCount = counters.length + alerts.length + fleetPills.length;
return (
<div className="relative">
<ScrollAffordance childCount={totalChipCount} threshold={3}>
<div className="flex gap-3 overflow-x-auto ui-scroll-fade-right [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden sm:flex-wrap sm:overflow-x-visible">
{counters}
{counters.length > 0 && (alerts.length > 0 || fleetPills.length > 0) && divider}
@@ -119,8 +107,7 @@ export async function SummaryBar() {
className="inline-flex items-center gap-1.5 rounded-full border border-status-positive/30 bg-status-positive-subtle/40 px-3 py-2 text-xs font-semibold text-status-positive hover:bg-status-positive-subtle transition-colors min-h-11 sm:min-h-0 shrink-0"
/>
</div>
{totalChipCount >= 3 && scrollHint}
</div>
</ScrollAffordance>
);
}
+46
View File
@@ -0,0 +1,46 @@
import { ChevronRight } from "lucide-react";
/**
* Wraps a horizontal-scroll row (chip strip, tab strip, filter row) and adds
* a mobile-only right-edge ChevronRight + fade mask so the user knows there's
* more content past the visible viewport. Hidden on sm+ where the row is
* expected to wrap naturally.
*
* Extracted from four duplicate call sites (Today SummaryBar, Settings tab
* strip, Projects status chips + banner, Prompts CategoryBar) where the same
* `relative wrapper + absolute pointer-events-none chevron + drop-shadow halo`
* pattern had grown copy-pasted with subtle threshold variations.
*
* The chevron only shows when `childCount >= threshold` so single-chip or
* single-tab rows don't get a misleading "scroll for more" cue.
*
* Callers own the scroll container and its overflow / fade classes — this
* component is layout-only and doesn't mandate which scrollbar-hide or
* fade-mask classes the caller uses.
*/
export function ScrollAffordance({
children,
childCount,
threshold = 4,
}: {
/** The scroll container — caller controls overflow + scrollbar-hide + fade. */
children: React.ReactNode;
/** Count of items in the row (chips/tabs/etc.); affordance hides when low. */
childCount: number;
/** Min children before showing the chevron. Default 4 ≈ ~414px overflow. */
threshold?: number;
}) {
return (
<div className="relative">
{children}
{childCount >= threshold && (
<span
aria-hidden
className="pointer-events-none absolute inset-y-0 right-0 z-10 flex items-center pr-1 text-text-tertiary sm:hidden"
>
<ChevronRight className="h-4 w-4 drop-shadow-[0_0_4px_var(--surface-page)]" />
</span>
)}
</div>
);
}