Skip to content

Commit 1cf4d4b

Browse files
fix(web,mobile): keep usage pace ticks visible
1 parent 0076ef6 commit 1cf4d4b

2 files changed

Lines changed: 78 additions & 31 deletions

File tree

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

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,32 @@ function WindowRow(props: {
5050
const timeLeft = elapsed === null ? null : Math.round((1 - elapsed) * 100);
5151
const pace = paceOf(window, now);
5252
const resetsIn = formatResetsIn(window, now);
53+
const [barWidth, setBarWidth] = useState(0);
54+
const tickX =
55+
timeLeft === null || barWidth < 6
56+
? null
57+
: Math.min(Math.max((barWidth * timeLeft) / 100, 3), barWidth - 3);
58+
const bar = (
59+
<View
60+
className="h-1.5 flex-row overflow-hidden rounded-full bg-subtle"
61+
style={barWidth > 0 ? { width: barWidth } : undefined}
62+
>
63+
<View
64+
className={
65+
remaining <= 10
66+
? "h-full rounded-full bg-red-500"
67+
: remaining <= 30
68+
? "h-full rounded-full bg-amber-500"
69+
: "h-full rounded-full bg-foreground"
70+
}
71+
style={[
72+
{ flex: remaining },
73+
remaining > 30 && props.color ? { backgroundColor: props.color } : null,
74+
]}
75+
/>
76+
<View style={{ flex: 100 - remaining }} />
77+
</View>
78+
);
5379
return (
5480
<View className="gap-1">
5581
<View className="flex-row items-baseline justify-between gap-3">
@@ -58,27 +84,35 @@ function WindowRow(props: {
5884
{remaining}% left
5985
</Text>
6086
</View>
61-
<View className="h-3 justify-center">
62-
<View className="h-1.5 flex-row overflow-hidden rounded-full bg-subtle">
63-
<View
64-
className={
65-
remaining <= 10
66-
? "h-full rounded-full bg-red-500"
67-
: remaining <= 30
68-
? "h-full rounded-full bg-amber-500"
69-
: "h-full rounded-full bg-foreground"
70-
}
71-
style={[
72-
{ flex: remaining },
73-
remaining > 30 && props.color ? { backgroundColor: props.color } : null,
74-
]}
75-
/>
76-
<View style={{ flex: 100 - remaining }} />
77-
</View>
78-
{timeLeft !== null ? (
87+
<View
88+
className="h-3 justify-center"
89+
onLayout={(event) => setBarWidth(event.nativeEvent.layout.width)}
90+
>
91+
{tickX === null ? (
92+
bar
93+
) : (
94+
<View className="h-1.5">
95+
{/* Clip the same full-width bar so neither fill proportions nor corner radii change. */}
96+
{(
97+
[
98+
[0, tickX - 3],
99+
[tickX + 3, barWidth],
100+
] as const
101+
).map(([start, end]) => (
102+
<View
103+
key={start}
104+
className="absolute top-0 bottom-0 overflow-hidden"
105+
style={{ left: start, width: end - start }}
106+
>
107+
<View style={{ marginLeft: -start }}>{bar}</View>
108+
</View>
109+
))}
110+
</View>
111+
)}
112+
{tickX !== null ? (
79113
<View
80-
className="absolute top-0 bottom-0 w-px bg-foreground"
81-
style={{ left: `${timeLeft}%`, opacity: 0.6 }}
114+
className="absolute top-px bottom-px w-0.5 rounded-full bg-foreground"
115+
style={{ left: tickX - 1 }}
82116
/>
83117
) : null}
84118
</View>

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function WindowBar({
8686
const remaining = remainingPercent(window);
8787
const elapsed = elapsedShare(window, now);
8888
const timeLeft = elapsed === null ? null : Math.round((1 - elapsed) * 100);
89+
const tickPosition = timeLeft === null ? null : `clamp(3px, ${timeLeft}%, calc(100% - 3px))`;
8990
const resetsIn = formatResetsIn(window, now);
9091
const resetsAt = window.resetsAt
9192
? formatUpcomingTimestamp(window.resetsAt, timestampFormat, now)
@@ -106,18 +107,30 @@ function WindowBar({
106107
/>
107108
}
108109
>
109-
<div className="absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
110-
{remaining > 0 ? (
111-
<div
112-
className="absolute inset-y-1.5 left-0 rounded-full"
113-
style={{ width: `${remaining}%`, backgroundColor: color }}
114-
/>
115-
) : null}
116-
{timeLeft !== null ? (
110+
{/* Mask both layers so the gap exposes even a translucent composer surface. */}
111+
<div
112+
className="absolute inset-0"
113+
style={
114+
tickPosition === null
115+
? undefined
116+
: {
117+
maskImage: `linear-gradient(to right, black calc(${tickPosition} - 3px), transparent calc(${tickPosition} - 3px), transparent calc(${tickPosition} + 3px), black calc(${tickPosition} + 3px))`,
118+
}
119+
}
120+
>
121+
<div className="absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
122+
{remaining > 0 ? (
123+
<div
124+
className="absolute inset-y-1.5 left-0 rounded-full"
125+
style={{ width: `${remaining}%`, backgroundColor: color }}
126+
/>
127+
) : null}
128+
</div>
129+
{tickPosition !== null ? (
117130
<span
118131
aria-hidden
119-
className="absolute inset-y-0.5 w-px -translate-x-1/2 bg-foreground/60"
120-
style={{ left: `${timeLeft}%` }}
132+
className="absolute inset-y-1 w-0.5 -translate-x-1/2 rounded-full bg-foreground"
133+
style={{ left: tickPosition }}
121134
/>
122135
) : null}
123136
</TooltipTrigger>
@@ -127,7 +140,7 @@ function WindowBar({
127140
{remaining}% left{timeLeft !== null ? ` · ${timeLeft}% of the window left` : ""}
128141
</span>
129142
{timeLeft !== null ? (
130-
<span className="text-muted-foreground">The line is where even spending would be.</span>
143+
<span className="text-muted-foreground">The tick is where even spending would be.</span>
131144
) : null}
132145
{resetsAt ? (
133146
<span className="text-muted-foreground">

0 commit comments

Comments
 (0)