Files
youtube-generator/src/components/errors/OfflineBanner.tsx
T
poli0981andClaude Opus 5.5 68dc48ea53 feat(a11y): AA contrast, output language, page announcements, single-key shortcut switch, desktop zoom
- Colour tokens reach WCAG AA: lighter muted text and accent in the dark
  theme, darker muted/success/warning/danger/donate in the light theme, and
  new accent-solid / danger-solid fills for buttons with white text.
  tests/styles/contrast.test.ts checks every text token on every surface.
- Generated text carries its language (lang) on Output, the YouTube and
  quick previews, History, Batch, Social and Playlist, so screen readers read
  Japanese output with a Japanese voice.
- RouteAnnouncer reads the new page's name after a navigation; focus stays.
- Toast region and close button are translated; Alt+T is in the shortcut list.
- Endings table inputs and the custom bank name get accessible names; the
  From/To headers are translated.
- Settings > Editor > Single-key shortcuts turns the bare ? off (WCAG 2.1.4).
- Text inputs use outline-hidden so the focus outline shows in Windows High
  Contrast; the genre remove button is 24px, small close/dismiss buttons
  grow on touch screens.
- Desktop: zoomHotkeysEnabled (Ctrl/Cmd + = / -), with the
  set-webview-zoom permission for the macOS/Linux polyfill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 20:02:37 +07:00

57 lines
2.2 KiB
TypeScript

import { useEffect, useRef, useState } from "react";
import { Link } from "react-router-dom";
import { toast } from "sonner";
import { useTranslation } from "react-i18next";
import { WifiOff, X } from "lucide-react";
import { useOnlineStatus } from "@hooks/use-online-status";
/**
* Non-blocking offline indicator.
*
* The app works fully offline (everything is client-side), so losing the
* network must never block input — this is a dismissible pill at the top of
* the screen (clear of the phone navigation bar), not a takeover page.
* Dismiss only hides the *current* offline episode; the next online→offline
* transition shows it again. A transient toast confirms when the connection
* returns (reusing the app-level `<Toaster/>`).
*/
export function OfflineBanner() {
const { t } = useTranslation("ui");
const online = useOnlineStatus();
const [dismissed, setDismissed] = useState(false);
const wasOnline = useRef(online);
useEffect(() => {
if (!wasOnline.current && online) {
toast.success(t("errorPages.offlineBanner.backOnline"));
}
if (wasOnline.current && !online) {
setDismissed(false);
}
wasOnline.current = online;
}, [online, t]);
if (online || dismissed) return null;
return (
<div
role="status"
className="border-warning/40 bg-surface-1 text-text-primary shadow-pop animate-slide-up fixed top-3 left-1/2 z-50 flex max-w-[calc(100%-1.5rem)] -translate-x-1/2 items-center gap-2.5 rounded-full border py-1.5 pr-1.5 pl-3.5 text-xs"
>
<WifiOff className="text-warning size-4 shrink-0" aria-hidden />
<span className="min-w-0 truncate">{t("errorPages.offlineBanner.message")}</span>
<Link to="/offline" className="text-accent hover:text-accent-hover shrink-0 font-medium">
{t("errorPages.offlineBanner.details")}
</Link>
<button
type="button"
onClick={() => setDismissed(true)}
aria-label={t("common.dismiss")}
className="text-text-muted hover:bg-surface-2 hover:text-text-primary flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-full transition-colors pointer-coarse:size-9"
>
<X className="size-3.5" aria-hidden="true" />
</button>
</div>
);
}