59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { useState } from 'react'
|
|
import Input from '@/components/ui/Input'
|
|
import Button from '@/components/ui/Button'
|
|
import Badge from '@/components/ui/Badge'
|
|
|
|
export interface FreeTextPathologyInputProps {
|
|
items: string[]
|
|
onChange: (next: string[]) => void
|
|
}
|
|
|
|
export default function FreeTextPathologyInput({
|
|
items,
|
|
onChange,
|
|
}: FreeTextPathologyInputProps) {
|
|
const [v, setV] = useState('')
|
|
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="Pathologie additionnelle (texte libre)"
|
|
onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); add() } }}
|
|
aria-label="Pathologie libre"
|
|
/>
|
|
<Button onClick={add} variant="secondary">Ajouter</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={`Retirer ${it}`}
|
|
onClick={() => remove(i)}
|
|
className="ml-1 text-[var(--color-accent-strong)] hover:text-[var(--color-danger)]"
|
|
>
|
|
✕
|
|
</button>
|
|
</Badge>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|