From 50f816abaf308aeafcf3de7dbba70bb09520cbe0 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Thu, 27 Aug 2026 21:27:03 -0500 Subject: [PATCH] feat(desktop): add an accent variant to the popover primitive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default popover is glass over the app's own chrome, which is right for something the user opened and wrong for something the app said. The accent variant fills the same box — same arrow, same placement engine — with a solid brand colour so an unprompted surface reads as the app speaking. Filling it with `primary` directly doesn't work across themes: a pale accent is a perfectly valid primary (imported VS Code themes love a pastel), and the honest `primaryForeground` for one is near-black, so the loud surface comes out a pastel card whispering. `--dt-primary-solid` deepens the hue until a light foreground clears AA — a no-op on an accent that is already deep, and darkening only, so the hue survives. --- apps/desktop/src/components/ui/popover.tsx | 50 ++++++++++++++++++---- apps/desktop/src/styles.css | 5 +++ apps/desktop/src/themes/context.tsx | 17 +++++++- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/apps/desktop/src/components/ui/popover.tsx b/apps/desktop/src/components/ui/popover.tsx index 16fa23f7a4..040bb1f988 100644 --- a/apps/desktop/src/components/ui/popover.tsx +++ b/apps/desktop/src/components/ui/popover.tsx @@ -1,3 +1,4 @@ +import { cva, type VariantProps } from 'class-variance-authority' import { Popover as PopoverPrimitive } from 'radix-ui' import * as React from 'react' @@ -16,6 +17,35 @@ function PopoverAnchor({ ...props }: React.ComponentProps } +// Both variants are the same box, and `--popover-surface` is what the arrow +// fills itself with — so a variant only ever has to restate the surface. +const popoverContentVariants = cva( + 'z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-lg p-2 outline-hidden data-[side=bottom]:slide-in-from-top-1 data-[side=left]:slide-in-from-right-1 data-[side=right]:slide-in-from-left-1 data-[side=top]:slide-in-from-bottom-1 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95', + { + variants: { + variant: { + // Themed glass surface, viewport-aware (Radix flips/shifts off edges). + // Border-only (no shadow). + default: + 'border border-(--ui-stroke-secondary) bg-(--popover-surface) text-popover-foreground backdrop-blur-md [--popover-surface:color-mix(in_srgb,var(--ui-bg-elevated)_92%,transparent)]', + // Solid accent. For a surface that has to read as the app SPEAKING + // rather than as chrome the user opened — it is loud on purpose, so + // it earns its place by being rare. No border: at full-strength fill + // an edge only muddies the silhouette, and the arrow reads as a point + // on the shape instead of a shape stuck to it. `primary-solid`, not + // `primary`: a pale accent would otherwise fill this with a pastel and + // pair it with near-black text (themes/context.tsx). + accent: + 'bg-(--popover-surface) text-(--dt-primary-solid-foreground) [--popover-surface:var(--dt-primary-solid)]' + } + }, + defaultVariants: { variant: 'default' } + } +) + +interface PopoverContentProps + extends React.ComponentProps, VariantProps {} + function PopoverContent({ align = 'center', // Keeps the arrow clear of the rounded corners (rounded-lg = 8px): Radix @@ -26,8 +56,9 @@ function PopoverContent({ className, collisionPadding = 8, sideOffset = 6, + variant, ...props -}: React.ComponentProps) { +}: PopoverContentProps) { // Portal into the enclosing dialog when nested in one (keeps focus inside so // the dialog doesn't close on dismiss); document.body otherwise. const container = usePopoverPortalContainer() @@ -37,12 +68,7 @@ function PopoverContent({ - + diff --git a/apps/desktop/src/styles.css b/apps/desktop/src/styles.css index 054153e018..7109409ffd 100644 --- a/apps/desktop/src/styles.css +++ b/apps/desktop/src/styles.css @@ -395,6 +395,11 @@ --dt-popover-foreground: var(--ui-text-primary); --dt-primary: var(--theme-primary); --dt-primary-foreground: #fcfcfc; + /* Boot-paint fallbacks. themes/context.tsx replaces --dt-primary-solid with + the hue deepened until #fcfcfc clears AA on it; until it runs, the raw + primary is the closest honest guess. */ + --dt-primary-solid: var(--theme-primary); + --dt-primary-solid-foreground: #fcfcfc; --dt-secondary: var(--theme-secondary); --dt-secondary-foreground: var(--ui-text-secondary); --dt-accent: var(--theme-accent-soft); diff --git a/apps/desktop/src/themes/context.tsx b/apps/desktop/src/themes/context.tsx index 6409315d06..d2024906a4 100644 --- a/apps/desktop/src/themes/context.tsx +++ b/apps/desktop/src/themes/context.tsx @@ -20,7 +20,7 @@ import { setAppearance } from '@/store/translucency' import { $accentOverride } from './accent-override' import { $backendThemes, $pendingSkinApply } from './backend-sync' -import { harmonize, hexToRgb, mix, readableOn } from './color' +import { ensureContrast, harmonize, hexToRgb, mix, readableOn } from './color' import { BUILTIN_THEME_LIST, DEFAULT_SKIN_NAME, DEFAULT_TYPOGRAPHY, nousTheme } from './presets' import { retintTheme } from './retint' import type { DesktopTheme, DesktopThemeColors } from './types' @@ -178,6 +178,11 @@ function renderedModeFor(colors: DesktopThemeColors, mode: 'light' | 'dark'): 'l // styles.css --theme-neutral-chrome — keep in sync. const NEUTRAL_CHROME = { light: '#f3f3f3', dark: '#0d0d0e' } as const +// The one foreground --dt-primary-solid is built to carry. Fixed rather than +// measured: the surface is derived to suit IT, not the other way round. +// styles.css --dt-primary-solid-foreground fallback — keep in sync. +const PRIMARY_SOLID_FOREGROUND = '#fcfcfc' + const chromeBackground = (background: string, isDark: boolean) => mix(background, NEUTRAL_CHROME[isDark ? 'dark' : 'light'], isDark ? 0.26 : 0.08) @@ -238,6 +243,16 @@ function applyTheme(theme: DesktopTheme, mode: 'light' | 'dark') { '--dt-ring': c.ring, '--dt-muted': c.muted, '--dt-midground-foreground': c.midgroundForeground ?? readableOn(midground), + // A LOUD fill of the brand colour, for the rare surface that has to read as + // the app speaking rather than as chrome. `primary` alone can't do that job: + // a pale accent (imported VS Code themes love a pastel pink) is a perfectly + // valid primary, and the honest `primaryForeground` for it is near-black — + // so the "loud" surface comes out a pastel card with dark text on it, + // whispering. Deepening the hue until the LIGHT foreground clears AA keeps + // one look across every theme: no-ops on an accent that is already deep, + // and only ever darkens, so the hue survives. + '--dt-primary-solid': ensureContrast(c.primary, PRIMARY_SOLID_FOREGROUND, 4.5), + '--dt-primary-solid-foreground': PRIMARY_SOLID_FOREGROUND, '--dt-composer-ring': c.composerRing ?? midground, '--dt-destructive': c.destructive, '--dt-destructive-foreground': c.destructiveForeground,