Skip to content

Commit 4b6b56c

Browse files
committed
fix(web): keep Clerk footer opaque
1 parent f036a49 commit 4b6b56c

2 files changed

Lines changed: 40 additions & 12 deletions

File tree

‎apps/web/src/components/clerk/clerkAppearance.test.ts‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ function contrastRatio(first: string, second: string): number {
2828
return (lighter + 0.05) / (darker + 0.05);
2929
}
3030

31+
function mixThemeColors(first: string, second: string, firstWeight: number): string {
32+
const channels = [first, second].map((value) => {
33+
const hex = themeColorToHex(value)?.slice(1, 7);
34+
if (!hex) throw new Error(`Expected a theme color, received ${value}`);
35+
return [0, 1, 2].map((channel) => Number.parseInt(hex.slice(channel * 2, channel * 2 + 2), 16));
36+
});
37+
const mixed = channels[0]!.map((channel, index) =>
38+
Math.round(channel * firstWeight + channels[1]![index]! * (1 - firstWeight)),
39+
);
40+
return `#${mixed.map((channel) => channel.toString(16).padStart(2, "0")).join("")}`;
41+
}
42+
3143
const builtInThemeModes = [
3244
T3_CHAT_THEME,
3345
GROVE_THEME,
@@ -39,29 +51,38 @@ const builtInThemeModes = [
3951
);
4052

4153
describe("clerkAppearance", () => {
42-
it("maps colors without overriding Clerk's component structure", () => {
54+
it("maps theme colors without overriding Clerk's component structure", () => {
4355
expect(clerkAppearance).toEqual({
4456
variables: {
4557
colorPrimary: "var(--update-foreground)",
4658
colorPrimaryForeground: "var(--card)",
47-
colorDanger: "var(--error-foreground)",
48-
colorSuccess: "var(--success-foreground)",
49-
colorWarning: "var(--warning-foreground)",
59+
colorDanger: "var(--error)",
60+
colorSuccess: "var(--success)",
61+
colorWarning: "var(--warning)",
5062
colorNeutral: "var(--foreground)",
5163
colorForeground: "var(--foreground)",
52-
colorMuted: "var(--muted)",
64+
colorMuted: "color-mix(in srgb, var(--card) 98%, var(--foreground))",
5365
colorMutedForeground: "var(--muted-foreground)",
5466
colorBackground: "var(--card)",
5567
colorInputForeground: "var(--foreground)",
5668
colorInput: "var(--secondary)",
5769
colorRing: "var(--ring)",
5870
},
71+
elements: {
72+
formFieldErrorText: { color: "var(--error-foreground)" },
73+
formFieldWarningText: { color: "var(--warning-foreground)" },
74+
formFieldSuccessText: { color: "var(--success-foreground)" },
75+
otpCodeFieldErrorText: { color: "var(--error-foreground)" },
76+
otpCodeFieldSuccessText: { color: "var(--success-foreground)" },
77+
},
5978
});
6079
});
6180

6281
it.each(builtInThemeModes)("keeps Clerk text readable across a built-in palette", (colors) => {
82+
const mutedSurface = mixThemeColors(colors.surface, colors.text, 0.98);
83+
6384
expect(contrastRatio(colors.text, colors.surface)).toBeGreaterThanOrEqual(4.5);
64-
expect(contrastRatio(colors.mutedForeground, colors.surface)).toBeGreaterThanOrEqual(4.5);
85+
expect(contrastRatio(colors.mutedForeground, mutedSurface)).toBeGreaterThanOrEqual(4.5);
6586
expect(contrastRatio(colors.text, colors.secondary)).toBeGreaterThanOrEqual(4.5);
6687
expect(contrastRatio(colors.updateForeground, colors.surface)).toBeGreaterThanOrEqual(4.5);
6788
expect(contrastRatio(colors.errorForeground, colors.surface)).toBeGreaterThanOrEqual(4.5);

‎apps/web/src/components/clerk/clerkAppearance.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,25 @@ export const clerkAppearance = {
1010
// text, while the card surface provides the inverse filled-control pair.
1111
colorPrimary: "var(--update-foreground)",
1212
colorPrimaryForeground: "var(--card)",
13-
// Clerk also renders status colors as inline text, so use the readable
14-
// foreground roles instead of the deeper fills used for icons and tinting.
15-
colorDanger: "var(--error-foreground)",
16-
colorSuccess: "var(--success-foreground)",
17-
colorWarning: "var(--warning-foreground)",
13+
colorDanger: "var(--error)",
14+
colorSuccess: "var(--success)",
15+
colorWarning: "var(--warning)",
1816
colorNeutral: "var(--foreground)",
1917
colorForeground: "var(--foreground)",
20-
colorMuted: "var(--muted)",
18+
// The stock dark theme's muted token is translucent. Clerk uses this as
19+
// the footer's background, so derive an opaque muted surface from the card.
20+
colorMuted: "color-mix(in srgb, var(--card) 98%, var(--foreground))",
2121
colorMutedForeground: "var(--muted-foreground)",
2222
colorBackground: "var(--card)",
2323
colorInputForeground: "var(--foreground)",
2424
colorInput: "var(--secondary)",
2525
colorRing: "var(--ring)",
2626
},
27+
elements: {
28+
formFieldErrorText: { color: "var(--error-foreground)" },
29+
formFieldWarningText: { color: "var(--warning-foreground)" },
30+
formFieldSuccessText: { color: "var(--success-foreground)" },
31+
otpCodeFieldErrorText: { color: "var(--error-foreground)" },
32+
otpCodeFieldSuccessText: { color: "var(--success-foreground)" },
33+
},
2734
} satisfies NonNullable<ClerkProviderProps["appearance"]>;

0 commit comments

Comments
 (0)