The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 00:30 UTC
fix(providers): badge initials stay readable on light accent colors (#16128)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Illia Panasenko committed
Oct 20, 2026 at 02:09 UTC
4f5f5a183f5de5a6b891fabba0d3f04367db0c95
4 files changed
+47
-11
apps/mobile/src/components/ProviderIcon.tsx
+10
-5
@@ -1,7 +1,11 @@
1
import { Image } from "expo-image";
2
import { Defs, LinearGradient, Path, Stop, Svg } from "react-native-svg";
3
import { View } from "react-native";
4
-import { providerInstanceInitials } from "@t3tools/client-runtime/state/provider-instance-display";
4
+import {
5
+ normalizeProviderAccentColor,
6
+ providerAccentForegroundColor,
7
+ providerInstanceInitials,
8
+} from "@t3tools/client-runtime/state/provider-instance-display";
9
import { useId, useState } from "react";
10
import { resolveOfficialAcpRegistryIconUrl } from "@t3tools/contracts";
11
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
@@ -156,6 +160,7 @@ export function ProviderInstanceIcon(props: {
160
readonly showBadge?: boolean;
161
readonly surfaceColor: string;
162
}) {
163
+ const accentColor = normalizeProviderAccentColor(props.accentColor);
164
return (
165
<View style={{ position: "relative" }}>
166
<View style={{ opacity: 0.6 }}>
@@ -169,7 +174,7 @@ export function ProviderInstanceIcon(props: {
174
style={{ position: "absolute", right: -3, bottom: -3, width: 32, alignItems: "flex-end" }}
175
>
176
<View
172
- className={props.accentColor ? undefined : "bg-card"}
177
+ className={accentColor ? undefined : "bg-card"}
178
style={{
179
height: 12,
180
minWidth: 12,
@@ -177,18 +182,18 @@ export function ProviderInstanceIcon(props: {
182
borderRadius: 999,
183
borderWidth: 1,
184
borderColor: props.surfaceColor,
180
- backgroundColor: props.accentColor,
185
+ backgroundColor: accentColor,
186
alignItems: "center",
187
justifyContent: "center",
188
}}
189
>
190
<Text
186
- className={props.accentColor ? undefined : "text-foreground-muted"}
191
+ className={accentColor ? undefined : "text-foreground-muted"}
192
style={{
193
fontSize: 7,
194
fontWeight: "600",
195
lineHeight: 9,
191
- color: props.accentColor ? "#ffffff" : undefined,
196
+ color: accentColor ? providerAccentForegroundColor(accentColor) : undefined,
197
}}
198
>
199
{providerInstanceInitials(props.displayName)}
apps/web/src/components/chat/ProviderInstanceIcon.tsx
+14
-6
@@ -1,6 +1,10 @@
1
import { type CSSProperties, memo } from "react";
2
3
-import { providerInstanceInitials } from "@t3tools/client-runtime/state/provider-instance-display";
3
+import {
4
+ normalizeProviderAccentColor,
5
+ providerAccentForegroundColor,
6
+ providerInstanceInitials,
7
+} from "@t3tools/client-runtime/state/provider-instance-display";
8
9
import { ProviderDriverKind } from "@t3tools/contracts";
10
import { AntigravityIcon, ClaudeAI, Icon, OpenAI } from "../Icons";
@@ -71,8 +75,12 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
75
const Icon = PROVIDER_ICON_BY_PROVIDER[props.driverKind] ?? null;
76
const packageIcon = providerClients.get(props.driverKind)?.icon;
77
const indicatorBackground = props.indicatorBackground ?? "var(--card)";
74
- const accentStyle = props.accentColor
75
- ? ({ "--provider-accent": props.accentColor } as CSSProperties)
78
+ const accentColor = normalizeProviderAccentColor(props.accentColor);
79
+ const accentStyle = accentColor
80
+ ? ({
81
+ "--provider-accent": accentColor,
82
+ "--provider-accent-foreground": providerAccentForegroundColor(accentColor),
83
+ } as CSSProperties)
84
: undefined;
85
const badgeContent = props.badgeContent ?? "initials";
86
const iconClassName = cn(props.size === "compact" && "size-3.5", props.iconClassName);
@@ -90,7 +98,7 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
98
props.className,
99
)}
100
style={accentStyle}
93
- data-provider-accent-color={props.accentColor}
101
+ data-provider-accent-color={accentColor}
102
>
103
{isAcpRegistry ? (
104
<AcpRegistryAgentIcon
@@ -125,8 +133,8 @@ export const ProviderInstanceIcon = memo(function ProviderInstanceIcon(props: {
133
<span
134
className={cn(
135
"pointer-events-none absolute right-0 bottom-0 z-10 flex h-3.5 min-w-3.5 items-center justify-center rounded-full border px-0.5 text-4xs font-semibold leading-none shadow-sm",
128
- props.accentColor
129
- ? "bg-(--provider-accent) text-white"
136
+ accentColor
137
+ ? "bg-(--provider-accent) text-(--provider-accent-foreground)"
138
: "bg-card text-muted-foreground",
139
props.size === "compact" &&
140
"right-[-0.1875rem] bottom-[-0.1875rem] h-3 min-w-3 px-0.5 text-5xs",
packages/client-runtime/src/state/providerInstanceDisplay.test.ts
+11
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vite-plus/test";
3
4
import {
5
normalizeProviderAccentColor,
6
+ providerAccentForegroundColor,
7
providerInstanceInitials,
8
resolveProviderInstanceDisplayName,
9
shouldShowInstanceBadge,
@@ -89,6 +90,16 @@ describe("normalizeProviderAccentColor", () => {
90
});
91
});
92
93
+describe("providerAccentForegroundColor", () => {
94
+ it.each([
95
+ ["#b5f23d", "#000000"],
96
+ ["#2563eb", "#ffffff"],
97
+ ["#777777", "#000000"],
98
+ ])("chooses the higher WCAG contrast foreground for %s", (accent, foreground) => {
99
+ expect(providerAccentForegroundColor(accent)).toBe(foreground);
100
+ });
101
+});
102
+
103
describe("shouldShowInstanceBadge", () => {
104
it("hides badges for distinct ACP agents sharing the registry driver", () => {
105
const mistral = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe", enabled: true };
packages/client-runtime/src/state/providerInstanceDisplay.ts
+12
@@ -42,6 +42,18 @@ export function normalizeProviderAccentColor(value: string | undefined): string
42
return /^#[0-9a-fA-F]{6}$/u.test(trimmed) ? trimmed : undefined;
43
}
44
45
+export function providerAccentForegroundColor(accentColor: string) {
46
+ const linearChannel = (offset: number) => {
47
+ const value = Number.parseInt(accentColor.slice(offset, offset + 2), 16) / 255;
48
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
49
+ };
50
+ const luminance =
51
+ 0.2126 * linearChannel(1) + 0.7152 * linearChannel(3) + 0.0722 * linearChannel(5);
52
+ const blackContrast = (luminance + 0.05) / 0.05;
53
+ const whiteContrast = 1.05 / (luminance + 0.05);
54
+ return blackContrast >= whiteContrast ? "#000000" : "#ffffff";
55
+}
56
+
57
export function shouldShowInstanceBadge(
58
entry: {
59
readonly driverKind: ProviderDriverKind;