Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ server (`docs/architecture.md`, "The language bar").
every call through `useApi()` with `credentials: 'omit'`, so no cookie lands
on a public page.
- The theme follows the OS by default; `localStorage.theme` holds an explicit
choice. The portal is another origin and keeps its own.
choice. `/black-friday` alone is always dark. The portal is another origin and
keeps its own.

## Conventions

Expand Down
384 changes: 236 additions & 148 deletions composer.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions docs/rebuild/design/design-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,22 @@ Every row of the §2.3 table becomes an assertion. Add a gamut assertion: no tok
var t = localStorage.getItem('theme');
if (t === 'dark' || t === 'system' || t === 'light') { choice = t; }
} catch (e) {}
var dark = choice === 'dark' || (choice === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);
var root = document.documentElement;
var forced = root.dataset.themeForced === 'dark';
var dark = forced || choice === 'dark' || (choice === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);
if (dark) { root.classList.add('dark'); }
root.dataset.themeChoice = choice; /* drives the control's icon without hydration */
root.style.colorScheme = dark ? 'dark' : 'light';
var m = document.querySelector('meta[name="theme-color"]');
if (m) { m.setAttribute('content', dark ? '#121212' : '#ffffff'); }
if (m) { m.setAttribute('content', forced ? '#060606' : dark ? '#121212' : '#ffffff'); }
})();
</script>
```

`#ffffff` and `#121212` are the two `--background` values in §2.2.

**The one forced page.** `/black-friday` is dark in both themes, from the banner to the footer (owner decision, 2026-11-18). Blade stamps `html[data-theme-forced="dark"]` and `LandingLayout`'s `alwaysDark` holds it across visits inside the app. The reader's stored choice is untouched, the theme control is hidden there, and `--background`, `--surface` and `--raised` drop to `oklch(0.12 0 0)` (`#060606`), `oklch(0.15 0 0)` and `oklch(0.18 0 0)`.

**Rules:**

