:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(quill): add an inverted surface that flips tokens for a subtree (#129206)
Thiago Salvatore89c96883a5f4
diff --git a/frontend/src/design.md b/frontend/src/design.mdindex 0b97849ad704..c7e78e15a19f 100644--- a/frontend/src/design.md+++ b/frontend/src/design.md@@ -150,6 +150,7 @@ Use via Tailwind utilities (`bg-primary text-primary-foreground`, `border-border- `success` vs `completed`: success = positive outcome ("saved", "passed"); completed = final state ("merged", "done")- Other surfaces:- `chrome`: toolbars, menubars, nav+ - Inverted surface: a floating bar that must stand out from the page, such as a bulk selection bar, takes `data-quill-inverted` with `bg-background text-foreground`. Quill components inside it switch to the opposite theme, so do not recolor them by hand.- Text:- `subtle-foreground`: tertiary meta text, one step quieter than `muted-foreground`- `primary-on-foreground`: brand text, such as a link, on an inverted surface that uses `foreground` as its background (tooltips). It swaps to the other mode's brand: yellow on a dark tooltip in light mode, orange on a light tooltip in dark mode. Plain `primary` fades on those surfaces.diff --git a/packages/quill/packages/primitives/AGENTS.md b/packages/quill/packages/primitives/AGENTS.mdindex 4a909ee78deb..f9de63223900 100644--- a/packages/quill/packages/primitives/AGENTS.md+++ b/packages/quill/packages/primitives/AGENTS.md@@ -1328,6 +1328,24 @@ Live text: a highlight sweeping a line to say work is still in flight. Put it on- **Retune** with `--quill-shimmer-base` / `--quill-shimmer-highlight`; defaults read as muted brightening to full.- Reduced motion hands the color back rather than just stopping — otherwise the text would stay invisible.+### Inverted surface — `data-quill-inverted`++A container in the opposite theme: a dark floating selection bar in light mode, a light one in dark mode.+Put `data-quill-inverted` on the container and paint it with `bg-background text-foreground`.++```tsx+<div data-quill-inverted className="flex items-center gap-2 rounded-lg bg-background px-3 py-2 text-foreground">+ <Text size="sm">3 tables selected</Text>+ <Button variant="outline">Export</Button>+ <Button variant="primary">Certify</Button>+</div>+```++- **Every token in the subtree takes the other mode's value**, including on elements that set `data-quill` themselves, such as Button. So Button variants, `Text variant="muted"`, Checkbox and focus rings stay legible with no per-component overrides.+- The rule ships in the token CSS (`color-system.css` and the scoped variant), not in `primitives.css`.+- Portaled popups (menus, tooltips) open outside the subtree, so they keep the page theme.+- The `dark:` variant and `.dark` component rules still follow the page theme. Keep them out of an inverted subtree.+---## Iconsdiff --git a/packages/quill/packages/primitives/src/inverted-surface.stories.tsx b/packages/quill/packages/primitives/src/inverted-surface.stories.tsxnew file mode 100644index 000000000000..57c4a71042a7--- /dev/null+++ b/packages/quill/packages/primitives/src/inverted-surface.stories.tsx@@ -0,0 +1,62 @@+import type { Meta, StoryObj } from '@storybook/react'+import { DownloadIcon, XIcon } from 'lucide-react'++import { Button } from './button'+import { Checkbox } from './checkbox'+import { Separator } from './separator'+import { Text } from './text'++const meta = {+ title: 'Primitives/Inverted surface',+ tags: ['autodocs'],+} satisfies Meta++export default meta+type Story = StoryObj<typeof meta>++function SelectionBar(): React.ReactElement {+ return (+ <div data-quill-inverted className="flex items-center gap-2 rounded-lg bg-background px-3 py-2 text-foreground">+ <Checkbox checked aria-label="Select all" />+ <Text size="sm" weight="medium">+ 3 tables selected+ </Text>+ <Text size="sm" variant="muted">+ of 42+ </Text>+ <Separator orientation="vertical" className="mx-1 h-5" />+ <Button variant="outline">+ <DownloadIcon />+ Export+ </Button>+ <Button>Add tag</Button>+ <Button variant="primary">Certify</Button>+ <Button variant="link">Learn more</Button>+ <Button size="icon" variant="outline" aria-label="Clear selection">+ <XIcon />+ </Button>+ </div>+ )+}++function Page({ mode }: { mode: 'light' | 'dark' }): React.ReactElement {+ return (+ <div className={mode === 'dark' ? 'dark' : undefined}>+ <div className="flex flex-col gap-3 rounded-lg border border-border bg-background p-6 text-foreground">+ <Text size="sm" variant="muted">+ {mode === 'dark' ? 'Dark page' : 'Page in the current theme'}+ </Text>+ <SelectionBar />+ </div>+ </div>+ )+}++export const SelectionBarInBothModes: Story = {+ render: () => (+ <div className="flex flex-col gap-4">+ <Page mode="light" />+ <Page mode="dark" />+ </div>+ ),+}diff --git a/packages/quill/packages/tokens/AGENTS.md b/packages/quill/packages/tokens/AGENTS.mdindex 95cd0d42d742..c5c43d41c8a2 100644--- a/packages/quill/packages/tokens/AGENTS.md+++ b/packages/quill/packages/tokens/AGENTS.md@@ -21,6 +21,8 @@ src/*.ts ──(tsx src/build.ts)──▶ dist/*.css| `tailwind-lib.css` | `@theme` + `@custom-variant` only | library packages || `*.scoped.css` | same, gated behind `[data-quill]` | consumers with their own design system |+The color-system files also emit the inverted surface: a `[data-quill-inverted]` subtree gets the other mode's tokens. See the Inverted surface section of `../primitives/AGENTS.md`.+After changing anything in `src/`, **rerun the build** so `dist/` matches.(The quill storybook also watches `src/` via `quillTokensWatcher` in its`main.ts`, so it hot-reloads without a manual build.)diff --git a/packages/quill/packages/tokens/src/colors.ts b/packages/quill/packages/tokens/src/colors.tsindex 0d47f790f079..45a48fcbf43d 100644--- a/packages/quill/packages/tokens/src/colors.ts+++ b/packages/quill/packages/tokens/src/colors.ts@@ -278,6 +278,36 @@ function resolveDarkSelector(raw?: string | string[]): string {return selectors.length === 1 ? selectors[0] : `:is(${selectors.join(', ')})`}+const INVERTED_SURFACE = '[data-quill-inverted]'++type ModeVars = { staticVars: Record<string, string>; dynamicVars: Record<string, string> }++/** Generate the rules that give an inverted surface subtree the other mode's tokens */+function generateInvertedSurfaceCSS(+ darkSelector: string,+ light: ModeVars,+ dark: ModeVars,+ dataViz: { light: string; dark: string }+): string {+ const inLightMode = `:is(${INVERTED_SURFACE}, ${INVERTED_SURFACE} *)`+ const inDarkMode = `:is(${darkSelector} ${INVERTED_SURFACE}, ${INVERTED_SURFACE}${darkSelector}, ${darkSelector} ${INVERTED_SURFACE} *, ${INVERTED_SURFACE}${darkSelector} *)`++ return `${inLightMode} {+ color-scheme: dark;+${cssVarsFlat(dark.staticVars)}+${cssVarsFlat(dark.dynamicVars)}+${dataViz.dark}+}++${inDarkMode} {+ color-scheme: light;+${cssVarsFlat(light.staticVars)}+${cssVarsFlat(light.dynamicVars)}+${dataViz.light}+}+`+}+/** Generate color-system.css (:root light + .dark overrides) */export function generateColorSystemCSS(theme: ThemeConfig = DEFAULT_THEME,@@ -297,7 +327,7 @@ export function generateColorSystemCSS(].join('\n')// Split colors into static (safe on :root) vs theme-derived (need * for local overrides)- const partition = (i: number): { staticVars: Record<string, string>; dynamicVars: Record<string, string> } => {+ const partition = (i: number): ModeVars => {const staticVars: Record<string, string> = {}const dynamicVars: Record<string, string> = {}for (const [k, v] of Object.entries(semanticColors)) {@@ -316,12 +346,13 @@ export function generateColorSystemCSS(// Data-viz tokens (categorical palette + graph chrome) are static like the// semantic static vars — they live with them on :root / the scope selector.const dataViz = generateDataVizVars()+ const invertedSurface = generateInvertedSurfaceCSS(darkSelector, light, dark, dataViz)// ── Scoped mode ─────────────────────────────────────// All vars gated behind the scope selector to avoid clashing// with the consumer's existing CSS custom properties.if (scope) {- const scopeSel = `:is(${scope}, ${scope} *)`+ const scopeSel = `:is(${scope}, ${scope} *, ${INVERTED_SURFACE}, ${INVERTED_SURFACE} *)`// Handle both ancestor-dark (`.dark [data-quill]`) and same-element// dark (`[data-quill].dark`) so dark mode works regardless of where// the dark selector lives relative to the scope element.@@ -366,7 +397,8 @@ ${cssVarsFlat(dark.staticVars)}${cssVarsFlat(dark.dynamicVars)}${dataViz.dark}}-`++${invertedSurface}`}// ── Unscoped mode (default) ─────────────────────────@@ -410,7 +442,8 @@ ${cssVarsFlat(light.dynamicVars)}:is(${darkSelector}, ${darkSelector} *) {${cssVarsFlat(dark.dynamicVars)}}-`++${invertedSurface}`}/** Generate Tailwind v4 @theme color mappings (--color-* → var(--*)) */