Files
faunosteo/src/components/observation/FreeTextFindingInput.tsx
T
Bastien ChanotandClaude Opus 4.7 d6027266bc feat(i18n): migrate site + PDF to locale-aware rendering
- formatDate(iso, locale) replaces formatDateFr in src/lib/dates.ts
- exportReportToPdf(report, { locale }) takes explicit locale option
- LanguageSwitcher segmented FR | EN toggle added; integrated in
  ReportHeader, HomeRoute, NewReportRoute
- All routes (Home, NewReport, Editor, NotFound) + observation
  components (FindingsTreePicker, ObservationCard, FreeTextFindingInput,
  SeveritySelector, VertebraPicker, ObservationList) + report forms
  (PractitionerForm, AnimalForm, ConclusionPanel, NextAppointmentPicker)
  route hardcoded FR via useT()
- PDF render functions (export.ts, header.ts, footer.ts,
  observationPage.ts, conclusionPage.ts) take a locale arg and read
  static labels from the dict snapshot at call time
- Catalog finding leaf labels rendered via labelFr/EnSnapshot per locale
- description_fr / scope_disclaimer stay FR-only (out of scope —
  vet-expert authoring needed for EN copy)
- LanguageSwitcher unit test (2) + lib.dates locale tests (7) cover
  the new behavior

151/151 tests pass, lint 0, typecheck clean, vite build OK
(902KB main + 15KB lazy pathologies chunk).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-20 07:11:40 +02:00

71 lines
1.8 KiB
TypeScript

import { useState } from 'react'
import Input from '@/components/ui/Input'
import Button from '@/components/ui/Button'
import Badge from '@/components/ui/Badge'
import { useT } from '@/i18n/useT'
export interface FreeTextFindingInputProps {
items: string[]
onChange: (next: string[]) => void
}
export default function FreeTextFindingInput({
items,
onChange,
}: FreeTextFindingInputProps) {
const [v, setV] = useState('')
const t = useT()
function add() {
const trimmed = v.trim()
if (!trimmed) return
onChange([...items, trimmed])
setV('')
}
function remove(i: number) {
onChange(items.filter((_, k) => k !== i))
}
return (
<div className="space-y-2">
<div className="flex gap-2">
<Input
value={v}
onChange={(e) => setV(e.target.value)}
placeholder={t('observation.free_placeholder')}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault()
add()
}
}}
aria-label={t('observation.free_aria')}
/>
<Button onClick={add} variant="secondary">
{t('common.add')}
</Button>
</div>
{items.length > 0 && (
<ul className="flex flex-wrap gap-2">
{items.map((it, i) => (
<li key={`${it}-${i}`}>
<Badge tone="accent" className="gap-1">
{it}
<button
type="button"
aria-label={`${t('observation.remove_zone')} ${it}`}
onClick={() => remove(i)}
className="ml-1 text-[var(--color-accent-strong)] hover:text-[var(--color-danger)]"
>
✕
</button>
</Badge>
</li>
))}
</ul>
)}
</div>
)
}