-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use @ariakit/react for new country picker (#306)
- Loading branch information
Showing
12 changed files
with
107 additions
and
129 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 0 additions & 91 deletions
91
src/components/FormComponents/CountryPicker/CountryCombobox/CountryCombobox.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/components/FormComponents/CountryPicker/country-combobox/CountryCombobox.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { ReactElement, startTransition, useState } from 'react' | ||
|
||
import { | ||
AkselifiedCombobox, | ||
AkselifiedComboboxDisclosure, | ||
AkselifiedComboboxItem, | ||
AkselifiedComboboxNonInteractiveFeedbackItem, | ||
AkselifiedComboboxNonSelectables, | ||
AkselifiedComboboxPopover, | ||
AkselifiedComboboxWrapper, | ||
} from '../../combobox/AkselifiedCombobox' | ||
import { countries } from '../../../../utils/countries' | ||
|
||
type Props = { | ||
id?: string | ||
onSelect: (countryCode: string | null) => void | ||
onChange: () => void | ||
initialValue: string | null | ||
} | ||
|
||
function CountryCombobox({ id, onChange, onSelect, initialValue }: Props): ReactElement { | ||
const defaultCountry = countries.find((country) => country.code === initialValue)?.name | ||
const [searchValue, setSearchValue] = useState(defaultCountry ?? '') | ||
const suggestions = !searchValue.trim() | ||
? countries | ||
: countries.filter( | ||
(country) => | ||
country.name.toLowerCase().includes(searchValue.toLowerCase()) || | ||
country.code.toLowerCase().includes(searchValue.toLowerCase()), | ||
) | ||
|
||
return ( | ||
<AkselifiedComboboxWrapper | ||
defaultValue={defaultCountry ?? undefined} | ||
labelId="country-typeahead-label" | ||
label="Landet sykmeldingen ble skrevet" | ||
setValue={(value) => { | ||
const country = countries.find((country) => country.name === value) | ||
|
||
startTransition(() => { | ||
if (country) { | ||
onSelect(country.code) | ||
setSearchValue(country.name) | ||
} else { | ||
onChange() | ||
setSearchValue(value) | ||
} | ||
}) | ||
}} | ||
> | ||
<AkselifiedCombobox id={id} aria-labelledby="country-typeahead-label" placeholder="Søk etter land"> | ||
<AkselifiedComboboxDisclosure /> | ||
</AkselifiedCombobox> | ||
<AkselifiedComboboxPopover> | ||
<AkselifiedComboboxNonSelectables> | ||
{suggestions.length === 0 && ( | ||
<AkselifiedComboboxNonInteractiveFeedbackItem> | ||
{`Fant ingen land med navn eller kode "${searchValue}"`} | ||
</AkselifiedComboboxNonInteractiveFeedbackItem> | ||
)} | ||
</AkselifiedComboboxNonSelectables> | ||
{suggestions.length > 0 && | ||
suggestions.map((value) => ( | ||
<AkselifiedComboboxItem key={value.code} value={value.name}> | ||
{value.name} | ||
</AkselifiedComboboxItem> | ||
))} | ||
</AkselifiedComboboxPopover> | ||
</AkselifiedComboboxWrapper> | ||
) | ||
} | ||
|
||
export default CountryCombobox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
12 changes: 8 additions & 4 deletions
12
src/app/api/country/_countries.ts → src/utils/countries/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters