Files
Investidor-V2/resources/js/components/country-select.tsx
T
nala e662230df7
tests / ci (push) Canceled after 0s
oportunidades 3
2026-10-09 15:00:37 +02:00

21 lines
1.3 KiB
TypeScript

import { useState } from 'react';
export type Country = { code: string; name: string; name_en: string };
export default function CountrySelect({ countries, value, onChange, id, disabled = false }: {
countries: Country[]; value: string; onChange: (value: string) => void; id: string; disabled?: boolean;
}) {
const [search, setSearch] = useState('');
const matches = countries.filter((country) => country.code === value ||
`${country.name} ${country.name_en} ${country.code}`.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase()
.includes(search.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase()));
return <div className="space-y-2">
<input disabled={disabled} className="w-full rounded border p-2" aria-label="Pesquisar país" value={search} onChange={(event) => setSearch(event.target.value)} placeholder="Pesquisar nome ou código do país" />
<select disabled={disabled} id={id} className="w-full rounded border p-2" value={value} onChange={(event) => onChange(event.target.value)}>
<option value="">Não informado</option>
{matches.map((country) => <option key={country.code} value={country.code}>{country.name} ({country.code})</option>)}
</select>
{matches.length === 0 && <p role="status">Nenhum país corresponde à pesquisa.</p>}
</div>;
}