mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-21 07:45:38 +00:00
fix(app): keep the derived neutral fill visible when a theme's own text is quiet
Bounding the fill by text contrast could reach a step of 1 or less on a palette whose body text is under about 3:1, returning the page background itself. The step now has a minimum.
This commit is contained in:
@@ -29,6 +29,8 @@ const NEUTRAL_FILL_STEPS = {
|
||||
// the contrast the theme gives its own text: foreground stays at least this readable on it. The
|
||||
// margin over 3:1 absorbs the rounding of the fill to 8-bit channels.
|
||||
const NEUTRAL_FILL_TEXT_FLOOR = 3.05;
|
||||
// A theme whose own text is quieter than that still gets a fill that separates from the page.
|
||||
const NEUTRAL_FILL_MIN_STEP = 1.25;
|
||||
|
||||
// Tertiary text: muted text, that fraction of the way toward the background, but never quieter
|
||||
// than this contrast against it (or than the muted text itself, when that is already quieter). The
|
||||
@@ -63,7 +65,11 @@ export function deriveNeutralFills(
|
||||
// Foreground on the fill is about (foreground on background) / step.
|
||||
const textBound = contrastRatio(background, foreground) / NEUTRAL_FILL_TEXT_FLOOR;
|
||||
return {
|
||||
surface3: stepContrast(background, foreground, Math.min(steps.surface3, textBound)),
|
||||
surface3: stepContrast(
|
||||
background,
|
||||
foreground,
|
||||
Math.max(NEUTRAL_FILL_MIN_STEP, Math.min(steps.surface3, textBound)),
|
||||
),
|
||||
surface4: stepContrast(background, foreground, steps.surface4),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -169,6 +169,18 @@ describe.each(themes.filter(({ name }) => name.startsWith("plugin ")))(
|
||||
},
|
||||
);
|
||||
|
||||
describe("a plugin theme whose own text is quiet", () => {
|
||||
it("still separates the neutral fill from the page", () => {
|
||||
const { colors } = buildPluginTheme({
|
||||
...MOCHA,
|
||||
colors: { ...MOCHA.colors, background: "#202020", foreground: "#6a6a6a" },
|
||||
});
|
||||
expect(contrastRatio(colors.surface0, colors.surface3)).toBeGreaterThanOrEqual(
|
||||
NEUTRAL_FILL_STEP,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("built-in themes", () => {
|
||||
it.each(themes.filter(({ name }) => !name.startsWith("plugin ")))(
|
||||
"$name keeps a control hover visible on the workspace surface",
|
||||
|
||||
Reference in New Issue
Block a user