CMS: één bannerlijst met Locatie, SLP-thema, thema-schakelaar, documentatie
- Banner-admin: één lijst met Locatie-badge (Boven/Onder), Locatie-keuzeveld in het formulier, "Live" en "Wordt niet getoond" per locatie, aan/uit per rij - Thema slpsoftware: Archivo, bordeaux #7A1414 (WCAG AA licht en donker), <SLP/>-logo, favicon, mail-logo; VITE_THEME in de SLP-builds (test en productie-config) - Thema-schakelaar: eerste klik wisselt altijd het getoonde thema (klasse op <html> als bron van waarheid, gedeelde status, startscript valideert opslag) + tests - Docs: README, docs/cms-themas.md, docs/deploy-en-testomgevingen.md, docs/privacy-gegevens-contactformulier.md, aidlc-docs (offering-banners, bug theme-toggle-first-click) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@
|
||||
<script>
|
||||
(function () {
|
||||
var s = localStorage.getItem('cms-theme');
|
||||
var t = s ? s : (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
||||
var t = s === 'light' || s === 'dark' ? s : (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
||||
document.documentElement.classList.add(t);
|
||||
})();
|
||||
</script>
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
"@dnd-kit/core": "^6.3.1",
|
||||
"@dnd-kit/sortable": "^10.0.0",
|
||||
"@dnd-kit/utilities": "^3.2.2",
|
||||
"@fontsource/archivo": "5.3.0",
|
||||
"@fontsource/jost": "5.3.0",
|
||||
"@fontsource/marcellus": "5.3.0",
|
||||
"@hookform/resolvers": "^5.4.0",
|
||||
|
||||
Generated
+8
@@ -17,6 +17,9 @@ importers:
|
||||
'@dnd-kit/utilities':
|
||||
specifier: ^3.2.2
|
||||
version: 3.2.2(react@19.2.7)
|
||||
'@fontsource/archivo':
|
||||
specifier: 5.3.0
|
||||
version: 5.3.0
|
||||
'@fontsource/jost':
|
||||
specifier: 5.3.0
|
||||
version: 5.3.0
|
||||
@@ -386,6 +389,9 @@ packages:
|
||||
'@floating-ui/utils@0.2.11':
|
||||
resolution: {integrity: sha512-RiB/yIh78pcIxl6lLMG0CgBXAZ2Y0eVHqMPYugu+9U0AeT6YBeiJpf7lbdJNIugFP5SIjwNRgo4DhR1Qxi26Gg==}
|
||||
|
||||
'@fontsource/archivo@5.3.0':
|
||||
resolution: {integrity: sha512-5DIMgPVJRi62OqdOVoogCFxP73EkNM/E0YVTSDIQlDEJfDbxqZduwM/YoNZwC9Sx1CDgpKinqf8ckRY1QNIecw==}
|
||||
|
||||
'@fontsource/jost@5.3.0':
|
||||
resolution: {integrity: sha512-lORv5y49hSoLVxjGb0qNuBzXvnaNYI3B94200uGPGJFei8fao6d6LLz2ziWbOZubGfZnibzuT6GVNX8fBw8WQQ==}
|
||||
|
||||
@@ -2638,6 +2644,8 @@ snapshots:
|
||||
|
||||
'@floating-ui/utils@0.2.11': {}
|
||||
|
||||
'@fontsource/archivo@5.3.0': {}
|
||||
|
||||
'@fontsource/jost@5.3.0': {}
|
||||
|
||||
'@fontsource/marcellus@5.3.0': {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useForm, useWatch } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -21,9 +21,9 @@ import { useSaveOfferingBanner } from '../services/useSaveOfferingBanner';
|
||||
import type { BannerPosition, OfferingBannerDto } from '../services/types';
|
||||
|
||||
interface OfferingBannerDialogProps {
|
||||
/** Open for editing this banner (its own position applies); null with `creatingPosition` = a new one there. */
|
||||
/** Open for editing this banner; null with `creating` = a new one. */
|
||||
banner: OfferingBannerDto | null;
|
||||
creatingPosition: BannerPosition | null;
|
||||
creating: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
@@ -52,21 +52,20 @@ function toForm(banner: OfferingBannerDto | null, position: BannerPosition): Off
|
||||
};
|
||||
}
|
||||
|
||||
export function OfferingBannerDialog({ banner, creatingPosition, onClose }: OfferingBannerDialogProps) {
|
||||
export function OfferingBannerDialog({ banner, creating, onClose }: OfferingBannerDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const open = creatingPosition !== null || banner !== null;
|
||||
const position: BannerPosition = banner?.position ?? creatingPosition ?? 'bottom';
|
||||
const open = creating || banner !== null;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(next) => { if (!next) onClose(); }}>
|
||||
<DialogContent className="max-h-[90vh] overflow-y-auto sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle data-testid="banner-dialog-title">
|
||||
{banner ? t(`offerings.banners.editTitle_${position}`) : t(`offerings.banners.createTitle_${position}`)}
|
||||
{banner ? t('offerings.banners.editTitle') : t('offerings.banners.createTitle')}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
{/* Content is unmounted while closed, so every opening starts from fresh form state. */}
|
||||
<OfferingBannerForm banner={banner} position={position} onClose={onClose} />
|
||||
<OfferingBannerForm banner={banner} onClose={onClose} />
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
@@ -74,11 +73,9 @@ export function OfferingBannerDialog({ banner, creatingPosition, onClose }: Offe
|
||||
|
||||
function OfferingBannerForm({
|
||||
banner,
|
||||
position,
|
||||
onClose,
|
||||
}: {
|
||||
banner: OfferingBannerDto | null;
|
||||
position: BannerPosition;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
@@ -89,14 +86,22 @@ function OfferingBannerForm({
|
||||
register,
|
||||
handleSubmit,
|
||||
control,
|
||||
formState: { errors },
|
||||
trigger,
|
||||
formState: { errors, isSubmitted },
|
||||
} = useForm<OfferingBannerFormData>({
|
||||
resolver: zodResolver(offeringBannerFormSchema),
|
||||
mode: 'onTouched',
|
||||
defaultValues: toForm(banner, position),
|
||||
defaultValues: toForm(banner, 'bottom'),
|
||||
});
|
||||
const position: BannerPosition = useWatch({ control, name: 'position' }) ?? 'bottom';
|
||||
const textMax = bannerTextMaxLength(position);
|
||||
const textLength = (useWatch({ control, name: 'text' }) ?? '').length;
|
||||
const textTooLong = textLength > textMax;
|
||||
|
||||
// After a failed submit, switching location re-validates so stale title/text errors follow the new rules.
|
||||
useEffect(() => {
|
||||
if (isSubmitted) void trigger(['title', 'text']);
|
||||
}, [position, isSubmitted, trigger]);
|
||||
|
||||
const onSubmit = async (values: OfferingBannerFormData) => {
|
||||
setServerError(null);
|
||||
@@ -129,6 +134,19 @@ function OfferingBannerForm({
|
||||
/>
|
||||
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4" noValidate data-testid="banner-form">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="banner-position">{t('offerings.banners.position.label')}</Label>
|
||||
<select
|
||||
id="banner-position"
|
||||
data-testid="banner-position"
|
||||
className="h-10 w-full rounded-md border border-input bg-background px-3 text-sm"
|
||||
{...register('position')}
|
||||
>
|
||||
<option value="top">{t('offerings.banners.position.top')}</option>
|
||||
<option value="bottom">{t('offerings.banners.position.bottom')}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="banner-title">{t(position === 'top' ? 'offerings.banners.titleLabelOptional' : 'offerings.banners.titleLabel')}</Label>
|
||||
<Input id="banner-title" data-testid="banner-title" maxLength={100} {...register('title')} />
|
||||
@@ -152,6 +170,11 @@ function OfferingBannerForm({
|
||||
{textLength}/{textMax}
|
||||
{position === 'top' && ` · ${t('offerings.banners.textHintTop')}`}
|
||||
</p>
|
||||
{textTooLong && !errors.text && (
|
||||
<p className="text-sm text-destructive" role="alert" data-testid="banner-text-toolong">
|
||||
{t('offerings.banners.textTooLong', { length: textLength, max: textMax })}
|
||||
</p>
|
||||
)}
|
||||
<FieldError message={errors.text?.message} testId="banner-text-error" />
|
||||
</div>
|
||||
|
||||
|
||||
@@ -10,30 +10,34 @@ import { useDeleteOfferingBanner } from '../services/useDeleteOfferingBanner';
|
||||
import { useSaveOfferingBanner } from '../services/useSaveOfferingBanner';
|
||||
import { bannerStatus } from '../schemas/offeringBanner';
|
||||
import { OfferingBannerDialog } from './OfferingBannerDialog';
|
||||
import type { BannerPosition, OfferingBannerDto } from '../services/types';
|
||||
import type { OfferingBannerDto } from '../services/types';
|
||||
|
||||
const fmt = (iso: string | null) =>
|
||||
iso ? new Date(iso).toLocaleString('nl-NL', { dateStyle: 'short', timeStyle: 'short' }) : null;
|
||||
|
||||
const POSITIONS: BannerPosition[] = ['top', 'bottom'];
|
||||
|
||||
const statusVariant = { live: 'default', scheduled: 'secondary', expired: 'outline', off: 'outline' } as const;
|
||||
|
||||
/** The banner shown now for one position: among the live ones, the most recently changed wins. */
|
||||
function liveBannerOf(banners: OfferingBannerDto[], now = new Date()): OfferingBannerDto | null {
|
||||
const live = banners.filter((b) => bannerStatus(b, now) === 'live');
|
||||
if (live.length === 0) return null;
|
||||
return live.reduce((a, b) => (new Date(b.updatedAt) > new Date(a.updatedAt) ? b : a));
|
||||
/** Ids of the banners actually shown now: per position, among the live ones the most recently changed wins. */
|
||||
function shownBannerIds(banners: OfferingBannerDto[], now = new Date()): Set<string> {
|
||||
const winners = new Map<string, OfferingBannerDto>();
|
||||
for (const b of banners) {
|
||||
if (bannerStatus(b, now) !== 'live') continue;
|
||||
const current = winners.get(b.position);
|
||||
if (!current || new Date(b.updatedAt) > new Date(current.updatedAt)) winners.set(b.position, b);
|
||||
}
|
||||
return new Set([...winners.values()].map((b) => b.id));
|
||||
}
|
||||
|
||||
export function OfferingBannersTab() {
|
||||
const { t } = useTranslation();
|
||||
const { data: banners, isPending, isError } = useOfferingBanners();
|
||||
const [editing, setEditing] = useState<OfferingBannerDto | null>(null);
|
||||
const [creating, setCreating] = useState<BannerPosition | null>(null);
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [pendingDelete, setPendingDelete] = useState<OfferingBannerDto | null>(null);
|
||||
const remove = useDeleteOfferingBanner();
|
||||
const save = useSaveOfferingBanner();
|
||||
const items = banners ?? [];
|
||||
const shownIds = shownBannerIds(items);
|
||||
|
||||
const toggleActive = (b: OfferingBannerDto) =>
|
||||
save.mutate(
|
||||
@@ -63,120 +67,119 @@ export function OfferingBannersTab() {
|
||||
{isPending && <p className="text-sm text-muted-foreground">{t('common.loading')}</p>}
|
||||
{isError && <p className="text-sm text-destructive">{t('errors.generic')}</p>}
|
||||
|
||||
{!isPending &&
|
||||
!isError &&
|
||||
POSITIONS.map((position) => {
|
||||
const items = (banners ?? []).filter((b) => b.position === position);
|
||||
const live = liveBannerOf(items);
|
||||
return (
|
||||
<section key={position} className="space-y-3" data-testid={`banners-section-${position}`}>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<div className="space-y-1">
|
||||
<h2 className="text-base font-semibold">{t(`offerings.banners.section.${position}.title`)}</h2>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t(`offerings.banners.section.${position}.description`)}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground" data-testid={`banner-live-hint-${position}`}>
|
||||
{live
|
||||
? t('offerings.banners.liveNow', { title: live.title || live.text })
|
||||
: t('offerings.banners.nothingActive')}
|
||||
</p>
|
||||
</div>
|
||||
<Button type="button" onClick={() => setCreating(position)} data-testid={`banner-add-${position}`}>
|
||||
<Plus className="mr-1 size-4" aria-hidden="true" />
|
||||
{t(`offerings.banners.section.${position}.addButton`)}
|
||||
</Button>
|
||||
</div>
|
||||
{!isPending && !isError && (
|
||||
<>
|
||||
<div className="flex justify-end">
|
||||
<Button type="button" onClick={() => setCreating(true)} data-testid="banner-add">
|
||||
<Plus className="mr-1 size-4" aria-hidden="true" />
|
||||
{t('offerings.banners.addButton')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{items.length === 0 ? (
|
||||
<div
|
||||
className="flex flex-col items-center space-y-2 py-8 text-center"
|
||||
data-testid={`banners-empty-${position}`}
|
||||
>
|
||||
<Megaphone className="size-8 text-muted-foreground" aria-hidden="true" />
|
||||
<p className="text-muted-foreground">{t('offerings.banners.empty')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="space-y-2" data-testid={`banners-list-${position}`}>
|
||||
{items.map((b) => {
|
||||
const status = bannerStatus(b);
|
||||
const toggleLabel = t(
|
||||
b.isActive ? 'offerings.banners.turnOffButton' : 'offerings.banners.turnOnButton',
|
||||
);
|
||||
return (
|
||||
<li
|
||||
key={b.id}
|
||||
className="flex flex-col gap-2 rounded-md border p-3 sm:flex-row sm:items-center sm:justify-between"
|
||||
data-testid={`banner-row-${b.id}`}
|
||||
{items.length === 0 ? (
|
||||
<div className="flex flex-col items-center space-y-2 py-8 text-center" data-testid="banners-empty">
|
||||
<Megaphone className="size-8 text-muted-foreground" aria-hidden="true" />
|
||||
<p className="text-muted-foreground">{t('offerings.banners.empty')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<ul className="space-y-2" data-testid="banners-list">
|
||||
{items.map((b) => {
|
||||
const status = bannerStatus(b);
|
||||
const shown = shownIds.has(b.id);
|
||||
const hidden = status === 'live' && !shown;
|
||||
const toggleLabel = t(
|
||||
b.isActive ? 'offerings.banners.turnOffButton' : 'offerings.banners.turnOnButton',
|
||||
);
|
||||
return (
|
||||
<li
|
||||
key={b.id}
|
||||
className="flex flex-col gap-2 rounded-md border p-3 sm:flex-row sm:items-center sm:justify-between"
|
||||
data-testid={`banner-row-${b.id}`}
|
||||
>
|
||||
<div className="min-w-0 space-y-1">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{b.title && <span className="font-medium">{b.title}</span>}
|
||||
<Badge variant="outline" data-testid={`banner-position-${b.id}`}>
|
||||
{t(`offerings.banners.position.${b.position}`)}
|
||||
</Badge>
|
||||
<Badge variant={statusVariant[status]} data-testid={`banner-status-${b.id}`}>
|
||||
{t(`offerings.banners.status.${status}`)}
|
||||
</Badge>
|
||||
{shown && (
|
||||
<Badge data-testid={`banner-shown-${b.id}`}>{t('offerings.banners.shownBadge')}</Badge>
|
||||
)}
|
||||
{hidden && (
|
||||
<Badge variant="destructive" data-testid={`banner-not-shown-${b.id}`}>
|
||||
{t('offerings.banners.notShownBadge')}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="truncate text-sm text-muted-foreground">{b.text}</p>
|
||||
{hidden && (
|
||||
<p className="text-xs text-destructive" data-testid={`banner-not-shown-hint-${b.id}`}>
|
||||
{t('offerings.banners.notShownHint')}
|
||||
</p>
|
||||
)}
|
||||
{(b.startsAt || b.endsAt) && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{fmt(b.startsAt) ?? '…'} – {fmt(b.endsAt) ?? '…'}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex shrink-0 gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="size-11"
|
||||
aria-label={toggleLabel}
|
||||
title={toggleLabel}
|
||||
disabled={save.isPending}
|
||||
data-testid={`banner-toggle-${b.id}`}
|
||||
onClick={() => toggleActive(b)}
|
||||
>
|
||||
<div className="min-w-0 space-y-1">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{b.title && <span className="font-medium">{b.title}</span>}
|
||||
<Badge variant={statusVariant[status]} data-testid={`banner-status-${b.id}`}>
|
||||
{t(`offerings.banners.status.${status}`)}
|
||||
</Badge>
|
||||
</div>
|
||||
<p className="truncate text-sm text-muted-foreground">{b.text}</p>
|
||||
{(b.startsAt || b.endsAt) && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{fmt(b.startsAt) ?? '…'} – {fmt(b.endsAt) ?? '…'}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex shrink-0 gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="size-11"
|
||||
aria-label={toggleLabel}
|
||||
title={toggleLabel}
|
||||
disabled={save.isPending}
|
||||
data-testid={`banner-toggle-${b.id}`}
|
||||
onClick={() => toggleActive(b)}
|
||||
>
|
||||
<Power className="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="size-11"
|
||||
aria-label={t('offerings.banners.editButton')}
|
||||
title={t('offerings.banners.editButton')}
|
||||
data-testid={`banner-edit-${b.id}`}
|
||||
onClick={() => setEditing(b)}
|
||||
>
|
||||
<Pencil className="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="size-11"
|
||||
aria-label={t('offerings.banners.deleteButton')}
|
||||
title={t('offerings.banners.deleteButton')}
|
||||
data-testid={`banner-delete-${b.id}`}
|
||||
onClick={() => setPendingDelete(b)}
|
||||
>
|
||||
<Trash2 className="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
<Power className="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="size-11"
|
||||
aria-label={t('offerings.banners.editButton')}
|
||||
title={t('offerings.banners.editButton')}
|
||||
data-testid={`banner-edit-${b.id}`}
|
||||
onClick={() => setEditing(b)}
|
||||
>
|
||||
<Pencil className="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="size-11"
|
||||
aria-label={t('offerings.banners.deleteButton')}
|
||||
title={t('offerings.banners.deleteButton')}
|
||||
data-testid={`banner-delete-${b.id}`}
|
||||
onClick={() => setPendingDelete(b)}
|
||||
>
|
||||
<Trash2 className="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
<OfferingBannerDialog
|
||||
banner={editing}
|
||||
creatingPosition={creating}
|
||||
creating={creating}
|
||||
onClose={() => {
|
||||
setEditing(null);
|
||||
setCreating(null);
|
||||
setCreating(false);
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { screen, waitFor, within } from '@testing-library/react';
|
||||
import { fireEvent, screen, waitFor, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { renderApp, mockAuthenticated } from '@/test/utils';
|
||||
import { getMockBanners, resetMockOfferings, setMockBanners } from '@/features/offerings/mocks/handlers';
|
||||
@@ -55,24 +55,19 @@ describe('Banner tab', () => {
|
||||
expect(await screen.findByTestId('offerings-add-button')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows two sections (top and bottom), each with its own empty state and "nothing active" hint', async () => {
|
||||
it('shows one list with an empty state and a single add button', async () => {
|
||||
await openBannerTab();
|
||||
const top = await screen.findByTestId('banners-section-top', {}, T);
|
||||
const bottom = screen.getByTestId('banners-section-bottom');
|
||||
expect(within(top).getByTestId('banners-empty-top')).toBeInTheDocument();
|
||||
expect(within(bottom).getByTestId('banners-empty-bottom')).toBeInTheDocument();
|
||||
expect(within(top).getByTestId('banner-add-top')).toBeInTheDocument();
|
||||
expect(within(bottom).getByTestId('banner-add-bottom')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('banner-live-hint-top')).toHaveTextContent(/niets actief|Nothing is active/);
|
||||
expect(screen.getByTestId('banner-live-hint-bottom')).toHaveTextContent(/niets actief|Nothing is active/);
|
||||
expect(await screen.findByTestId('banners-empty', {}, T)).toBeInTheDocument();
|
||||
expect(screen.getByTestId('banner-add')).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('banners-section-top')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('banner-add-top')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('creates a bottom banner with a link and a schedule, sending position bottom', async () => {
|
||||
it('creates a banner defaulting to location bottom, with a link and a schedule', async () => {
|
||||
await openBannerTab();
|
||||
expect(await screen.findByTestId('banners-empty-bottom', {}, T)).toBeInTheDocument();
|
||||
|
||||
await userEvent.click(screen.getByTestId('banner-add-bottom'));
|
||||
await userEvent.type(await screen.findByTestId('banner-title'), 'Zomeractie');
|
||||
await userEvent.click(await screen.findByTestId('banner-add', {}, T));
|
||||
expect(await screen.findByTestId('banner-position')).toHaveValue('bottom');
|
||||
await userEvent.type(screen.getByTestId('banner-title'), 'Zomeractie');
|
||||
await userEvent.type(screen.getByTestId('banner-text'), '10% korting in juli');
|
||||
await userEvent.type(screen.getByTestId('banner-link-label'), 'Bekijk');
|
||||
await userEvent.type(screen.getByTestId('banner-link-url'), '/privacy');
|
||||
@@ -91,41 +86,67 @@ describe('Banner tab', () => {
|
||||
});
|
||||
expect(saved.startsAt).toBe(fromLocalInput('2030-07-01T09:00'));
|
||||
expect(await screen.findByText('Zomeractie')).toBeInTheDocument();
|
||||
expect(within(screen.getByTestId('banners-section-bottom')).getByTestId(`banner-status-${saved.id}`)).toHaveTextContent(
|
||||
/Gepland|Scheduled/,
|
||||
);
|
||||
expect(screen.getByTestId('banners-empty-top')).toBeInTheDocument();
|
||||
expect(screen.getByTestId(`banner-position-${saved.id}`)).toHaveTextContent(/Onder|Bottom/);
|
||||
expect(screen.getByTestId(`banner-status-${saved.id}`)).toHaveTextContent(/Gepland|Scheduled/);
|
||||
});
|
||||
|
||||
it('requires a title for a bottom banner', async () => {
|
||||
it('requires a title at location bottom', async () => {
|
||||
await openBannerTab();
|
||||
await userEvent.click(await screen.findByTestId('banner-add-bottom', {}, T));
|
||||
await userEvent.click(await screen.findByTestId('banner-add', {}, T));
|
||||
await userEvent.type(await screen.findByTestId('banner-text'), 'Alleen tekst');
|
||||
await userEvent.click(screen.getByTestId('banner-submit'));
|
||||
expect(await screen.findByTestId('banner-title-error')).toBeInTheDocument();
|
||||
expect(getMockBanners()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('creates a top banner without a title, limited to 120 characters with a counter', async () => {
|
||||
it('creates a top banner without a title; the text limit follows the chosen location live', async () => {
|
||||
await openBannerTab();
|
||||
await userEvent.click(await screen.findByTestId('banner-add-top', {}, T));
|
||||
expect(await screen.findByTestId('banner-text')).toHaveAttribute('maxlength', '120');
|
||||
await userEvent.click(await screen.findByTestId('banner-add', {}, T));
|
||||
const text = await screen.findByTestId('banner-text');
|
||||
expect(text).toHaveAttribute('maxlength', '300');
|
||||
expect(screen.getByTestId('banner-text-counter')).toHaveTextContent('0/300');
|
||||
|
||||
await userEvent.selectOptions(screen.getByTestId('banner-position'), 'top');
|
||||
expect(text).toHaveAttribute('maxlength', '120');
|
||||
expect(screen.getByTestId('banner-text-counter')).toHaveTextContent('0/120');
|
||||
|
||||
await userEvent.type(screen.getByTestId('banner-text'), 'Gratis verzending deze week');
|
||||
await userEvent.type(text, 'Gratis verzending deze week');
|
||||
expect(screen.getByTestId('banner-text-counter')).toHaveTextContent('27/120');
|
||||
await userEvent.click(screen.getByTestId('banner-submit'));
|
||||
|
||||
await waitFor(() => expect(getMockBanners()).toHaveLength(1));
|
||||
expect(getMockBanners()[0]).toMatchObject({ position: 'top', title: '', text: 'Gratis verzending deze week' });
|
||||
const top = screen.getByTestId('banners-section-top');
|
||||
expect(await within(top).findByText('Gratis verzending deze week')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('banners-empty-bottom')).toBeInTheDocument();
|
||||
const saved = getMockBanners()[0];
|
||||
expect(saved).toMatchObject({ position: 'top', title: '', text: 'Gratis verzending deze week' });
|
||||
expect(await screen.findByTestId(`banner-position-${saved.id}`)).toHaveTextContent(/Boven|Top/);
|
||||
});
|
||||
|
||||
it('does not silently truncate: switching to top with too long text shows a visible error and blocks saving', async () => {
|
||||
await openBannerTab();
|
||||
await userEvent.click(await screen.findByTestId('banner-add', {}, T));
|
||||
await userEvent.type(await screen.findByTestId('banner-title'), 'Titel');
|
||||
fireEvent.change(screen.getByTestId('banner-text'), { target: { value: 'x'.repeat(200) } });
|
||||
expect(screen.getByTestId('banner-text-counter')).toHaveTextContent('200/300');
|
||||
expect(screen.queryByTestId('banner-text-toolong')).not.toBeInTheDocument();
|
||||
|
||||
await userEvent.selectOptions(screen.getByTestId('banner-position'), 'top');
|
||||
expect(screen.getByTestId('banner-text')).toHaveValue('x'.repeat(200));
|
||||
expect(screen.getByTestId('banner-text-counter')).toHaveTextContent('200/120');
|
||||
expect(await screen.findByTestId('banner-text-toolong')).toBeInTheDocument();
|
||||
|
||||
await userEvent.click(screen.getByTestId('banner-submit'));
|
||||
expect(await screen.findByTestId('banner-text-error')).toBeInTheDocument();
|
||||
expect(getMockBanners()).toHaveLength(0);
|
||||
|
||||
await userEvent.selectOptions(screen.getByTestId('banner-position'), 'bottom');
|
||||
await waitFor(() => expect(screen.queryByTestId('banner-text-error')).not.toBeInTheDocument());
|
||||
expect(screen.queryByTestId('banner-text-toolong')).not.toBeInTheDocument();
|
||||
await userEvent.click(screen.getByTestId('banner-submit'));
|
||||
await waitFor(() => expect(getMockBanners()).toHaveLength(1));
|
||||
});
|
||||
|
||||
it('rejects an unsafe link and a link without button text, and an end before the start', async () => {
|
||||
await openBannerTab();
|
||||
await userEvent.click(await screen.findByTestId('banner-add-bottom', {}, T));
|
||||
await userEvent.click(await screen.findByTestId('banner-add', {}, T));
|
||||
await userEvent.type(await screen.findByTestId('banner-title'), 'X');
|
||||
await userEvent.type(screen.getByTestId('banner-text'), 'Y');
|
||||
|
||||
@@ -148,41 +169,58 @@ describe('Banner tab', () => {
|
||||
expect(getMockBanners()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('lists banners under their own position and shows which one is live (most recently changed wins)', async () => {
|
||||
it('lists all banners in one list in API order with a location badge per row', async () => {
|
||||
setMockBanners([
|
||||
banner({ id: 'b-old', title: 'Oud', updatedAt: '2026-01-01T00:00:00Z' }),
|
||||
banner({ id: 'b-new', title: 'Nieuw', updatedAt: '2026-02-01T00:00:00Z' }),
|
||||
banner({ id: 't1', position: 'top', title: '', text: 'Balktekst' }),
|
||||
]);
|
||||
await openBannerTab();
|
||||
const top = await screen.findByTestId('banners-section-top', {}, T);
|
||||
const bottom = screen.getByTestId('banners-section-bottom');
|
||||
|
||||
expect(within(top).getByTestId('banner-row-t1')).toBeInTheDocument();
|
||||
expect(within(top).queryByTestId('banner-row-b-new')).not.toBeInTheDocument();
|
||||
expect(within(bottom).getByTestId('banner-row-b-old')).toBeInTheDocument();
|
||||
expect(within(bottom).getByTestId('banner-row-b-new')).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByTestId('banner-live-hint-bottom')).toHaveTextContent(/Nu live: Nieuw|Live now: Nieuw/);
|
||||
expect(screen.getByTestId('banner-live-hint-top')).toHaveTextContent(/Balktekst/);
|
||||
const list = await screen.findByTestId('banners-list', {}, T);
|
||||
const rows = within(list).getAllByTestId(/^banner-row-/);
|
||||
expect(rows.map((r) => r.getAttribute('data-testid'))).toEqual(['banner-row-b-new', 'banner-row-t1']);
|
||||
expect(screen.getByTestId('banner-position-b-new')).toHaveTextContent(/Onder|Bottom/);
|
||||
expect(screen.getByTestId('banner-position-t1')).toHaveTextContent(/Boven|Top/);
|
||||
});
|
||||
|
||||
it('turns a banner off and on from its section', async () => {
|
||||
setMockBanners([banner({ id: 't1', position: 'top', title: '', text: 'Balktekst' })]);
|
||||
it('marks the shown banner per location and flags older live banners on the same location as not shown', async () => {
|
||||
setMockBanners([
|
||||
banner({ id: 'b-old', title: 'Oud', updatedAt: '2026-01-01T00:00:00Z' }),
|
||||
banner({ id: 'b-new', title: 'Nieuw', updatedAt: '2026-02-01T00:00:00Z' }),
|
||||
banner({ id: 't1', position: 'top', title: '', text: 'Balktekst' }),
|
||||
banner({ id: 'b-off', title: 'Uit', isActive: false, updatedAt: '2026-03-01T00:00:00Z' }),
|
||||
]);
|
||||
await openBannerTab();
|
||||
expect(await screen.findByTestId('banner-status-t1', {}, T)).toHaveTextContent(/Actief|Active/);
|
||||
|
||||
await userEvent.click(screen.getByTestId('banner-toggle-t1'));
|
||||
await waitFor(() => expect(getMockBanners()[0].isActive).toBe(false));
|
||||
expect(getMockBanners()[0].position).toBe('top');
|
||||
expect(await screen.findByTestId('banner-status-t1')).toHaveTextContent(/Uit|Off/);
|
||||
expect(screen.getByTestId('banner-live-hint-top')).toHaveTextContent(/niets actief|Nothing is active/);
|
||||
|
||||
await userEvent.click(screen.getByTestId('banner-toggle-t1'));
|
||||
await waitFor(() => expect(getMockBanners()[0].isActive).toBe(true));
|
||||
expect(await screen.findByTestId('banner-shown-b-new', {}, T)).toBeInTheDocument();
|
||||
expect(screen.getByTestId('banner-shown-t1')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('banner-not-shown-b-old')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('banner-not-shown-hint-b-old')).toHaveTextContent(/niet getoond|Not shown/);
|
||||
expect(screen.queryByTestId('banner-shown-b-old')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('banner-not-shown-b-new')).not.toBeInTheDocument();
|
||||
// An inactive banner is neither shown nor flagged.
|
||||
expect(screen.queryByTestId('banner-shown-b-off')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('banner-not-shown-b-off')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('edits and deletes an existing banner, keeping its position', async () => {
|
||||
it('turns a banner off and on, moving the shown mark to the next live banner', async () => {
|
||||
setMockBanners([
|
||||
banner({ id: 'b-old', title: 'Oud', updatedAt: '2026-01-01T00:00:00Z' }),
|
||||
banner({ id: 'b-new', title: 'Nieuw', updatedAt: '2026-02-01T00:00:00Z' }),
|
||||
]);
|
||||
await openBannerTab();
|
||||
expect(await screen.findByTestId('banner-status-b-new', {}, T)).toHaveTextContent(/Actief|Active/);
|
||||
|
||||
await userEvent.click(screen.getByTestId('banner-toggle-b-new'));
|
||||
await waitFor(() => expect(getMockBanners().find((b) => b.id === 'b-new')?.isActive).toBe(false));
|
||||
expect(getMockBanners().find((b) => b.id === 'b-new')?.position).toBe('bottom');
|
||||
expect(await screen.findByTestId('banner-status-b-new')).toHaveTextContent(/Uit|Off/);
|
||||
expect(await screen.findByTestId('banner-shown-b-old')).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('banner-not-shown-b-old')).not.toBeInTheDocument();
|
||||
|
||||
await userEvent.click(screen.getByTestId('banner-toggle-b-new'));
|
||||
await waitFor(() => expect(getMockBanners().find((b) => b.id === 'b-new')?.isActive).toBe(true));
|
||||
});
|
||||
|
||||
it('edits a banner including its location (top keeps title optional), then deletes it', async () => {
|
||||
setMockBanners([banner({ id: 'b1', title: 'Oud' })]);
|
||||
await openBannerTab();
|
||||
expect(await screen.findByTestId('banner-status-b1', {}, T)).toHaveTextContent(/Actief|Active/);
|
||||
@@ -190,18 +228,21 @@ describe('Banner tab', () => {
|
||||
await userEvent.click(screen.getByTestId('banner-edit-b1'));
|
||||
const title = await screen.findByTestId('banner-title');
|
||||
expect(title).toHaveValue('Oud');
|
||||
expect(screen.getByTestId('banner-position')).toHaveValue('bottom');
|
||||
await userEvent.clear(title);
|
||||
await userEvent.type(title, 'Nieuw');
|
||||
await userEvent.selectOptions(screen.getByTestId('banner-position'), 'top');
|
||||
expect(screen.getByTestId('banner-text')).toHaveAttribute('maxlength', '120');
|
||||
await userEvent.click(screen.getByTestId('banner-active'));
|
||||
await userEvent.click(screen.getByTestId('banner-submit'));
|
||||
await waitFor(() => expect(getMockBanners()[0]).toMatchObject({ title: 'Nieuw', isActive: false, position: 'bottom' }));
|
||||
await waitFor(() => expect(getMockBanners()[0]).toMatchObject({ title: '', isActive: false, position: 'top' }));
|
||||
expect(await screen.findByTestId('banner-status-b1')).toHaveTextContent(/Uit|Off/);
|
||||
expect(screen.getByTestId('banner-position-b1')).toHaveTextContent(/Boven|Top/);
|
||||
|
||||
await userEvent.click(screen.getByTestId('banner-delete-b1'));
|
||||
expect(await screen.findByTestId('banner-delete-message')).toHaveTextContent('Nieuw');
|
||||
expect(await screen.findByTestId('banner-delete-message')).toHaveTextContent('Tekst');
|
||||
await userEvent.click(screen.getByTestId('banner-delete-confirm'));
|
||||
await waitFor(() => expect(getMockBanners()).toHaveLength(0));
|
||||
expect(await screen.findByTestId('banners-empty-bottom')).toBeInTheDocument();
|
||||
expect(await screen.findByTestId('banners-empty')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -48,3 +48,57 @@ describe('useTheme', () => {
|
||||
expect(document.documentElement.classList.contains('light')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('first click', () => {
|
||||
const media = (dark: boolean) => vi.spyOn(window, 'matchMedia').mockReturnValue({ matches: dark } as MediaQueryList);
|
||||
const shown = () => (document.documentElement.classList.contains('dark') ? 'dark' : 'light');
|
||||
|
||||
it.each([
|
||||
['light', 'dark'],
|
||||
['dark', 'light'],
|
||||
])('flips the shown theme straight away when the OS prefers %s and nothing is stored or applied', (os, expected) => {
|
||||
media(os === 'dark');
|
||||
const { result } = renderHook(() => useTheme());
|
||||
|
||||
expect(shown()).toBe(os);
|
||||
act(() => { result.current.toggleTheme(); });
|
||||
|
||||
expect(shown()).toBe(expected);
|
||||
expect(result.current.theme).toBe(expected);
|
||||
});
|
||||
|
||||
it('flips from what is shown even when the stored value is unusable', () => {
|
||||
localStorage.setItem('cms-theme', 'system');
|
||||
media(true);
|
||||
document.documentElement.className = 'system';
|
||||
const { result } = renderHook(() => useTheme());
|
||||
|
||||
expect(shown()).toBe('dark');
|
||||
act(() => { result.current.toggleTheme(); });
|
||||
expect(shown()).toBe('light');
|
||||
});
|
||||
|
||||
it('follows the shown theme when it differs from the stored one', () => {
|
||||
localStorage.setItem('cms-theme', 'light');
|
||||
document.documentElement.className = 'dark';
|
||||
const { result } = renderHook(() => useTheme());
|
||||
|
||||
expect(result.current.theme).toBe('dark');
|
||||
act(() => { result.current.toggleTheme(); });
|
||||
expect(shown()).toBe('light');
|
||||
expect(localStorage.getItem('cms-theme')).toBe('light');
|
||||
});
|
||||
|
||||
it('keeps two toggles on the page in step', () => {
|
||||
localStorage.setItem('cms-theme', 'light');
|
||||
const a = renderHook(() => useTheme());
|
||||
const b = renderHook(() => useTheme());
|
||||
|
||||
act(() => { a.result.current.toggleTheme(); });
|
||||
expect(b.result.current.theme).toBe('dark');
|
||||
|
||||
act(() => { b.result.current.toggleTheme(); });
|
||||
expect(shown()).toBe('light');
|
||||
expect(a.result.current.theme).toBe('light');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,26 +1,62 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useCallback, useSyncExternalStore } from 'react';
|
||||
|
||||
type Theme = 'light' | 'dark';
|
||||
|
||||
const STORAGE_KEY = 'cms-theme';
|
||||
|
||||
function getInitialTheme(): Theme {
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function isTheme(value: string | null): value is Theme {
|
||||
return value === 'light' || value === 'dark';
|
||||
}
|
||||
|
||||
function preferredTheme(): Theme {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
if (stored === 'light' || stored === 'dark') return stored;
|
||||
if (isTheme(stored)) return stored;
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
function apply(theme: Theme) {
|
||||
document.documentElement.classList.remove('light', 'dark');
|
||||
document.documentElement.classList.add(theme);
|
||||
}
|
||||
|
||||
/**
|
||||
* The theme that is actually shown, which is what the <html> class says: the stylesheet only
|
||||
* knows that class. The stored value and the OS preference are only the way to pick a theme when
|
||||
* the page carries none (or an unusable one); in that case it is applied right away, so the state
|
||||
* we report and what the user sees can never differ. A first click then always flips what is shown.
|
||||
*/
|
||||
function currentTheme(): Theme {
|
||||
const classes = document.documentElement.classList;
|
||||
if (classes.contains('dark')) return 'dark';
|
||||
if (classes.contains('light')) return 'light';
|
||||
|
||||
const theme = preferredTheme();
|
||||
apply(theme);
|
||||
return theme;
|
||||
}
|
||||
|
||||
function subscribe(listener: () => void) {
|
||||
listeners.add(listener);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
}
|
||||
|
||||
export function useTheme() {
|
||||
const [theme, setTheme] = useState<Theme>(getInitialTheme);
|
||||
// One source of truth shared by every toggle on the page (desktop sidebar, mobile overlay).
|
||||
const theme = useSyncExternalStore(subscribe, currentTheme, () => 'light' as Theme);
|
||||
|
||||
const toggleTheme = useCallback(() => {
|
||||
setTheme((current) => {
|
||||
const next: Theme = current === 'dark' ? 'light' : 'dark';
|
||||
const next: Theme = currentTheme() === 'dark' ? 'light' : 'dark';
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, next);
|
||||
document.documentElement.classList.remove('light', 'dark');
|
||||
document.documentElement.classList.add(next);
|
||||
return next;
|
||||
});
|
||||
} catch {
|
||||
// Storage can be unavailable (private mode); the switch itself still works.
|
||||
}
|
||||
apply(next);
|
||||
listeners.forEach((notify) => notify());
|
||||
}, []);
|
||||
|
||||
return { theme, isDark: theme === 'dark', toggleTheme };
|
||||
|
||||
@@ -325,28 +325,19 @@
|
||||
"title": "Offerings",
|
||||
"addButton": "Add Offering",
|
||||
"banners": {
|
||||
"intro": "A banner is a wide announcement or promotion on the website. Plan ahead with a start and end time. At most one banner is shown per spot (top and bottom) at any time: the most recently changed active one.",
|
||||
"section": {
|
||||
"top": {
|
||||
"title": "Top",
|
||||
"description": "Narrow bar at the top of the website, one line of text.",
|
||||
"addButton": "Add top banner"
|
||||
},
|
||||
"bottom": {
|
||||
"title": "Bottom",
|
||||
"description": "Large banner at the bottom of the page with title, text and button.",
|
||||
"addButton": "Add bottom banner"
|
||||
}
|
||||
"intro": "A banner is a wide announcement or promotion on the website. Plan ahead with a start and end time. At most one banner is shown per location (top and bottom) at any time: the most recently changed active one.",
|
||||
"position": {
|
||||
"label": "Location",
|
||||
"top": "Top",
|
||||
"bottom": "Bottom"
|
||||
},
|
||||
"liveNow": "Live now: {{title}}",
|
||||
"nothingActive": "Nothing is active in this spot right now.",
|
||||
"shownBadge": "Live",
|
||||
"notShownBadge": "Not shown",
|
||||
"notShownHint": "Not shown: a newer banner at this location",
|
||||
"turnOffButton": "Turn banner off",
|
||||
"turnOnButton": "Turn banner on",
|
||||
"createTitle_top": "New banner (top)",
|
||||
"createTitle_bottom": "New banner (bottom)",
|
||||
"editTitle_top": "Edit banner (top)",
|
||||
"editTitle_bottom": "Edit banner (bottom)",
|
||||
"titleLabelOptional": "Title (optional)",
|
||||
"textTooLong": "The text is {{length}} characters; this location allows at most {{max}}. Shorten the text or pick another location.",
|
||||
"textHintTop": "One short line, up to 120 characters.",
|
||||
"addButton": "Add banner",
|
||||
"empty": "No banners yet.",
|
||||
|
||||
@@ -325,28 +325,19 @@
|
||||
"title": "Aanbiedingen",
|
||||
"addButton": "Aanbieding toevoegen",
|
||||
"banners": {
|
||||
"intro": "Een banner is een brede mededeling of actie op de website. Plan vooruit met een begin- en eindtijd. Per plek (boven en onder) wordt altijd maximaal één banner getoond: de laatst gewijzigde actieve.",
|
||||
"section": {
|
||||
"top": {
|
||||
"title": "Boven",
|
||||
"description": "Smalle balk bovenaan de website, één regel tekst.",
|
||||
"addButton": "Banner boven toevoegen"
|
||||
},
|
||||
"bottom": {
|
||||
"title": "Onder",
|
||||
"description": "Grote banner onderaan de pagina met titel, tekst en knop.",
|
||||
"addButton": "Banner onder toevoegen"
|
||||
}
|
||||
"intro": "Een banner is een brede mededeling of actie op de website. Plan vooruit met een begin- en eindtijd. Per locatie (boven en onder) wordt maximaal één banner getoond: de laatst gewijzigde actieve.",
|
||||
"position": {
|
||||
"label": "Locatie",
|
||||
"top": "Boven",
|
||||
"bottom": "Onder"
|
||||
},
|
||||
"liveNow": "Nu live: {{title}}",
|
||||
"nothingActive": "Er is nu niets actief op deze plek.",
|
||||
"shownBadge": "Live",
|
||||
"notShownBadge": "Wordt niet getoond",
|
||||
"notShownHint": "Wordt niet getoond: nieuwere banner op deze locatie",
|
||||
"turnOffButton": "Banner uitzetten",
|
||||
"turnOnButton": "Banner aanzetten",
|
||||
"createTitle_top": "Nieuwe banner (boven)",
|
||||
"createTitle_bottom": "Nieuwe banner (onder)",
|
||||
"editTitle_top": "Banner bewerken (boven)",
|
||||
"editTitle_bottom": "Banner bewerken (onder)",
|
||||
"titleLabelOptional": "Titel (optioneel)",
|
||||
"textTooLong": "De tekst is {{length}} tekens; voor deze locatie zijn maximaal {{max}} tekens toegestaan. Kort de tekst in of kies een andere locatie.",
|
||||
"textHintTop": "Eén korte regel, maximaal 120 tekens.",
|
||||
"addButton": "Banner toevoegen",
|
||||
"empty": "Nog geen banners.",
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('resolveTheme', () => {
|
||||
});
|
||||
|
||||
it('lists the available themes', () => {
|
||||
expect(availableThemes()).toContain('asf');
|
||||
expect(availableThemes()).toEqual(expect.arrayContaining(['asf', 'slpsoftware']));
|
||||
});
|
||||
|
||||
it.each(['nope', '../asf', 'asf/../asf', '..', 'ASF', 'asf asf'])('rejects %j loudly, naming the real themes', (name) => {
|
||||
@@ -99,3 +99,35 @@ describe('asf theme tokens', () => {
|
||||
expect(theme).toContain('@fontsource/marcellus');
|
||||
});
|
||||
});
|
||||
|
||||
describe('slpsoftware theme', () => {
|
||||
it('resolves stylesheet, favicon, logo pair and e-mail logo', () => {
|
||||
const theme = resolveTheme('slpsoftware');
|
||||
|
||||
expect(theme.css.replaceAll('\\', '/')).toMatch(/themes\/slpsoftware\/theme\.css$/);
|
||||
expect(fs.existsSync(theme.css)).toBe(true);
|
||||
expect(theme.favicon !== null && fs.existsSync(theme.favicon)).toBe(true);
|
||||
expect(theme.logo).not.toBeNull();
|
||||
for (const f of [theme.logo!.onLight, theme.logo!.onDark, theme.logo!.mail!]) {
|
||||
expect(fs.readFileSync(f).subarray(1, 4).toString()).toBe('PNG');
|
||||
}
|
||||
});
|
||||
|
||||
it('self-hosts Archivo and invents no structural token', () => {
|
||||
const css = fs.readFileSync(path.resolve(__dirname, 'slpsoftware/theme.css'), 'utf-8');
|
||||
const base = fs.readFileSync(path.resolve(__dirname, '../src/index.css'), 'utf-8');
|
||||
const names = (src: string, block: string) => {
|
||||
const m = src.match(new RegExp(`${block}\\s*\\{([^}]*)\\}`));
|
||||
return new Set([...(m?.[1] ?? '').matchAll(/(--[a-z-]+)\s*:/g)].map((x) => x[1]));
|
||||
};
|
||||
|
||||
expect(css).not.toMatch(/https?:\/\//);
|
||||
expect(css).toContain('@fontsource/archivo');
|
||||
for (const block of ['\\:root', '\\.dark']) {
|
||||
const existing = names(base, block);
|
||||
const themed = names(css, block);
|
||||
for (const t of existing) expect(themed, `${block} ${t}`).toContain(t);
|
||||
for (const t of themed) if (!existing.has(t)) expect(t).toMatch(/^--(slp-|font-sans$)/);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
def lum(h):
|
||||
h=h.lstrip('#'); c=[int(h[i:i+2],16)/255 for i in (0,2,4)]
|
||||
c=[x/12.92 if x<=0.03928 else ((x+0.055)/1.055)**2.4 for x in c]
|
||||
return .2126*c[0]+.7152*c[1]+.0722*c[2]
|
||||
def cr(a,b):
|
||||
la,lb=sorted([lum(a),lum(b)],reverse=True); return (la+.05)/(lb+.05)
|
||||
L=dict(bg='#ffffff',fg='#1a1a1a',card='#f7f7f7',primary='#7a1414',pf='#ffffff',muted='#f4f4f5',mfg='#5c5c5c',accent='#f6e9e9',afg='#7a1414',destr='#c62828',dfg='#ffffff',ring='#7a1414')
|
||||
D=dict(bg='#141414',fg='#f5f5f5',card='#1e1e1e',primary='#e0646c',pf='#141414',muted='#2a2a2a',mfg='#b0b0b0',accent='#3a1f21',afg='#f0a0a6',destr='#ff7b72',dfg='#141414',ring='#e0646c')
|
||||
for n,t in (('light',L),('dark',D)):
|
||||
print(n)
|
||||
for lab,a,b,m in [('foreground/background','fg','bg',4.5),('card-foreground/card','fg','card',4.5),('primary-foreground/primary','pf','primary',4.5),('primary(link)/background','primary','bg',4.5),('primary/card','primary','card',4.5),('muted-foreground/background','mfg','bg',4.5),('muted-foreground/card','mfg','card',4.5),('muted-foreground/muted','mfg','muted',4.5),('accent-foreground/accent','afg','accent',4.5),('destructive-foreground/destructive','dfg','destr',4.5),('destructive/background','destr','bg',4.5),('ring/background','ring','bg',3),('ring/card','ring','card',3)]:
|
||||
r=cr(t[a],t[b]); print(f' {lab:38s}{r:6.2f} {"OK" if r>=m else "FAIL"} (min {m})')
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-20 0 3658 824" role="img" aria-label="SLP Software">
|
||||
<path fill="#7a1414" transform="translate(0 756) scale(1 -1)" d="M565 -6 63 194V327L565 527V399L197 260L565 121Z"/>
|
||||
<path fill="#1a1a1a" transform="translate(649 756) scale(1 -1)" d="M360 -12Q295 -12 238.0 -0.5Q181 11 137.5 37.0Q94 63 69.0 105.5Q44 148 44 210Q44 214 44.0 219.0Q44 224 45 227H218Q218 224 217.5 219.5Q217 215 217 212Q217 180 233.5 160.5Q250 141 280.0 132.5Q310 124 350 124Q372 124 391.0 126.0Q410 128 425.0 133.0Q440 138 451.5 145.5Q463 153 468.5 163.5Q474 174 474 188Q474 211 456.5 226.0Q439 241 409.5 251.0Q380 261 343.0 270.0Q306 279 266.0 289.0Q226 299 189.0 314.0Q152 329 122.5 352.0Q93 375 75.5 409.5Q58 444 58 493Q58 547 81.0 586.5Q104 626 144.5 651.0Q185 676 238.0 687.5Q291 699 351 699Q410 699 461.5 687.0Q513 675 553.0 649.5Q593 624 615.5 585.5Q638 547 639 493V481H467V488Q467 511 454.5 528.5Q442 546 417.0 556.5Q392 567 355 567Q318 567 292.5 560.0Q267 553 253.5 540.0Q240 527 240 509Q240 487 257.5 473.0Q275 459 305.0 449.0Q335 439 372.0 430.5Q409 422 448.5 412.5Q488 403 525.0 388.5Q562 374 592.0 351.5Q622 329 639.5 296.0Q657 263 657 216Q657 134 618.5 84.0Q580 34 512.5 11.0Q445 -12 360 -12Z"/>
|
||||
<path fill="#1a1a1a" transform="translate(1346 756) scale(1 -1)" d="M75 0V687H254V147H603V0Z"/>
|
||||
<path fill="#1a1a1a" transform="translate(1969 756) scale(1 -1)" d="M75 0V687H453Q523 687 572.5 658.5Q622 630 648.5 579.5Q675 529 675 461Q675 391 647.5 340.0Q620 289 569.5 260.5Q519 232 449 232H254V0ZM254 370H407Q449 370 471.0 393.5Q493 417 493 459Q493 489 483.5 508.0Q474 527 455.0 537.5Q436 548 407 548H254Z"/>
|
||||
<path fill="#7a1414" transform="translate(2667 756) scale(1 -1)" d="M0 -48 196 736H302L106 -48Z"/>
|
||||
<path fill="#7a1414" transform="translate(2969 756) scale(1 -1)" d="M84 -6V121L452 260L84 399V527L586 327V194Z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.8 KiB |
@@ -0,0 +1,100 @@
|
||||
"""
|
||||
Builds the SLP Software brand logo: logo-on-light.png, logo-on-dark.png, logo-mail.png and logo.svg.
|
||||
|
||||
The mark is the text <SLP/> in Archivo ExtraBold; the angle brackets and slash are bordeaux accents,
|
||||
"SLP" is ink. Displayed 40 px high in the admin; PNGs are rendered at 3x (about 120 px high).
|
||||
|
||||
Needs: pip install pillow fonttools brotli; and `pnpm install` in frontend/ (font comes from @fontsource/archivo).
|
||||
Run from this folder: python make-logo.py
|
||||
"""
|
||||
import io
|
||||
import os
|
||||
from fontTools.ttLib import TTFont
|
||||
from fontTools.pens.svgPathPen import SVGPathPen
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
SCALE = 3
|
||||
H = 40 * SCALE
|
||||
PAD = 2 * SCALE
|
||||
FONT_WOFF2 = "../../node_modules/@fontsource/archivo/files/archivo-latin-800-normal.woff2"
|
||||
TTF = "archivo-800.tmp.ttf"
|
||||
PARTS = [("<", "accent"), ("SLP", "ink"), ("/>", "accent")]
|
||||
VARIANTS = {
|
||||
"logo-on-light.png": {"ink": (26, 26, 26), "accent": (122, 20, 20)},
|
||||
"logo-on-dark.png": {"ink": (245, 245, 245), "accent": (224, 100, 108)},
|
||||
}
|
||||
|
||||
f = TTFont(FONT_WOFF2)
|
||||
f.flavor = None
|
||||
f.save(TTF)
|
||||
|
||||
# Pick the pixel size so that the ink bounding box of the whole text is about H - 2*PAD high.
|
||||
size = 100
|
||||
probe = ImageFont.truetype(TTF, size)
|
||||
text = "".join(p for p, _ in PARTS)
|
||||
b = probe.getbbox(text)
|
||||
size = round(size * (H - 2 * PAD) / (b[3] - b[1]))
|
||||
font = ImageFont.truetype(TTF, size)
|
||||
full = font.getbbox(text)
|
||||
asc_top, asc_bot = full[1], full[3]
|
||||
|
||||
def render(colors):
|
||||
# Draw the parts one after another using advance widths (keeps the font's own kerning-free spacing).
|
||||
width = round(font.getlength(text)) + 2 * PAD + 4
|
||||
img = Image.new("RGBA", (width, 2 * H), (0, 0, 0, 0))
|
||||
d = ImageDraw.Draw(img)
|
||||
x = PAD
|
||||
for part, role in PARTS:
|
||||
d.text((x, PAD - asc_top), part, font=font, fill=colors[role] + (255,))
|
||||
x += font.getlength(part)
|
||||
img = img.crop(img.getchannel("A").getbbox())
|
||||
out = Image.new("RGBA", (img.width + 2 * PAD, img.height + 2 * PAD), (0, 0, 0, 0))
|
||||
out.alpha_composite(img, (PAD, PAD))
|
||||
return out
|
||||
|
||||
for name, colors in VARIANTS.items():
|
||||
im = render(colors)
|
||||
im.save(name, optimize=True)
|
||||
print(f"{name} {im.width}x{im.height}")
|
||||
|
||||
# logo-mail.png: the light variant on a white rounded badge (same approach as themes/asf/make-mail-logo.py).
|
||||
src = Image.open("logo-on-light.png").convert("RGBA")
|
||||
src = src.crop(src.getchannel("A").getbbox())
|
||||
CONTENT_H, MPAD, RADIUS = 40 * SCALE, 8 * SCALE, 8 * SCALE
|
||||
logo = src.resize((round(src.width * CONTENT_H / src.height), CONTENT_H), Image.LANCZOS)
|
||||
w, h = logo.width + 2 * MPAD, CONTENT_H + 2 * MPAD
|
||||
badge = Image.new("RGBA", (w, h), (0, 0, 0, 0))
|
||||
ImageDraw.Draw(badge).rounded_rectangle((0, 0, w - 1, h - 1), radius=RADIUS, fill=(255, 255, 255, 255))
|
||||
badge.alpha_composite(logo, (MPAD, MPAD))
|
||||
badge.save("logo-mail.png", optimize=True)
|
||||
print(f"logo-mail.png {w}x{h}")
|
||||
|
||||
# logo.svg: text converted to paths (archive/source; the build uses the PNGs).
|
||||
gs = f.getGlyphSet()
|
||||
cmap = f.getBestCmap()
|
||||
upm = f["head"].unitsPerEm
|
||||
hmtx = f["hmtx"]
|
||||
paths, x = [], 0
|
||||
ymin, ymax = 10**9, -10**9
|
||||
from fontTools.pens.boundsPen import BoundsPen
|
||||
for part, role in PARTS:
|
||||
for ch in part:
|
||||
g = cmap[ord(ch)]
|
||||
pen = SVGPathPen(gs)
|
||||
gs[g].draw(pen)
|
||||
bp = BoundsPen(gs)
|
||||
gs[g].draw(bp)
|
||||
if bp.bounds:
|
||||
ymin, ymax = min(ymin, bp.bounds[1]), max(ymax, bp.bounds[3])
|
||||
paths.append((pen.getCommands(), x, role))
|
||||
x += hmtx[g][0]
|
||||
pad = 20
|
||||
vb_h = ymax - ymin + 2 * pad
|
||||
fill = {"ink": "#1a1a1a", "accent": "#7a1414"}
|
||||
body = "\n".join(
|
||||
f' <path fill="{fill[r]}" transform="translate({px} {ymax + pad}) scale(1 -1)" d="{d}"/>' for d, px, r in paths
|
||||
)
|
||||
svg = f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="{-pad} 0 {x + 2 * pad} {vb_h}" role="img" aria-label="SLP Software">\n{body}\n</svg>\n'
|
||||
open("logo.svg", "w", encoding="utf-8", newline="\n").write(svg)
|
||||
print("logo.svg", len(svg), "bytes")
|
||||
os.remove(TTF)
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Theme "slpsoftware" - SLP Software.
|
||||
*
|
||||
* Re-declares the admin design tokens only (colours, radius, font); no layout or component changes.
|
||||
* Brand: bordeaux #7A1414 (website variant B) as primary/ring/accent basis on a white, neutral surface.
|
||||
* Font: Archivo, self-hosted through @fontsource (the admin CSP is font-src 'self').
|
||||
* Selected at build time with VITE_THEME=slpsoftware.
|
||||
*
|
||||
* Contrast (WCAG 2.x, computed by contrast.py next to this file; AA = 4.5:1 text, 3:1 UI/large):
|
||||
*
|
||||
* Pair Light Dark
|
||||
* foreground / background 17.40 16.90
|
||||
* card-foreground / card 16.25 15.29
|
||||
* primary-foreground / primary 10.84 5.45
|
||||
* primary (links) / background 10.84 5.45
|
||||
* primary / card 10.12 4.93
|
||||
* muted-foreground / background 6.69 8.49
|
||||
* muted-foreground / card 6.24 7.69
|
||||
* muted-foreground / muted 6.08 6.62
|
||||
* accent-foreground / accent 9.16 7.36
|
||||
* destructive-foreground / destructive 5.62 7.31
|
||||
* destructive / background 5.62 7.31
|
||||
* ring / background (min 3.0) 10.84 5.45
|
||||
* ring / card (min 3.0) 10.12 4.93
|
||||
*
|
||||
* All pairs pass AA in both modes. Dark mode has no website counterpart: its primary is a lighter,
|
||||
* derived bordeaux (#e0646c) so button text and links stay above 4.5:1 on the dark surfaces.
|
||||
*/
|
||||
@import '@fontsource/archivo/latin-400.css';
|
||||
@import '@fontsource/archivo/latin-500.css';
|
||||
@import '@fontsource/archivo/latin-600.css';
|
||||
@import '@fontsource/archivo/latin-700.css';
|
||||
|
||||
:root {
|
||||
--slp-bordeaux: #7a1414;
|
||||
--slp-ink: #1a1a1a;
|
||||
--slp-ink-2: #5c5c5c;
|
||||
--slp-surface: #f7f7f7;
|
||||
--slp-tint: #f6e9e9;
|
||||
--slp-error: #c62828;
|
||||
--slp-line: #e4e4e7;
|
||||
|
||||
--slp-font-body: 'Archivo', system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||
|
||||
--background: #ffffff;
|
||||
--foreground: var(--slp-ink);
|
||||
|
||||
--card: var(--slp-surface);
|
||||
--card-foreground: var(--slp-ink);
|
||||
|
||||
--popover: #ffffff;
|
||||
--popover-foreground: var(--slp-ink);
|
||||
|
||||
--primary: var(--slp-bordeaux);
|
||||
--primary-foreground: #ffffff;
|
||||
|
||||
--secondary: #f4f4f5;
|
||||
--secondary-foreground: var(--slp-ink);
|
||||
|
||||
--muted: #f4f4f5;
|
||||
--muted-foreground: var(--slp-ink-2);
|
||||
|
||||
--accent: var(--slp-tint);
|
||||
--accent-foreground: var(--slp-bordeaux);
|
||||
|
||||
--destructive: var(--slp-error);
|
||||
--destructive-foreground: #ffffff;
|
||||
|
||||
--border: var(--slp-line);
|
||||
--input: var(--slp-line);
|
||||
--ring: var(--slp-bordeaux);
|
||||
|
||||
--radius: 0.375rem;
|
||||
|
||||
--font-sans: var(--slp-font-body);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: #141414;
|
||||
--foreground: #f5f5f5;
|
||||
|
||||
--card: #1e1e1e;
|
||||
--card-foreground: #f5f5f5;
|
||||
|
||||
--popover: #1e1e1e;
|
||||
--popover-foreground: #f5f5f5;
|
||||
|
||||
--primary: #e0646c;
|
||||
--primary-foreground: #141414;
|
||||
|
||||
--secondary: #2a2a2a;
|
||||
--secondary-foreground: #f5f5f5;
|
||||
|
||||
--muted: #2a2a2a;
|
||||
--muted-foreground: #b0b0b0;
|
||||
|
||||
--accent: #3a1f21;
|
||||
--accent-foreground: #f0a0a6;
|
||||
|
||||
--destructive: #ff7b72;
|
||||
--destructive-foreground: #141414;
|
||||
|
||||
--border: #333333;
|
||||
--input: #333333;
|
||||
--ring: #e0646c;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--slp-font-body);
|
||||
}
|
||||
Reference in New Issue
Block a user