feat(observation): FreeTextPathologyInput with chip removal
This commit is contained in:
1 parent
4c67c900b9
commit
241bb42c7d
1 file changed
+57
-2
@@ -1,3 +1,58 @@
|
||||
export default function FreeTextPathologyInput() {
|
||||
return <div>FreeTextPathologyInput placeholder</div>
|
||||
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>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user