Skip to content

Commit cac9798

Browse files
fix(web,mobile): Limits bars show the even-pace mark as a tick in a gap
The even-pace mark was a thin line that disappeared on foreground-coloured fills and spilled past the bar at 0% and 100%. Every Limits bar (web and mobile rows, web and mobile pooled segments) now cuts a 6px transparent gap through track and fill with an opaque 2px tick inside it, clamped 3px from each end. Unknown timing still draws no mark. Rows reuse #16937's rendering. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 573d376 commit cac9798

5 files changed

Lines changed: 248 additions & 61 deletions

File tree

‎apps/mobile/src/features/usage/UsageLimitsPooled.tsx‎

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,53 @@ function accountName(account: LimitAccount) {
4141
return `${local[0] ?? ""}${domain[0] ?? ""}`.toUpperCase() || "Account";
4242
}
4343

44+
// Same gap-and-tick as the Limits rows: two clipped copies of the segment leave a see-through gap.
45+
function PaceGap({
46+
timeLeft,
47+
children,
48+
}: {
49+
readonly timeLeft: number | null;
50+
readonly children: ReactNode;
51+
}) {
52+
const [width, setWidth] = useState(0);
53+
const tickX =
54+
timeLeft === null || width < 6
55+
? null
56+
: Math.min(Math.max((width * timeLeft) / 100, 3), width - 3);
57+
return (
58+
<View
59+
pointerEvents="none"
60+
className="absolute inset-0"
61+
onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
62+
>
63+
{tickX === null
64+
? children
65+
: (
66+
[
67+
[0, tickX - 3],
68+
[tickX + 3, width],
69+
] as const
70+
).map(([start, end]) => (
71+
<View
72+
key={start}
73+
className="absolute top-0 bottom-0 overflow-hidden"
74+
style={{ left: start, width: end - start }}
75+
>
76+
<View className="absolute top-0 bottom-0" style={{ left: -start, width }}>
77+
{children}
78+
</View>
79+
</View>
80+
))}
81+
{tickX !== null ? (
82+
<View
83+
className="absolute top-0.5 bottom-0.5 w-0.5 rounded-full bg-foreground"
84+
style={{ left: tickX - 1 }}
85+
/>
86+
) : null}
87+
</View>
88+
);
89+
}
90+
4491
function AccountSegment({
4592
remaining,
4693
color,
@@ -155,22 +202,18 @@ function PoolWindowCard({
155202
accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}`}
156203
accessibilityHint="Show account details"
157204
onPress={() => openAccount(account)}
158-
className="h-7 min-w-0 flex-1 rounded-md bg-subtle"
205+
className="h-7 min-w-0 flex-1 rounded-md"
159206
>
160-
<View className="absolute inset-0 overflow-hidden rounded-md">
161-
<AccountSegment
162-
remaining={remainingPercent(window)}
163-
color={color}
164-
refillPercent={window.resetsAt ? member.refillPercent : 0}
165-
/>
166-
</View>
167-
{timeLeft !== null ? (
168-
<View
169-
pointerEvents="none"
170-
className="absolute -top-1 -bottom-1 w-0.5 -translate-x-px rounded-full bg-foreground-muted"
171-
style={{ left: `${timeLeft}%` }}
172-
/>
173-
) : null}
207+
<PaceGap timeLeft={timeLeft}>
208+
<View className="absolute inset-0 rounded-md bg-subtle" />
209+
<View className="absolute inset-0 overflow-hidden rounded-md">
210+
<AccountSegment
211+
remaining={remainingPercent(window)}
212+
color={color}
213+
refillPercent={window.resetsAt ? member.refillPercent : 0}
214+
/>
215+
</View>
216+
</PaceGap>
174217
<View
175218
pointerEvents="none"
176219
className="absolute inset-0 items-center justify-center overflow-hidden rounded-md"

‎apps/mobile/src/features/usage/UsageLimitsSection.tsx‎

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,32 @@ function WindowRow(props: {
4949
const timeLeft = paceRemainingPercent(window, now);
5050
const pace = paceOf(window, now);
5151
const resetsIn = formatResetsIn(window, now);
52+
const [barWidth, setBarWidth] = useState(0);
53+
const tickX =
54+
timeLeft === null || barWidth < 6
55+
? null
56+
: Math.min(Math.max((barWidth * timeLeft) / 100, 3), barWidth - 3);
57+
const bar = (
58+
<View
59+
className="h-1.5 flex-row overflow-hidden rounded-full bg-subtle"
60+
style={barWidth > 0 ? { width: barWidth } : undefined}
61+
>
62+
<View
63+
className={
64+
remaining <= 10
65+
? "h-full rounded-full bg-red-500"
66+
: remaining <= 30
67+
? "h-full rounded-full bg-amber-500"
68+
: "h-full rounded-full bg-foreground"
69+
}
70+
style={[
71+
{ flex: remaining },
72+
remaining > 30 && props.color ? { backgroundColor: props.color } : null,
73+
]}
74+
/>
75+
<View style={{ flex: 100 - remaining }} />
76+
</View>
77+
);
5278
return (
5379
<View className="gap-1">
5480
<View className="flex-row items-baseline justify-between gap-3">
@@ -57,27 +83,35 @@ function WindowRow(props: {
5783
{remaining}% left
5884
</Text>
5985
</View>
60-
<View className="h-3 justify-center">
61-
<View className="h-1.5 flex-row overflow-hidden rounded-full bg-subtle">
62-
<View
63-
className={
64-
remaining <= 10
65-
? "h-full rounded-full bg-red-500"
66-
: remaining <= 30
67-
? "h-full rounded-full bg-amber-500"
68-
: "h-full rounded-full bg-foreground"
69-
}
70-
style={[
71-
{ flex: remaining },
72-
remaining > 30 && props.color ? { backgroundColor: props.color } : null,
73-
]}
74-
/>
75-
<View style={{ flex: 100 - remaining }} />
76-
</View>
77-
{timeLeft !== null ? (
86+
<View
87+
className="h-3 justify-center"
88+
onLayout={(event) => setBarWidth(event.nativeEvent.layout.width)}
89+
>
90+
{tickX === null ? (
91+
bar
92+
) : (
93+
<View className="h-1.5">
94+
{/* Clip the same full-width bar so neither fill proportions nor corner radii change. */}
95+
{(
96+
[
97+
[0, tickX - 3],
98+
[tickX + 3, barWidth],
99+
] as const
100+
).map(([start, end]) => (
101+
<View
102+
key={start}
103+
className="absolute top-0 bottom-0 overflow-hidden"
104+
style={{ left: start, width: end - start }}
105+
>
106+
<View style={{ marginLeft: -start }}>{bar}</View>
107+
</View>
108+
))}
109+
</View>
110+
)}
111+
{tickX !== null ? (
78112
<View
79-
className="absolute top-0 bottom-0 w-px bg-foreground"
80-
style={{ left: `${timeLeft}%`, opacity: 0.6 }}
113+
className="absolute top-px bottom-px w-0.5 rounded-full bg-foreground"
114+
style={{ left: tickX - 1 }}
81115
/>
82116
) : null}
83117
</View>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { ProviderDriverKind, type ServerProviderUsageWindow } from "@t3tools/contracts";
2+
import { act, type ReactNode } from "react";
3+
import { createRoot } from "react-dom/client";
4+
import { expect, it, vi } from "vite-plus/test";
5+
import { page } from "vite-plus/test/browser";
6+
7+
import "~/index.css";
8+
9+
vi.mock("../../state/session", () => ({
10+
useEnvironmentScope: () => true,
11+
readEnvironmentScope: () => true,
12+
}));
13+
vi.mock("../../state/server", () => ({ serverEnvironment: { consumeResetCredit: null } }));
14+
vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() }));
15+
vi.mock("../../hooks/useSettings", () => ({ usePrimarySettings: () => "24h" }));
16+
17+
import { LimitWindows } from "./UsageLimits";
18+
19+
const codex = ProviderDriverKind.make("codex");
20+
const now = Date.parse("2026-09-03T12:00:00Z");
21+
22+
async function render(ui: ReactNode) {
23+
const container = document.createElement("div");
24+
container.style.width = "640px";
25+
document.body.append(container);
26+
const root = createRoot(container);
27+
await act(async () => root.render(ui));
28+
return {
29+
[Symbol.asyncDispose]: async () => {
30+
await act(async () => root.unmount());
31+
container.remove();
32+
},
33+
};
34+
}
35+
36+
const sessionWindow = (minutesUntilReset: number | null): ServerProviderUsageWindow => ({
37+
id: "five_hour",
38+
kind: "session",
39+
label: "Session",
40+
usedPercent: 40,
41+
...(minutesUntilReset === null
42+
? {}
43+
: {
44+
windowDurationMins: 300,
45+
resetsAt: new Date(now + minutesUntilReset * 60_000).toISOString(),
46+
}),
47+
});
48+
49+
const tick = () => {
50+
const bar = page.getByRole("img", { name: /^Session:/ }).element();
51+
const mark = bar.querySelector(":scope > span[aria-hidden]");
52+
return { bar: bar.getBoundingClientRect(), mark: mark?.getBoundingClientRect() };
53+
};
54+
55+
it("places the even-pace tick at the share of the window left", async () => {
56+
await using _screen = await render(
57+
<LimitWindows driver={codex} windows={[sessionWindow(90)]} now={now} />,
58+
);
59+
const { bar, mark } = tick();
60+
expect(mark).toBeDefined();
61+
expect(mark!.left + mark!.width / 2 - bar.left).toBeCloseTo(bar.width * 0.3, 0);
62+
});
63+
64+
it("keeps the tick inside the bar at both ends of the window", async () => {
65+
for (const minutesUntilReset of [0, 300]) {
66+
await using _screen = await render(
67+
<LimitWindows driver={codex} windows={[sessionWindow(minutesUntilReset)]} now={now} />,
68+
);
69+
const { bar, mark } = tick();
70+
expect(mark!.left).toBeGreaterThanOrEqual(bar.left);
71+
expect(mark!.right).toBeLessThanOrEqual(bar.right);
72+
}
73+
});
74+
75+
it("shows no tick when the window timing is unknown", async () => {
76+
await using _screen = await render(
77+
<LimitWindows driver={codex} windows={[sessionWindow(null)]} now={now} />,
78+
);
79+
expect(tick().mark).toBeUndefined();
80+
});

‎apps/web/src/components/usage/UsageLimits.tsx‎

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@ export function PaceIcon({ pace }: { readonly pace: LimitPace }) {
7373
);
7474
}
7575

76+
// The tick sits in a transparent gap cut from the bar, clamped so it stays inside at 0% and 100%.
77+
// The gap is a clip-path slot rather than a mask: a mask composites its layer and re-antialiases
78+
// the bar's rounded ends, and the polygon reaches 1px past the box so only the slot edges clip.
79+
export function paceMarkStyles(timeLeft: number | null) {
80+
if (timeLeft === null) return null;
81+
const at = `clamp(3px, ${timeLeft}%, calc(100% - 3px))`;
82+
const [left, right] = [`calc(${at} - 3px)`, `calc(${at} + 3px)`];
83+
const [near, far] = ["-1px", "calc(100% + 1px)"];
84+
return {
85+
tick: { left: at },
86+
gap: {
87+
clipPath: `polygon(${near} ${near}, ${left} ${near}, ${left} ${far}, ${right} ${far}, ${right} ${near}, ${far} ${near}, ${far} ${far}, ${near} ${far})`,
88+
},
89+
// For a track painted on an element that also draws focus rings, which a clip would cut.
90+
gappedTrack: {
91+
backgroundColor: "transparent",
92+
backgroundImage: `linear-gradient(to right, var(--color-muted) ${left}, transparent ${left}, transparent ${right}, var(--color-muted) ${right})`,
93+
},
94+
};
95+
}
96+
7697
function WindowBar({
7798
color,
7899
window,
@@ -85,6 +106,7 @@ function WindowBar({
85106
const timestampFormat = usePrimarySettings((settings) => settings.timestampFormat);
86107
const remaining = remainingPercent(window);
87108
const timeLeft = paceRemainingPercent(window, now);
109+
const paceMark = paceMarkStyles(timeLeft);
88110
const resetsIn = formatResetsIn(window, now);
89111
const resetsAt = window.resetsAt
90112
? formatUpcomingTimestamp(window.resetsAt, timestampFormat, now)
@@ -105,18 +127,21 @@ function WindowBar({
105127
/>
106128
}
107129
>
108-
<div className="absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
109-
{remaining > 0 ? (
110-
<div
111-
className="absolute inset-y-1.5 left-0 rounded-full"
112-
style={{ width: `${remaining}%`, backgroundColor: color }}
113-
/>
114-
) : null}
115-
{timeLeft !== null ? (
130+
{/* Clip both layers so the gap exposes even a translucent composer surface. */}
131+
<div className="absolute inset-0" style={paceMark?.gap}>
132+
<div className="absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
133+
{remaining > 0 ? (
134+
<div
135+
className="absolute inset-y-1.5 left-0 rounded-full"
136+
style={{ width: `${remaining}%`, backgroundColor: color }}
137+
/>
138+
) : null}
139+
</div>
140+
{paceMark ? (
116141
<span
117142
aria-hidden
118-
className="absolute inset-y-0.5 w-px -translate-x-1/2 bg-foreground/60"
119-
style={{ left: `${timeLeft}%` }}
143+
className="absolute inset-y-1 w-0.5 -translate-x-1/2 rounded-full bg-foreground"
144+
style={paceMark.tick}
120145
/>
121146
) : null}
122147
</TooltipTrigger>

‎apps/web/src/components/usage/UsageLimitsPooled.tsx‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
PaceIcon,
4343
ResetCreditDialog,
4444
barColor,
45+
paceMarkStyles,
4546
resetCreditsSummary,
4647
useResetCredit,
4748
} from "./UsageLimits";
@@ -342,6 +343,7 @@ function SegmentTriggers({
342343
const payload: SegmentPayload = { account, window, reset, redeem };
343344
const remaining = remainingPercent(window);
344345
const timeLeft = paceRemainingPercent(window, now);
346+
const paceMark = paceMarkStyles(timeLeft);
345347
const resetsIn = formatResetsIn(window, now);
346348
const credits = account.limits.resetCredits?.availableCount ?? 0;
347349
return (
@@ -353,34 +355,37 @@ function SegmentTriggers({
353355
render={
354356
<button
355357
type="button"
356-
style={{ gridColumn: index, gridRow: 1 }}
358+
style={{ gridColumn: index, gridRow: 1, ...paceMark?.gappedTrack }}
357359
aria-label={`${account.displayName ?? (account.email ? accountInitials(account.email) : account.driver)}: ${remaining}% left${resetsIn ? `, ${resetsIn}` : ""}${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}${credits ? `, ${credits} reset ${credits === 1 ? "credit" : "credits"} banked` : ""}`}
358360
className="relative h-5 min-w-0 cursor-pointer rounded-md bg-muted text-start outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background data-[popup-open]:ring-1 data-[popup-open]:ring-inset data-[popup-open]:ring-border @2xl/pool:h-8"
359361
/>
360362
}
361363
>
362364
<div aria-hidden className="absolute inset-0 overflow-hidden rounded-md">
363-
<div
364-
aria-hidden
365-
className="absolute inset-y-0 left-0 rounded-md opacity-35"
366-
style={{ width: `${remaining}%`, backgroundColor: color }}
367-
/>
368-
{remaining < 100 && reset && refillPercent > 0 ? (
365+
{/* Clipped inside the rounded clip so the bar's own corners keep their antialiasing. */}
366+
<div className="absolute inset-0" style={paceMark?.gap}>
369367
<div
370368
aria-hidden
371-
className="absolute inset-y-0 right-0 opacity-20"
372-
style={{
373-
width: `${Math.min(100 - remaining, refillPercent)}%`,
374-
backgroundImage: `repeating-linear-gradient(135deg, ${color} 0 1px, transparent 1px 5px)`,
375-
}}
369+
className="absolute inset-y-0 left-0 rounded-md opacity-35"
370+
style={{ width: `${remaining}%`, backgroundColor: color }}
376371
/>
377-
) : null}
372+
{remaining < 100 && reset && refillPercent > 0 ? (
373+
<div
374+
aria-hidden
375+
className="absolute inset-y-0 right-0 opacity-20"
376+
style={{
377+
width: `${Math.min(100 - remaining, refillPercent)}%`,
378+
backgroundImage: `repeating-linear-gradient(135deg, ${color} 0 1px, transparent 1px 5px)`,
379+
}}
380+
/>
381+
) : null}
382+
</div>
378383
</div>
379-
{timeLeft !== null ? (
384+
{paceMark ? (
380385
<span
381386
aria-hidden
382-
className="absolute -inset-y-1 w-0.5 -translate-x-1/2 rounded-full bg-muted-foreground"
383-
style={{ left: `${timeLeft}%` }}
387+
className="absolute inset-y-0.5 w-0.5 -translate-x-1/2 rounded-full bg-foreground"
388+
style={paceMark.tick}
384389
/>
385390
) : null}
386391
<span

0 commit comments

Comments
 (0)