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
44 changes: 36 additions & 8 deletions apps/iris/src/components/settings/appearance-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
ToggleGroup,
ToggleGroupItem,
} from '@filcdev/ui/components/toggle-group';
import { applyColorScheme } from '@filcdev/ui/lib/color-scheme';
import {
applyColorScheme,
DEFAULT_COLOR_SCHEME,
} from '@filcdev/ui/lib/color-scheme';
import { DEFAULT_SITE_THEME } from '@filcdev/ui/lib/site-theme';
import { cn } from '@filcdev/ui/lib/utils';
import { LayoutGrid, Table2 } from 'lucide-react';
import { useTheme } from 'next-themes';
Expand Down Expand Up @@ -51,7 +55,7 @@ export function AppearancePane({
onClose: () => void;
}) {
const { t } = useTranslation();
const { setTheme: applyTheme } = useTheme();
const { resolvedTheme, setTheme: applyTheme } = useTheme();
const settingsQuery = useNotificationSettings(active);
const { setView, view } = useTimetableView(settingsQuery.data?.timetableView);
const [theme, setTheme] = useState('system');
Expand Down Expand Up @@ -132,12 +136,7 @@ export function AppearancePane({
<span className="text-sm">
{t(`preferences.colorSchemeId.${id}`)}
</span>
<span className="flex gap-1" data-color-scheme={id}>
<span className="h-3 w-3 rounded-full bg-background ring-1 ring-border" />
<span className="h-3 w-3 rounded-full bg-primary" />
<span className="h-3 w-3 rounded-full bg-accent" />
<span className="h-3 w-3 rounded-full bg-foreground" />
</span>
<SchemeSwatch dark={resolvedTheme === 'dark'} scheme={id} />
</button>
))}
</div>
Expand Down Expand Up @@ -212,3 +211,32 @@ export function AppearancePane({
</div>
);
}

/**
* One palette's four dots. `default` has no block in `schemes.css`, so without
* `data-site-theme="default"` its swatch would inherit the active seasonal skin
* from `<html>` instead of showing the everyday palette. The `dark` class keeps
* that preview on the visitor's own side of the palette.
*/
function SchemeSwatch({
dark,
scheme,
}: {
dark: boolean;
scheme: ColorScheme;
}) {
const isDefault = scheme === DEFAULT_COLOR_SCHEME;

return (
<span
className={cn('flex gap-1', isDefault && dark && 'dark')}
data-color-scheme={scheme}
data-site-theme={isDefault ? DEFAULT_SITE_THEME : undefined}
>
<span className="h-3 w-3 rounded-full bg-background ring-1 ring-border" />
<span className="h-3 w-3 rounded-full bg-primary" />
<span className="h-3 w-3 rounded-full bg-accent" />
<span className="h-3 w-3 rounded-full bg-foreground" />
</span>
);
}
5 changes: 4 additions & 1 deletion docs/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ the backdrop and the class colours are all data-driven from the id list.
The settings picker iterates the ids and renders each swatch with the palette
itself (`data-color-scheme` on the swatch), so no colours are copied into TS.
Use the palette's published values rather than derived shades — that is the
point of naming it after a known theme.
point of naming it after a known theme. The `default` id has no block, so its
swatch also carries `data-site-theme="default"`: that pins the preview to the
everyday palette instead of letting it inherit the active seasonal skin from
`<html>`.

## Subject colours come along for free

Expand Down