Files
vitareba/components/LanguageSwitcher.tsx
GandClaude Opus 5 3e059f0818 chore: add a formatter (#83)
* chore: add a formatter, matching the style this repo already writes

singleQuote=false was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.

Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format with prettier (304 files)

Mechanical. No behaviour change. This SHA is listed in
.git-blame-ignore-revs so `git blame` skips it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore: teach git blame to skip the reformat

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format the two files the reformat pass missed

prettier --check flagged app/shared.module.css and lib/domain/clinicians.test.ts
on a branch whose whole point was that everything had been formatted. Re-running
the same command with the same version fixes both, so the rollout's write step
did not finish what it reported.

The rollout now runs --check straight after --write and refuses to open a PR
unless it comes back clean, so a partial reformat fails at the source instead of
in CI.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 10:48:01 +00:00

83 lines
2.1 KiB
TypeScript

"use client";
import { useLocale } from "next-intl";
import { useRouter, usePathname } from "@/lib/i18n/navigation";
import { routing } from "@/i18n/routing";
import { useState, useRef, useEffect } from "react";
import styles from "./LanguageSwitcher.module.css";
const LOCALE_LABELS: Record<string, string> = {
de: "DE",
en: "EN",
fr: "FR",
it: "IT",
};
export function LanguageSwitcher() {
const locale = useLocale();
const router = useRouter();
const pathname = usePathname();
const [open, setOpen] = useState(false);
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
function handleClick(e: MouseEvent) {
if (ref.current && !ref.current.contains(e.target as Node)) {
setOpen(false);
}
}
document.addEventListener("mousedown", handleClick);
return () => document.removeEventListener("mousedown", handleClick);
}, []);
function select(l: string) {
router.replace(pathname, { locale: l });
setOpen(false);
}
return (
<div className={styles.root} ref={ref}>
<button
type="button"
className={styles.trigger}
onClick={() => setOpen((o) => !o)}
aria-haspopup="listbox"
aria-expanded={open}
>
{LOCALE_LABELS[locale]}
<svg
className={`${styles.chevron} ${open ? styles.chevronOpen : ""}`}
width="10"
height="10"
viewBox="0 0 10 10"
fill="none"
>
<path
d="M2 3.5L5 6.5L8 3.5"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</button>
{open && (
<div className={styles.dropdown} role="listbox">
{routing.locales.map((l) => (
<button
key={l}
type="button"
role="option"
aria-selected={l === locale}
className={`${styles.option} ${l === locale ? styles.optionActive : ""}`}
onClick={() => select(l)}
>
{LOCALE_LABELS[l]}
</button>
))}
</div>
)}
</div>
);
}