- SSR markup never depends on the theme.
Expand Down
2 changes: 1 addition & 1 deletion docs/rebuild/design/positioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ prices, with a code that works only inside the window (`App\Support\Pricing\Camp
- **Where, while it is live:** the banner slot on every page but the sale's own, a black band above the homepage
hero and Pricing's header, and the plan cards of the cycles it covers. Checkout from the site attaches the code.
Before and after the window, only the sale's own page mentions it.
- **The sale's own page,** `/black-friday`, keeps one URL from year to year. Before the sale it states the window and
- **The sale's own page,** `/black-friday`, keeps one URL from year to year and is black throughout, in both themes. Before the sale it states the window and
the prices, and offers a calendar file for the start instead of a button that cannot be pressed; during it the offers
can be bought from it; after it, its title, heading and description say the sale has ended, and nothing on it is
offered. Its copy stays near 150 words: the offers as two ruled rows, Pro one-time first and larger, then the Pro
Expand Down
13 changes: 13 additions & 0 deletions resources/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ html.campaign-live .campaign-band {
color: var(--foreground);
}

/* /black-friday is black from the banner to the footer in either theme, so its hero's ground is the page's. */
@media screen {
html[data-theme-forced] {
--background: oklch(0.12 0 0);
--surface: oklch(0.15 0 0);
--raised: oklch(0.18 0 0);
}
}

html[data-theme-forced] .theme-setting {
display: none;
}

.campaign-banner {
border-bottom: 1px solid color-mix(in oklab, var(--accent) 45%, var(--rule));
}
Expand Down
12 changes: 1 addition & 11 deletions resources/js/components/shared/footer-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ interface FooterBarProps {
className?: string;
}

/**
* The last row of every page in both apps (design-system §5.3.17): the mark
* and the copyright on the left, the language menu and the theme on the
* right. Its rule runs rail to rail, so above a cell grid it lands on the
* grid's last line and draws it once.
*
* With `chat`, the controls stop short of the chat launcher: they keep
* `LAUNCHER_REACH` clear of the screen's right edge, which costs nothing once
* the page's own margin is that wide (from about 1416px).
*/
export default function FooterBar({ copyright, language, themeLabels, chat = false, className }: FooterBarProps) {
return (
<div
Expand All @@ -158,7 +148,7 @@ export default function FooterBar({ copyright, language, themeLabels, chat = fal
style={chat ? { paddingRight: `max(0px, calc(${LAUNCHER_REACH}px - max(var(--cell-bleed), (100vw - 76rem) / 2)))` } : undefined}
>
{language}
<ThemeControl variant="icons" labels={themeLabels} />
<ThemeControl variant="icons" labels={themeLabels} className="theme-setting" />
</div>
</div>
);
Expand Down
19 changes: 1 addition & 18 deletions resources/js/components/site/mobile-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,6 @@ interface MobileNavProps {
desktop: string;
}

/**
* The menu below the desktop header (sitemap §B.2; design-system §5.3.17): a
* modal `<dialog>` sheet over the whole viewport.
*
* `showModal()` traps focus and makes the page behind it inert; Escape and the
* close button close it, and focus returns to the toggle that opened it.
* Crossing to the desktop layout while it is open closes it too, so a rotated
* tablet never keeps a scroll-locked page with no visible control.
*
* Order: Features (expanding in place to the same links as the desktop menu),
* Databases, Pricing, the platform pages, Docs, Blog, FAQ, GitHub with its star
* count, Account; then
* Download for Mac and the App Store badge, each with the system it needs, so
* both are on the first screen of a phone; last, the language, one row that
* opens the list, and the theme control. On an iPhone or iPad the badge comes
* before the Mac button.
*/
export default function MobileNav({ id, open, onClose, desktop }: MobileNavProps) {
const { locale, m, fmt } = useI18n();
const { url } = usePage();
Expand Down Expand Up @@ -278,7 +261,7 @@ export default function MobileNav({ id, open, onClose, desktop }: MobileNavProps

<div className="mt-8 grid gap-4 border-t border-rule pt-4">
<LanguageSwitcher variant="stack" />
<div className="grid gap-2">
<div className="theme-setting grid gap-2">
<p className="type-small font-medium text-muted-foreground" aria-hidden="true">
{m.controls.theme.label}
</p>
Expand Down
52 changes: 9 additions & 43 deletions resources/js/layouts/landing-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,33 @@
import { useEffect, type ReactNode } from 'react';
import { useEffect, useLayoutEffect, type ReactNode } from 'react';
import { useLiveChat } from '@/components/site/chat-button';
import ConsentBar from '@/components/site/consent-bar';
import FrameRails from '@/components/shared/frame-rails';
import SiteFooter from '@/components/site/site-footer';
import SiteHeader from '@/components/site/site-header';
import TopBanner from '@/components/site/top-banner';
import { useI18n } from '@/i18n';
import { syncTheme } from '@/lib/theme';
import { forceDark, syncTheme } from '@/lib/theme';

interface Props {
children: ReactNode;
/**
* False on a page that carries its own newsletter form (the blog index),
* so the footer does not repeat the same field a screen below it.
*/
footerNewsletter?: boolean;
alwaysDark?: boolean;
}

/**
* The public page frame: a stack in reading and tab order, drawn as a grid
* (design-system §4.6, §4.7, §7.2).
*
* 1. The skip link, first in the document.
* 2. The top banner, which scrolls away with the page: the license banner,
* or the bar offering this page in the reader's language. Then the sticky
* header. The header is a real `banner` landmark because it sits outside
* `<main>`.
* 3. `<main id="main-content" tabIndex={-1}>`, so the skip link moves focus
* into it rather than only scrolling.
* 4. The footer, a `contentinfo` landmark for the same reason.
* 5. The consent bar, last, so it is the last tab stop on the page.
*
* The grid is drawn, not laid out: the rails are a decorative overlay on this
* `relative` root (`FrameRails`, from 1280px), and a full-bleed hairline joins
* every two blocks of `<main>` (frame.css). Neither moves content or takes a
* tab stop.
*
* Crisp's chat launcher joins every page once it has loaded and the browser is
* idle (`useLiveChat`, `lib/crisp.ts`); it is not part of the server render.
*
* There is no toast region: nothing on the public site calls `toast()`, and
* Sonner's region carried an English landmark name onto every /vi page.
*
* Nothing here clips overflow: `overflow-x: hidden` on an ancestor masked
* horizontal-scroll regressions instead of preventing them, and would break the
* sticky header. Anything wide scrolls inside its own region.
*/
export default function LandingLayout({ children, footerNewsletter = true }: Props) {
// Nothing here clips overflow: `overflow-x: hidden` on an ancestor would break the sticky header.
export default function LandingLayout({ children, footerNewsletter = true, alwaysDark = false }: Props) {
const { locale, m } = useI18n();

/*
* `<html lang>` is right on the first byte, from Blade. A visit between
* locales is a full document load (`LocaleLink` renders a plain `<a>` for
* it), so this only matters if history navigation ever restores a page in
* the other language without one. It is a safety net, not the mechanism.
*/
// History navigation can restore a page in another language without a document load.
useEffect(() => {
document.documentElement.lang = locale;
}, [locale]);

/* Another tab changed the theme, or the system did while "System" is chosen. */
useEffect(() => syncTheme(), []);

// Before paint, so a visit from a light page never shows this one light. Blade covers the first load.
useLayoutEffect(() => (alwaysDark ? forceDark() : undefined), [alwaysDark]);

useLiveChat();

return (
Expand Down
37 changes: 21 additions & 16 deletions resources/js/lib/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export type ThemeChoice = 'light' | 'dark' | 'system';

export const THEME_CHOICES: readonly ThemeChoice[] = ['light', 'dark', 'system'];

/** `theme-color` per resolved theme: the two `--background` values in tokens.css. */
export const THEME_COLORS = { light: '#ffffff', dark: '#121212' } as const;
// `sale` is the `--background` app.css gives a page under `html[data-theme-forced]`.
export const THEME_COLORS = { light: '#ffffff', dark: '#121212', sale: '#060606' } as const;

const SYSTEM_DARK_QUERY = '(prefers-color-scheme: dark)';

Expand Down Expand Up @@ -56,28 +56,20 @@ export function resolveDark(choice: ThemeChoice, prefersDark: boolean): boolean
return choice === 'dark' || (choice === 'system' && prefersDark);
}

/**
* Paints `choice` on the document without storing it.
*
* Toggles `.dark` (every token and every themed image follows that class, never
* the media query), and updates `data-theme-choice` (which drives the theme
* control's icon and selected option from CSS), `color-scheme` and the single
* `theme-color` meta.
*
* Transitions are suppressed for one frame with `theme-switching`, so the
* colour transitions on links and buttons do not ripple across the page as
* every token changes at once.
*/
export function renderTheme(choice: ThemeChoice): void {
const root = document.documentElement;
const dark = resolveDark(choice, systemPrefersDark());
const forced = root.dataset.themeForced === 'dark';
const dark = forced || resolveDark(choice, systemPrefersDark());

// `theme-switching` stops link and button transitions rippling across the page as every token changes.
root.classList.add('theme-switching');
root.classList.toggle('dark', dark);
root.dataset.themeChoice = choice;
root.style.colorScheme = dark ? 'dark' : 'light';

document.querySelector('meta[name="theme-color"]')?.setAttribute('content', dark ? THEME_COLORS.dark : THEME_COLORS.light);
document
.querySelector('meta[name="theme-color"]')
?.setAttribute('content', forced ? THEME_COLORS.sale : dark ? THEME_COLORS.dark : THEME_COLORS.light);

// Reading a computed value forces the new colours to apply while
// transitions are still off; the class comes off on the next frame.
Expand All @@ -92,6 +84,19 @@ export function renderTheme(choice: ThemeChoice): void {
}
}

// Holds the page dark whatever the reader chose, without touching that choice. Returns the release.
export function forceDark(): () => void {
const root = document.documentElement;

root.dataset.themeForced = 'dark';
renderTheme(readTheme());

return () => {
delete root.dataset.themeForced;
renderTheme(readTheme());
};
}

/**
* The reader chose a theme: store it, paint it, and tell every control.
*
Expand Down
2 changes: 1 addition & 1 deletion resources/js/pages/BlackFriday.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default function BlackFriday({ content, paidFeatures, organizationProfile
const big = { big: (text: string) => <span className="sale-display block pb-2 text-foreground">{text}</span> };

return (
<LandingLayout footerNewsletter={phase === 'live'}>
<LandingLayout footerNewsletter={phase === 'live'} alwaysDark>
<SEOHead
title={title}
description={description}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
--}}
@php($campaign = \App\Support\Pricing\Campaign::current())
@php($htmlClasses = array_filter([\App\Support\Banner::shownOn(request()) ? 'has-banner' : null, $campaign?->isLive() ? 'campaign-live' : null]))
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}"@if($htmlClasses !== []) class="{{ implode(' ', $htmlClasses) }}"@endif>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}"@if($htmlClasses !== []) class="{{ implode(' ', $htmlClasses) }}"@endif{!! ($page['component'] ?? null) === 'BlackFriday' ? ' data-theme-forced="dark"' : '' !!}>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
5 changes: 3 additions & 2 deletions resources/views/partials/head-theme.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
var t = localStorage.getItem('theme');
if (t === 'dark' || t === 'system' || t === 'light') { choice = t; }
} catch (e) {}
var dark = choice === 'dark' || (choice === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);
var root = document.documentElement;
var forced = root.dataset.themeForced === 'dark';
var dark = forced || choice === 'dark' || (choice === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);
if (dark) { root.classList.add('dark'); }
root.dataset.themeChoice = choice; /* drives the control's icon without hydration */
root.style.colorScheme = dark ? 'dark' : 'light';
var m = document.querySelector('meta[name="theme-color"]');
if (m) { m.setAttribute('content', dark ? '#121212' : '#ffffff'); }
if (m) { m.setAttribute('content', forced ? '#060606' : dark ? '#121212' : '#ffffff'); }
})();
</script>
9 changes: 9 additions & 0 deletions tests/Feature/Pages/CampaignTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ function afterSale(): void
travelTo(Campaign::current()?->endsAt ?? now());
}

it('holds only the sale page dark before first paint', function (string $path, bool $forced): void {
expect(str_contains(get($path)->assertOk()->getContent(), 'data-theme-forced="dark"'))->toBe($forced);
})->with([
'the sale page' => ['/black-friday', true],
'a translated sale page' => ['/vi/black-friday', true],
'the homepage' => ['/', false],
'pricing' => ['/pricing', false],
]);

it('is upcoming before the start, live from it, and ended from the end', function (): void {
$campaign = saleCampaign();

Expand Down
54 changes: 52 additions & 2 deletions tests/js/theme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
THEME_COLORS,
THEME_STORAGE_KEY,
applyTheme,
forceDark,
parseTheme,
readTheme,
renderTheme,
Expand Down Expand Up @@ -246,8 +247,33 @@ test('another tab changing the key repaints this one without writing it back', (
assert.equal(browser.events.length, 1, 'an unrelated key changes nothing');
});

// The head partial cannot import this module, so it repeats the decision.
test('the head script and this module make the same decision', () => {
test('a forced page stays dark through every repaint and gives the reader their theme back', () => {
const browser = installBrowser({ stored: 'light', systemDark: false });

syncTheme();
const release = forceDark();

assert.ok(browser.root.classes.has('dark'));
assert.equal(browser.root.style.colorScheme, 'dark');
assert.equal(browser.themeColor.content, THEME_COLORS.sale);
assert.equal(browser.root.dataset.themeChoice, 'light');
assert.equal(browser.storage.get(THEME_STORAGE_KEY), 'light');

for (const listener of browser.listeners.get('storage') ?? []) {
listener({ key: THEME_STORAGE_KEY });
}

assert.ok(browser.root.classes.has('dark'), 'another tab cannot lighten it');

release();

assert.ok(!browser.root.classes.has('dark'));
assert.equal(browser.root.dataset.themeForced, undefined);
assert.equal(browser.root.style.colorScheme, 'light');
assert.equal(browser.themeColor.content, THEME_COLORS.light);
});

function headScript(): string {
const partial = readFileSync(
fileURLToPath(new URL('../../resources/views/partials/head-theme.blade.php', import.meta.url)),
'utf8',
Expand All @@ -256,6 +282,30 @@ test('the head script and this module make the same decision', () => {

assert.ok(script, 'the partial holds an inline script');

return script;
}

test('the head script paints a forced page dark over a stored light choice', () => {
const browser = installBrowser({ stored: 'light', systemDark: false });

browser.root.dataset.themeForced = 'dark';

new Function('window', 'localStorage', 'document', headScript())(
(globalThis as Record<string, unknown>).window,
(globalThis as unknown as { window: { localStorage: unknown } }).window.localStorage,
(globalThis as Record<string, unknown>).document,
);

assert.ok(browser.root.classes.has('dark'));
assert.equal(browser.root.dataset.themeChoice, 'light');
assert.equal(browser.root.style.colorScheme, 'dark');
assert.equal(browser.themeColor.content, THEME_COLORS.sale);
});

// The head partial cannot import this module, so it repeats the decision.
test('the head script and this module make the same decision', () => {
const script = headScript();

const cases: { stored?: string; storageThrows?: boolean; systemDark: boolean }[] = [
{ systemDark: false },
{ systemDark: true },
Expand Down