diff --git a/.changeset/hide-single-nav-tab.md b/.changeset/hide-single-nav-tab.md
new file mode 100644
index 0000000..0537b16
--- /dev/null
+++ b/.changeset/hide-single-nav-tab.md
@@ -0,0 +1,5 @@
+---
+"@gabriel20xx/web-ui": patch
+---
+
+`Header` no longer renders the primary navigation tab, or the mobile menu toggle, when `navItems` has only one entry. A lone item is just the app's home page, so projects like OmniLogger and OutdoorGames no longer show a single "Dashboard" tab in the header.
diff --git a/packages/web-ui/src/lib/components/Header.svelte b/packages/web-ui/src/lib/components/Header.svelte
index 03c3f6c..b3c9e90 100644
--- a/packages/web-ui/src/lib/components/Header.svelte
+++ b/packages/web-ui/src/lib/components/Header.svelte
@@ -130,6 +130,9 @@
Boolean(username && (onProfile || (showSettings && onSettings) || onAbout || aboutHref || onLogout)),
);
+ // A lone nav item is just the app's home page, so it isn't worth a header tab (or a menu toggle).
+ const hasNavItems = $derived(navItems.length > 1);
+
function closeMenus(): void {
navOpen = false;
profileOpen = false;
@@ -164,27 +167,29 @@
{brand}
-
+ {#if hasNavItems}
+
+ {/if}
{/if}
-
+ {#if hasNavItems}
+
+ {/if}
diff --git a/packages/web-ui/src/lib/primary-color.svelte.ts b/packages/web-ui/src/lib/primary-color.svelte.ts
index 1a1a622..30b5f79 100644
--- a/packages/web-ui/src/lib/primary-color.svelte.ts
+++ b/packages/web-ui/src/lib/primary-color.svelte.ts
@@ -74,6 +74,21 @@ function mixHex(hex: string, towards: number, weight: number): string {
return `#${channels.map((c) => Math.round(c + (towards - c) * weight).toString(16).padStart(2, '0')).join('')}`
}
+// WCAG relative luminance of a #rrggbb color, from 0 (black) to 1 (white).
+function luminance(hex: string): number {
+ const [red, green, blue] = [1, 3, 5].map((start) => {
+ const channel = parseInt(hex.slice(start, start + 2), 16) / 255
+ return channel <= 0.03928 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4
+ })
+ return 0.2126 * red + 0.7152 * green + 0.0722 * blue
+}
+
+// WCAG contrast ratio between two #rrggbb colors, from 1 (no contrast) to 21 (black on white).
+function contrastRatio(a: string, b: string): number {
+ const [lighter, darker] = [luminance(a), luminance(b)].sort((x, y) => y - x)
+ return (lighter + 0.05) / (darker + 0.05)
+}
+
// The color is written to a stylesheet rather than inline on . Shared and app CSS re-declare these
// tokens on every [data-theme] element (the AppShell root, for one), and that declaration hides the value
// would pass down, so the choice never reached the app's UI. Targeting [data-theme] elements with
@@ -83,7 +98,9 @@ function primaryDeclarations(color: PaletteColor, dark: boolean): string {
// Hover is lighter on dark and darker on light, as in the shared theme. It is a hex value, not color-mix(),
// because consumers such as the terminal read these tokens as plain colors.
const hover = dark ? mixHex(primary, 255, 0.15) : mixHex(primary, 0, 0.15)
- const foreground = dark ? color.darkFg : '#ffffff'
+ // Text on the primary is white or the palette's dark text, whichever reads better. Mid-tone light colors
+ // are too light for white text, so the choice follows the color rather than the theme.
+ const foreground = contrastRatio(primary, '#ffffff') >= contrastRatio(primary, color.darkFg) ? '#ffffff' : color.darkFg
return [
...primaryVars.map((name) => `${name}: ${primary} !important;`),
`--sc-primary-hover: ${hover} !important;`,
diff --git a/packages/web-ui/tests/primary-color.test.ts b/packages/web-ui/tests/primary-color.test.ts
index 48cb8a5..b649c34 100644
--- a/packages/web-ui/tests/primary-color.test.ts
+++ b/packages/web-ui/tests/primary-color.test.ts
@@ -54,6 +54,13 @@ describe('primary color', () => {
expect(styleText()).not.toContain('#db3e24');
});
+ it('uses dark text on light colors where white would be hard to read', () => {
+ applyPrimaryColor('app', 'Honey');
+ const [light] = styleText().split("[data-theme='dark']");
+ expect(light).toContain('--sc-primary-fg: #2a2b0d !important;');
+ expect(light).not.toContain('--sc-primary-fg: #ffffff !important;');
+ });
+
it('makes the hover lighter on dark and darker on light', () => {
applyPrimaryColor('app', 'Clover');
const [light, dark] = styleText().split("[data-theme='dark']");